能力值:
( LV6,RANK:90 )
8 楼
又看到这篇经典之作了,顺便发一下我以前改的一个样板
主要是增加了按ctrl+alt+end解除钩子的功能 .386
.model flat,stdcall
option casemap :none
include windows.inc
include kernel32.inc
include user32.inc
include advapi32.inc
includelib kernel32.lib
includelib user32.lib
includelib advapi32.lib
NewSASProc PROTO :HWND,:UINT,:WPARAM,:LPARAM
MyHotKeyId equ 11h
MyMessage equ 401h
szText MACRO Name, Text:VARARG
LOCAL lbl
jmp lbl
Name db Text,0
lbl:
ENDM
.data
hProcess dd 0
hSnapshot dd 0
ph dd 0
hEvent dd 0
szUserBase dd 0
szKernelBase dd 0
injection_base dd 0
dwSize dd 0
szkernel32 db 'kernel32.dll',0
szuser32 db 'user32.dll',0
szSetWindowLong db 'SetWindowLongA',0
szFindWindow db 'FindWindowA',0
szCallWindowProc db 'CallWindowProcA',0
szExitThread db 'ExitThread',0
szWinlogon db 'winlogon.exe',0
szWinlogon2 db 'WINLOGON.EXE',0
szMessageBoxA db 'MessageBoxA',0
szRegisterHotKey db 'RegisterHotKey', 0
szUnregisterHotKey db 'UnregisterHotKey' ,0
szSendMessageA db 'SendMessageA' ,0
szCreateEventA db 'CreateEventA' ,0
szCloseHandle db 'CloseHandle' ,0
szWaitForSingleObject db 'WaitForSingleObject', 0
szSetEvent db 'SetEvent' ,0
szResetEvent db 'ResetEvent' ,0
szSuccessful db '已成功卸载!',0
szFind db '发现钩子,是否从新加载?' ,0
uProcess PROCESSENTRY32 <0>
szfname db 0 dup(30h) .code
_injection:
call @f
_CallWindowProc dd 0
_CloseHandle dd 0
_FindWindow dd 0
_CreateEventA dd 0
_SetWindowLong dd 0
_ExitThread dd 0
_SendMessageA dd 0
_RegisterHotKey dd 0
_UnregisterHotKey dd 0
_MessageBoxA dd 0
_WaitForSingleObject dd 0
_SetEvent dd 0
_ResetEvent dd 0
_szEvent db 'MyEvent' ,0
szwindowtext db 'SAS window',0
szclass db 'SAS Window class',0
_MyEventHandle dd 0
_WindowHandle dd 0
_Edit dd 0
OldSASProc dd 0
@@:
call @F
@@:
pop ebx
sub ebx ,offset @B
lea ecx , [ebx + offset szwindowtext]
push ecx
lea ecx , [ebx + offset szclass]
push ecx
call [ebx + _FindWindow]
mov [ebx + _WindowHandle] ,eax
lea ecx , [ebx + NewSASProc]
push ecx
push GWL_WNDPROC
push eax
call [ebx + _SetWindowLong]
mov [ebx + OldSASProc] ,eax
lea ecx , [ebx + offset _szEvent]
push ecx
push NULL
push NULL
push NULL
call [ebx + _CreateEventA]
mov [ebx + _MyEventHandle] ,eax
@Wait:
push MyHotKeyId
push NULL
push MyMessage
push [ebx + _WindowHandle]
call [ebx + _SendMessageA]
@@:
push -1
push [ebx + _MyEventHandle]
call [ebx + _WaitForSingleObject]
push [ebx + _MyEventHandle]
call [ebx + _ResetEvent]
mov edi ,[ebx + _Edit]
cmp byte ptr [ebx + edi + 5] ,075h
je @b
mov byte ptr [ebx + edi + 5] ,075h
jmp @Wait
;-------------------------
;新的窗口处理函数
;-------------------------
NewSASProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
mov eax,uMsg
@Edit:
.if eax==WM_HOTKEY
.if lParam==02E0003h
mov eax,0 ;屏蔽
.elseif lParam == 0230003h
pushad
call @f
@@:
pop ebx
sub ebx ,@B
push MyHotKeyId
push [ebx + _WindowHandle]
call [ebx + _UnregisterHotKey]
lea edi ,offset @Edit
mov byte ptr [ebx + edi + 5] ,0ebh
popad
mov eax ,0
mov ecx ,1
.endif
.elseif eax == MyMessage
pushad
call @f
@@:
pop ebx
sub ebx ,@b
push 23h
push 3
push MyHotKeyId
push [ebx + _WindowHandle]
call [ebx + _RegisterHotKey]
lea eax ,offset @Edit
mov [ebx + _Edit] ,eax
popad
mov eax ,1
.else
call @f
@@:
pop ebx
sub ebx ,@b
push lParam
push wParam
push uMsg
push hWin
push [ebx + OldSASProc]
call [ebx + _CallWindowProc ]
.endif
ret
NewSASProc endp
injection_size equ $-_injection
Start:
invoke CreateEventA ,NULL ,NULL ,NULL ,addr _szEvent
mov hEvent ,eax
invoke GetLastError
.if eax == 0b7h
invoke MessageBoxA ,NULL ,addr szFind ,NULL ,MB_YESNO
.if eax == IDYES
invoke SetEvent ,hEvent
invoke ExitProcess ,NULL
.else
invoke ExitProcess ,NULL
.endif
.endif
invoke LoadLibrary,addr szkernel32
mov szKernelBase,eax
invoke GetProcAddress,eax,addr szExitThread
mov _ExitThread,eax
invoke GetProcAddress,szKernelBase ,addr szCreateEventA
mov _CreateEventA ,eax
invoke GetProcAddress,szKernelBase ,addr szCloseHandle
mov _CloseHandle ,eax
invoke GetProcAddress,szKernelBase ,addr szWaitForSingleObject
mov _WaitForSingleObject ,eax
invoke GetProcAddress,szKernelBase ,addr szSetEvent
mov _SetEvent ,eax
invoke GetProcAddress,szKernelBase ,addr szResetEvent
mov _ResetEvent ,eax
invoke LoadLibrary,addr szuser32
mov szUserBase,eax
invoke GetProcAddress,eax,addr szSetWindowLong
mov _SetWindowLong,eax
invoke GetProcAddress,szUserBase,addr szFindWindow
mov _FindWindow,eax
invoke GetProcAddress,szUserBase,addr szRegisterHotKey
mov _RegisterHotKey ,eax
invoke GetProcAddress,szUserBase,addr szUnregisterHotKey
mov _UnregisterHotKey ,eax
invoke GetProcAddress,szUserBase,addr szMessageBoxA
mov _MessageBoxA ,eax
invoke GetProcAddress,szUserBase,addr szSendMessageA
mov _SendMessageA ,eax
invoke GetProcAddress,szUserBase,addr szCallWindowProc
mov _CallWindowProc,eax
call _EnableDebugPrivilege
invoke CreateToolhelp32Snapshot, 2, 0
mov hSnapshot, eax
mov uProcess.dwSize, sizeof uProcess
invoke Process32First, hSnapshot, ADDR uProcess
mov hProcess, eax
.while hProcess!=0
lea eax,uProcess.szExeFile
invoke lstrcmp,addr szWinlogon,eax
push eax
lea eax,uProcess.szExeFile
invoke lstrcmp,addr szWinlogon2,eax
pop ecx
and eax,ecx
jnz @F
invoke OpenProcess, PROCESS_ALL_ACCESS, NULL,uProcess.th32ProcessID
mov ph, eax
jmp skip
@@:
invoke Process32Next, hSnapshot, ADDR uProcess
mov hProcess, eax
.endw
skip:
invoke CloseHandle, hSnapshot
invoke VirtualAllocEx,ph,NULL,injection_size,MEM_COMMIT,PAGE_EXECUTE_READWRITE
mov injection_base, EAX
invoke WriteProcessMemory,ph,EAX,addr _injection,injection_size,NULL
invoke CreateRemoteThread,ph,NULL, 0,injection_base,NULL, 0, 0
invoke CloseHandle,ph
invoke Sleep ,500
invoke CloseHandle ,hEvent
invoke ExitProcess,NULL
_EnableDebugPrivilege proc
local @hToken
local @tp:TOKEN_PRIVILEGES
szText SE_DEBUG_NAME_Y,"SeDebugPrivilege"
invoke GetCurrentProcess
lea ecx,@hToken
invoke OpenProcessToken,eax,TOKEN_ALL_ACCESS,ecx
mov @tp.PrivilegeCount,1
invoke LookupPrivilegeValue,NULL,addr SE_DEBUG_NAME_Y,addr @tp.Privileges[0].Luid
mov @tp.Privileges[0].Attributes,SE_PRIVILEGE_ENABLED
invoke AdjustTokenPrivileges,@hToken,FALSE,addr @tp,sizeof @tp,NULL,NULL
push eax
invoke CloseHandle,@hToken
pop eax
ret
_EnableDebugPrivilege endp
end Start