InjectDll icon indicating copy to clipboard operation
InjectDll copied to clipboard

How to load the dll from the char array?

Open R3uan3 opened this issue 1 year ago • 1 comments

Is possible to load the DLL from the char array generated by the ExtracArray instead of loading it from disk?

R3uan3 avatar Sep 13 '22 23:09 R3uan3

ExtractArray pulls out the code section of a DLL (ignores PE header and all other sections that are not code). For a carefully written DLL, the code section can be run as shellcode by writing it into executable memory and, for example, calling CreateThread on it. The reflective loader used in this project is one such example of a DLL where this works.

This project uses ExtractArray to convert the reflective loader DLL into shellcode, then appends an arbitrary DLL to that shellcode. ExtractArray is not meant to be run on the DLL provided to InjectDLL.exe.

If you want to load a DLL from memory instead of passing it to the command line, you can modify the code here where the DLL is read from a file:

https://github.com/UserExistsError/InjectDll/blob/979fefe4e920a21379a60aa400d826fc79570d45/InjectDll/InjectDll.cpp#L60-L66

If you want to convert this DLL to a char array, you can copy and modify ExtractArray to write the entire file to an array, and not just the .text section. The loop below could be rewritten to write out all imageSize bytes of the array image:

https://github.com/UserExistsError/InjectDll/blob/979fefe4e920a21379a60aa400d826fc79570d45/ExtractArray/ExtractArray.cpp#L84-L89

UserExistsError avatar Oct 08 '22 21:10 UserExistsError