1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
| .386 .model flat, stdcall ;32 bit memory model option casemap :none ;case sensitive
include MyTest.inc .code INJECT_CODE_START: ;int 3 push ebp mov ebp,esp push 0 push 0 push 0 push 0 label1: mov eax,12345678h call eax ;call [ebp+8] ;leave mov esp,ebp pop ebp retn 4 INJECT_CODE_END:
Inject proc LOCAL @hWnd:HWND LOCAL @dwPid:DWORD LOCAL @hProcess:HANDLE LOCAL @lpBuf:LPVOID LOCAL @dwBytes:dword LOCAL @hUser32:dword LOCAL @old:dword LOCAL @hMods[1024]:HMODULE LOCAL @cbNeeded:dword LOCAL @szModName[260]:byte LOCAL @hRemoteBase:dword LOCAL @lpLocalAddr:dword ;push 0 ;push 0 ;push 0 ;push 0 ;call MessageBoxA ;call dword ptr [MyMsg] ;==>call xxxxxxxx USER32.DLL call dword ptr ds:[40201c] invoke FindWindow,NULL,OFFSET MY_WND_NAME MOV @hWnd,eax ;check invoke GetWindowThreadProcessId,@hWnd,addr @dwPid ;check invoke OpenProcess,PROCESS_ALL_ACCESS,FALSE,@dwPid mov @hProcess,eax ;check ;1.对方进程申请内存 invoke VirtualAllocEx,@hProcess,NULL,1000h,MEM_COMMIT,PAGE_EXECUTE_READWRITE mov @lpBuf,eax ;check ;代码重定位 ;修改内存属性 invoke VirtualProtect,offset INJECT_CODE_START,1000h,PAGE_EXECUTE_READWRITE,addr @old ;遍历模块基址 invoke EnumProcessModules,@hProcess,@hMods,sizeof @hMods,addr @cbNeeded mov ebx,0 mov edx,@cbNeeded shr edx,2 mov @cbNeeded,edx .while ebx < @cbNeeded invoke GetModuleFileNameEx,@hProcess,dword ptr [@hMods+ebx*4],addr @szModName,sizeof @szModName invoke crt_strstr,addr @szModName,offset MY_USER32 .if eax!=0 mov eax,dword ptr[@hMods+ebx*4] mov @hRemoteBase,eax .break .endif inc ebx .endw ;check invoke LoadLibrary,offset MY_USER32 mov @hUser32,eax ;check invoke GetProcAddress,@hUser32,offset MY_MSGBOX mov @lpLocalAddr,eax ;check remoteBase+(MessageBoxA-@hUser32) sub eax,@hUser32 add eax,@hRemoteBase mov dword ptr [label1+1],eax ;2.写入INJECT_CODE的代码 mov ebx,offset INJECT_CODE_END sub ebx,offset INJECT_CODE_START invoke WriteProcessMemory,@hProcess,@lpBuf,offset INJECT_CODE_START,ebx,addr @dwBytes ;check; ;3.创建远程线程 invoke CreateRemoteThread,@hProcess,NULL,0,@lpBuf,NULL,0,NULL ;check ret Inject endp
start: ;invoke crt_strcpy,NULL,NULL push 0 call INJECT_CODE_START invoke GetModuleHandle,NULL mov hInstance,eax invoke InitCommonControls invoke DialogBoxParam,hInstance,IDD_DIALOG1,NULL,addr DlgProc,NULL invoke ExitProcess,0 ;######################################################################## DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM mov eax,uMsg .if eax==WM_INITDIALOG .elseif eax==WM_COMMAND mov eax,wParam .if ax==BTN_INJECT invoke MessageBox,NULL,offset MY_MSG,NULL,MB_OK .endif .elseif eax==WM_CLOSE invoke EndDialog,hWin,0 .else mov eax,FALSE ret .endif mov eax,TRUE ret DlgProc endp end start
|