Skip to content

Commit 4681416

Browse files
author
HD Moore
committed
Update block_api with @schierlm's changes
1 parent e872894 commit 4681416

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,15 @@ def prepend_migrate(buf)
6868
api_call:
6969
pushad ; We preserve all the registers for the caller, bar EAX and ECX.
7070
mov ebp, esp ; Create a new stack frame
71-
xor edx, edx ; Zero EDX
72-
mov edx, [fs:edx+48] ; Get a pointer to the PEB
71+
xor eax, eax ; Zero EAX (upper 3 bytes will remain zero until function is found)
72+
mov edx, [fs:eax+48] ; Get a pointer to the PEB
7373
mov edx, [edx+12] ; Get PEB->Ldr
7474
mov edx, [edx+20] ; Get the first module from the InMemoryOrder module list
7575
next_mod: ;
7676
mov esi, [edx+40] ; Get pointer to modules name (unicode string)
7777
movzx ecx, word [edx+38] ; Set ECX to the length we want to check
7878
xor edi, edi ; Clear EDI which will store the hash of the module name
7979
loop_modname: ;
80-
xor eax, eax ; Clear EAX
8180
lodsb ; Read in the next byte of the name
8281
cmp al, 'a' ; Some versions of Windows use lower case module names
8382
jl not_lowercase ;
@@ -92,10 +91,10 @@ def prepend_migrate(buf)
9291
push edi ; Save the current module hash for later
9392
; Proceed to iterate the export address table
9493
mov edx, [edx+16] ; Get this modules base address
95-
mov eax, [edx+60] ; Get PE header
94+
mov ecx, [edx+60] ; Get PE header
9695
9796
; use ecx as our EAT pointer here so we can take advantage of jecxz.
98-
mov ecx, [eax+edx+120] ; Get the EAT from the PE header
97+
mov ecx, [ecx+edx+120] ; Get the EAT from the PE header
9998
jecxz get_next_mod1 ; If no EAT present, process the next module
10099
add ecx, edx ; Add the modules base address
101100
push ecx ; Save the current modules EAT
@@ -113,7 +112,6 @@ def prepend_migrate(buf)
113112
xor edi, edi ; Clear EDI which will store the hash of the function name
114113
; And compare it to the one we want
115114
loop_funcname: ;
116-
xor eax, eax ; Clear EAX
117115
lodsb ; Read in the next byte of the ASCII function name
118116
ror edi, 13 ; Rotate right our hash value
119117
add edi, eax ; Add the next byte of the name
@@ -145,7 +143,7 @@ def prepend_migrate(buf)
145143
; We now automagically return to the correct caller...
146144
147145
get_next_mod: ;
148-
pop eax ; Pop off the current (now the previous) modules EAT
146+
pop edi ; Pop off the current (now the previous) modules EAT
149147
get_next_mod1: ;
150148
pop edi ; Pop off the current (now the previous) modules hash
151149
pop edx ; Restore our position in the module list

0 commit comments

Comments
 (0)