@@ -128,13 +128,20 @@ def generate_simple_LoadLibraryW_32_with_error(k32):
128128 code += x86 .Ret ()
129129 return code .get_code ()
130130
131- def generate_simple_LoadLibraryW_64 (load_libraryW , GetLastError , remote_store ):
131+ def generate_simple_LoadLibraryW_64_with_error (k32 , remote_store ):
132+ """A shellcode that execute LoadLibraryW(param) and store the value at a fixed address.
133+ This allow a 32b process to inject and retrieve a 64bit module address
134+
135+ Thread return value is the result of GetLastError()
136+ """
137+ load_libraryW = k32 .pe .exports ["LoadLibraryW" ]
138+ GetLastError = k32 .pe .exports ["GetLastError" ]
132139 code = RemoteLoadLibrayStub = x64 .MultipleInstr ()
133140 code += x64 .Mov ("RAX" , load_libraryW )
134141 code += (x64 .Push ("RDI" ) * 5 ) # Prepare stack
135142 code += x64 .Call ("RAX" )
136143 code += x64 .Mov (x64 .deref (remote_store ), "RAX" )
137- code += x64 .Mov ("RAX" , GetLastError )
144+ code += x64 .Mov ("RAX" , GetLastError ) # Add a jump ?
138145 code += x64 .Call ("RAX" )
139146 code += (x64 .Pop ("RDI" ) * 5 ) # Clean stack
140147 code += x64 .Ret ()
@@ -161,12 +168,6 @@ def load_dll_in_remote_process(target, dll_path):
161168 if k32 :
162169 # We have kernel32 \o/
163170 k32 = k32 [0 ]
164- try :
165- load_libraryW = k32 .pe .exports ["LoadLibraryW" ]
166- GetLastError = k32 .pe .exports ["GetLastError" ]
167- except KeyError :
168- raise ValueError ("Kernel32 have no export <LoadLibraryA> (wtf)" )
169-
170171 with target .allocated_memory (0x1000 ) as addr :
171172 if target .bitness == 32 :
172173 shellcode32 = generate_simple_LoadLibraryW_32_with_error (k32 )
@@ -193,7 +194,7 @@ def load_dll_in_remote_process(target, dll_path):
193194 param_addr = addr
194195 addr += len (full_dll_name )
195196 shellcode_addr = addr
196- shellcode = generate_simple_LoadLibraryW_64 ( load_libraryW , GetLastError , retval_addr )
197+ shellcode = generate_simple_LoadLibraryW_64_with_error ( k32 , retval_addr )
197198 target .write_memory (shellcode_addr , shellcode )
198199 t = target .create_thread (shellcode_addr , param_addr )
199200 t .wait ()
0 commit comments