Skip to content

Commit 7006c8f

Browse files
authored
Merge pull request rapid7#19609 from dledda-r7/remove-hardcoded-blockapi-hash
Remove hardcoded blockapi hashes
2 parents 36505c7 + 6d6608c commit 7006c8f

File tree

18 files changed

+837
-1422
lines changed

18 files changed

+837
-1422
lines changed

lib/msf/core/payload/windows.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ module Msf::Payload::Windows
2121

2222
#
2323
# ROR hash associations for some of the exit technique routines.
24-
#
24+
2525
@@exit_types =
2626
{
2727
nil => 0, # Default to nothing
2828
'' => 0, # Default to nothing
29-
'seh' => 0xEA320EFE, # SetUnhandledExceptionFilter
30-
'thread' => 0x0A2A1DE0, # ExitThread
31-
'process' => 0x56A2B5F0, # ExitProcess
32-
'none' => 0x5DE2C5AA # GetLastError
29+
'seh' => Rex::Text.block_api_hash("kernel32.dll", "SetUnhandledExceptionFilter").to_i(16), # SetUnhandledExceptionFilter
30+
'thread' => Rex::Text.block_api_hash("kernel32.dll", "ExitThread").to_i(16), # ExitThread
31+
'process' => Rex::Text.block_api_hash("kernel32.dll", "ExitProcess").to_i(16), # ExitProcess
32+
'none' => Rex::Text.block_api_hash("kernel32.dll", "GetLastError").to_i(16) # GetLastError
3333
}
3434

3535
#

lib/msf/core/payload/windows/exitfunk.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ def asm_exitfunk(opts={})
3333
when 'thread'
3434
asm << %Q^
3535
mov ebx, 0x#{Msf::Payload::Windows.exit_types['thread'].to_s(16)}
36-
push 0x9DBD95A6 ; hash( "kernel32.dll", "GetVersion" )
36+
push #{Rex::Text.block_api_hash("kernel32.dll", "GetVersion")} ; hash( "kernel32.dll", "GetVersion" )
3737
call ebp ; GetVersion(); (AL will = major version and AH will = minor version)
3838
cmp al, 6 ; If we are not running on Windows Vista, 2008 or 7
3939
jl exitfunk_goodbye ; Then just call the exit function...
4040
cmp bl, 0xE0 ; If we are trying a call to kernel32.dll!ExitThread on Windows Vista, 2008 or 7...
4141
jne exitfunk_goodbye ;
42-
mov ebx, 0x6F721347 ; Then we substitute the EXITFUNK to that of ntdll.dll!RtlExitUserThread
42+
mov ebx, #{Rex::Text.block_api_hash("ntdll.dll", "RtlExitUserThread")} ; Then we substitute the EXITFUNK to that of ntdll.dll!RtlExitUserThread
4343
exitfunk_goodbye: ; We now perform the actual call to the exit function
4444
push.i8 0 ; push the exit function parameter
4545
push ebx ; push the hash of the exit function

lib/msf/core/payload/windows/prepend_migrate.rb

Lines changed: 56 additions & 196 deletions
Large diffs are not rendered by default.

lib/msf/core/payload/windows/reverse_http.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def asm_reverse_http(opts={})
442442
else
443443
asm << %Q^
444444
failure:
445-
push 0x56A2B5F0 ; hardcoded to exitprocess for size
445+
push #{Rex::Text.block_api_hash('kernel32.dll', 'ExitProcess')}
446446
call ebp
447447
^
448448
end

lib/msf/core/payload/windows/reverse_named_pipe.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def asm_reverse_named_pipe(opts={})
147147
else
148148
asm << %Q^
149149
failure:
150-
push 0x56A2B5F0 ; hardcoded to exitprocess for size
150+
push #{Rex::Text.block_api_hash('kernel32.dll', 'ExitProcess')}
151151
call ebp
152152
^
153153
end

lib/msf/core/payload/windows/reverse_tcp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def asm_reverse_tcp(opts={})
201201
else
202202
asm << %Q^
203203
failure:
204-
push 0x56A2B5F0 ; hardcoded to exitprocess for size
204+
push #{Rex::Text.block_api_hash('kernel32.dll', 'ExitProcess')}
205205
call ebp
206206
^
207207
end

lib/msf/core/payload/windows/reverse_tcp_dns.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def asm_reverse_tcp_dns(opts={})
142142
else
143143
asm << %Q^
144144
failure:
145-
push 0x56A2B5F0 ; hardcoded to exitprocess for size
145+
push #{Rex::Text.block_api_hash('kernel32.dll', 'ExitProcess')}
146146
call ebp
147147
^
148148
end

lib/msf/core/payload/windows/reverse_udp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def asm_reverse_udp(opts={})
129129
else
130130
asm << %Q^
131131
failure:
132-
push 0x56A2B5F0 ; hardcoded to exitprocess for size
132+
push #{Rex::Text.block_api_hash('kernel32.dll', 'ExitProcess')}
133133
call ebp
134134
^
135135
end

lib/msf/core/payload/windows/reverse_win_http.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ def asm_reverse_winhttp(opts={})
476476
else
477477
asm << %Q^
478478
failure:
479-
push 0x56A2B5F0 ; hardcoded to exitprocess for size
479+
push #{Rex::Text.block_api_hash('kernel32.dll', 'ExitProcess')}
480480
call ebp
481481
^
482482
end

lib/msf/core/payload/windows/x64/reverse_named_pipe_x64.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def generate_reverse_named_pipe(opts={})
5959
and rsp, ~0xF ; Ensure RSP is 16 byte aligned
6060
call start ; Call start, this pushes the address of 'api_call' onto the stack.
6161
#{asm_block_api}
62-
start:
63-
pop rbp ; block API pointer
62+
start:
63+
pop rbp ; block API pointer
6464
#{asm_reverse_named_pipe(opts)}
6565
^
6666
Metasm::Shellcode.assemble(Metasm::X64.new, combined_asm).encode_string
@@ -145,7 +145,7 @@ def asm_reverse_named_pipe(opts={})
145145
else
146146
asm << %Q^
147147
failure:
148-
push 0x56A2B5F0 ; hardcoded to exitprocess for size
148+
push #{Rex::Text.block_api_hash('kernel32.dll', 'ExitProcess')}
149149
call rbp
150150
^
151151
end

0 commit comments

Comments
 (0)