This repository has been archived by the owner on Sep 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathX32-Inject.Asm
127 lines (99 loc) · 2.34 KB
/
X32-Inject.Asm
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
.386
.model flat, stdcall ;32 bit memory model
option casemap :none ;case sensitive
include FirstDlg.inc
.code
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke InitCommonControls
invoke DialogBoxParam,hInstance,IDD_INJECT,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 eax == BTN_INJECT
invoke InjectCode
.endif
.elseif eax==WM_CLOSE
invoke EndDialog,hWin,0
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgProc endp
begin_label:
call $+5 ;重定位
NEXT:
pop ebp
sub ebp, NEXT
push MB_OK
lea eax, [ebp + offset g_szTitle]
push eax
lea eax, [ebp + offset g_szMsg]
push eax
push NULL
mov eax, [ebp + offset g_pfnMessageBox]
call eax
ret
g_szTitle db 'Title', 0
g_szMsg db 'Hello World', 0
g_pfnMessageBox DWORD 0
;g_pfnLoadLibrary DWORD 0
;g_pfnGetProcAddress DWORD 0
end_label:
InjectCode proc
LOCAL @hCalc:HWND
LOCAL @dwPid :dword
LOCAL @hProcess :HANDLE
LOCAL @lpBuff :PVOID
LOCAL @hUser:HANDLE
LOCAL @oldProtect:DWORD
LOCAL @lpMsgBox:PVOID
invoke LoadLibrary, addr g_szUser32
mov @hUser, eax
;check
invoke GetProcAddress, @hUser, addr g_szMsgBox
mov @lpMsgBox, eax
;check
;修改内存保护属性
invoke VirtualProtect, addr begin_label, end_label - begin_label, \
PAGE_EXECUTE_READWRITE, addr @oldProtect
;check
mov eax, @lpMsgBox
mov g_pfnMessageBox, eax
invoke VirtualProtect, addr begin_label, end_label - begin_label, \
@oldProtect, addr @oldProtect
;check
invoke FreeLibrary,@hUser
;check
invoke FindWindow,NULL, addr g_szCalc
mov @hCalc, eax
;check
invoke GetWindowThreadProcessId,@hCalc, addr @dwPid
;check
invoke OpenProcess, PROCESS_ALL_ACCESS, FALSE, @dwPid
mov @hProcess, eax
;check
;申请内存
invoke VirtualAllocEx, @hProcess, NULL, 1000h, MEM_COMMIT, PAGE_EXECUTE_READWRITE
mov @lpBuff, eax
;check
;写入内存
invoke WriteProcessMemory,@hProcess, @lpBuff, \
addr begin_label, end_label - begin_label, NULL
;check
;创建远程线程
invoke CreateRemoteThread,@hProcess, NULL, 0, @lpBuff, NULL, 0, NULL
;check
;释放内存
invoke VirtualFreeEx,@hProcess, @lpBuff, 1000h, MEM_RELEASE
;check
ret
InjectCode endp
end start