Use DInvoke & Process Hollowing to bypass AV and Firewall

In a previous post I described how to create a stager executable that implements DInvoke and can achieve an undetected meterpreter session with the help of a python server. Since the results where very promising regarding the detection rates and the session was not detected even after loading external modules such as kiwi, I decided to do some extra modifications and tests.

A very interesting result came by implementing process hollowing using DInvoke in order to bypass both the 'Antivirus' as well as the 'IDS/Firewall' part of Avira Internet Security. The thing is, that, Avira IS by default will block internet access to applications that are considered 'Not Trusted', such as not signed or well known executables. For this reason the user has to specifically click 'Allow' for the connection to take place so as to obtain a meterpreter session (after clicking 'Allow' the session is established and operates unhindered).

The good news is that this can easily be bypassed by implementing process hollowing or shellcode injection using DInvoke. In this post I will demonstrate how to use the process hollowing technique since shellcode injection is rather simple.

If you want to understand how process hollowing works you can see this post and this for a basic example of DInvoke.

This time I have combined the required code files from RastaMouse's repo into a single project so as to build a single executable and avoid the overhead of embedding the DLLs to the final program. If you want to reduce the surface even further you can remove methods that have zero references.

The main part of the program can be seen below. As always there are comments to explain the main steps:

  • Make sure to choose the target process wisely because common options such as explorer and svchost get detected.

  • As for today the plain shellcode compiled within the exe is not detected, but if it does, you can use the metasploit encoders or custom encryption & decryption within the program.

  • I used the reverse_https payload with a custom certificate. You can generate your own using the following commands in kali:

PoC

Last updated