本帖最后由 pusofalse 于 2012-2-22 01:51 编辑
#include <GUIMenu.au3>
#include <Thread.au3>
Const $tagREMOTE_SYSCOMMAND = "ptr SetWindowLongW;ptr CallWindowProcW;ptr GetSystemMenu;ptr GetMenuStringW;ptr MessageBoxW;ptr wsprintfW;ptr WndProc;dword Breakpoint;wchar wzTitle[16];wchar wzText[32];ubyte ShellX[256]"
$hWnd = WinGetHandle("[class:Notepad]")
If $hWnd = 0 Then
Run(@WindowsDir & "\notepad.exe")
$hWnd = WinWait("[class:Notepad]")
EndIf
$hMenu = _GUICtrlMenu_GetSystemMenu($hWnd)
If $hMenu = 0 Then Exit
_GUICtrlMenu_InsertMenuItem($hMenu, -1, "", 0)
_GUICtrlMenu_InsertMenuItem($hMenu, -1, "Hello", 0xF201)
$iProcessID = WinGetProcess($hWnd)
$hProcess = _RTOpenProcess($iProcessID)
$pBaseAddress = _RTVirtualAllocEx($hProcess, 4096)
$tBuffer = DllStructCreate($tagREMOTE_SYSCOMMAND)
$pBuffer = DllStructGetPtr($tBuffer)
DllStructSetData($tBuffer, "SetWindowLongW", _RTGetProcAddress("User32.dll", "SetWindowLongW"))
DllStructSetData($tBuffer, "CallWindowProcW", _RTGetProcAddress("User32.dll", "CallWindowProcW"))
DllStructSetData($tBuffer, "GetSystemMenu", _RTGetProcAddress("User32.dll", "GetSystemMenu"))
DllStructSetData($tBuffer, "GetMenuStringW", _RTGetProcAddress("User32.dll", "GetMenuStringW"))
DllStructSetData($tBuffer, "MessageBoxW", _RTGetProcAddress("User32.dll", "MessageBoxW"))
DllStructSetData($tBuffer, "wsprintfW", _RTGetProcAddress("User32.dll", "wsprintfW"))
DllStructSetData($tBuffer, "Breakpoint", 0xCCCCCCCC)
DllStructSetData($tBuffer, "wzTitle", "Hello")
DllStructSetData($tBuffer, "wzText", "You clicked ID 0x%08X.")
DllStructSetData($tBuffer, "ShellX", _GetShellX())
_RTWriteProcessMemory($hProcess, $pBaseAddress, $pBuffer, DllStructGetSize($tBuffer))
$hThread = _RTCreateRemoteThread($hProcess, $pBaseAddress + 0x80, $hWnd)
_RTWaitForObject($hThread)
_RTCloseHandle($hThread)
_RTCloseHandle($hProcess)
Func _GetShellX()
Local $bBinary = "0x558BEC53E8000000005B81EB890000008D83A8000000506AFCFF7508FF138943185B5DC20400CCCC558BEC53E8000000005B81EBB1000000817D0C12010000753AF7451000020000743181EC00040000568D742404FF75108D43405056FF531483C40C6A308D43205056FF7508FF531033C05E81C400040000EB12FF7514FF7510FF750CFF7508FF7318FF53045B5DC21000CCCC"
Return Binary($bBinary)
EndFunc ;==>_GetShellX
为了区分系统定义的命令ID,_GUICtrlMenu_InsertMenuItem函数中指定的ID的第9位必须为1,即合法的命令ID为 0x.....2..,0x.....3..,0x.....7..,0x.....E..等等,以下是汇编代码。00AD0080 55 push ebp ; 设置窗口过程
00AD0081 8BEC mov ebp, esp
00AD0083 53 push ebx
00AD0084 E8 00000000 call 00AD0089 ; 代码自定位
00AD0089 5B pop ebx
00AD008A 81EB 89000000 sub ebx, 89
00AD0090 8D83 A8000000 lea eax, dword ptr [ebx+A8]
00AD0096 50 push eax
00AD0097 6A FC push -4
00AD0099 FF75 08 push dword ptr [ebp+8]
00AD009C FF13 call dword ptr [ebx] ; SetWindowLongW
00AD009E 8943 18 mov dword ptr [ebx+18], eax
00AD00A1 5B pop ebx
00AD00A2 5D pop ebp
00AD00A3 C2 0400 retn 4
00AD00A6 CC int3
00AD00A7 CC int3
00AD00A8 55 push ebp ; 窗口过程
00AD00A9 8BEC mov ebp, esp
00AD00AB 53 push ebx
00AD00AC E8 00000000 call 00AD00B1
00AD00B1 5B pop ebx
00AD00B2 81EB B1000000 sub ebx, 0B1
00AD00B8 817D 0C 12010000 cmp dword ptr [ebp+C], 112 ; if MsgID = WM_SYSCOMAMND ...
00AD00BF 75 3A jnz short 00AD00FB
00AD00C1 F745 10 00020000 test dword ptr [ebp+10], 200 ; 测试标志位
00AD00C8 74 31 je short 00AD00FB
00AD00CA 81EC 00040000 sub esp, 400
00AD00D0 56 push esi
00AD00D1 8D7424 04 lea esi, dword ptr [esp+4]
00AD00D5 FF75 10 push dword ptr [ebp+10]
00AD00D8 8D43 40 lea eax, dword ptr [ebx+40]
00AD00DB 50 push eax
00AD00DC 56 push esi
00AD00DD FF53 14 call dword ptr [ebx+14] ; wsprintfW
00AD00E0 83C4 0C add esp, 0C
00AD00E3 6A 30 push 30
00AD00E5 8D43 20 lea eax, dword ptr [ebx+20]
00AD00E8 50 push eax
00AD00E9 56 push esi
00AD00EA FF75 08 push dword ptr [ebp+8]
00AD00ED FF53 10 call dword ptr [ebx+10] ; MessageBoxW
00AD00F0 33C0 xor eax, eax
00AD00F2 5E pop esi
00AD00F3 81C4 00040000 add esp, 400
00AD00F9 EB 12 jmp short 00AD010D
00AD00FB FF75 14 push dword ptr [ebp+14]
00AD00FE FF75 10 push dword ptr [ebp+10]
00AD0101 FF75 0C push dword ptr [ebp+C]
00AD0104 FF75 08 push dword ptr [ebp+8]
00AD0107 FF73 18 push dword ptr [ebx+18]
00AD010A FF53 04 call dword ptr [ebx+4] ; CallWindowProcW
00AD010D 5B pop ebx
00AD010E 5D pop ebp
00AD010F C2 1000 retn 10
00AD0112 CC int3
00AD0113 CC int3
|