Using pfSense to selectively allow traffic during dynamic malware analysis


Right now your enterprise network with all its users and systems is a live production lab for any malware or attacker that comes along. If you have an EDR you have an advantageous view of the the endpoints. How about installing that same EDR on your malware analysis system so you can review signatures and TTPs from malware in a controlled environment? You'll be surprised the difference it makes in finding new TTPs.

I have always felt it would be nice to be able to allow some traffic out of a dynamic malware analysis lab without letting it all out. As a rule I don't allow malware to talk directly to the Internet without a very good reason to do so. Now with EDR technology available it became crucial to allow the EDR to be able to connect to the mothership while restricting all other traffic to the host only malware network. But once this is setup we can expand things a bit and allow api.ipify.org and other benign traffic.

Here is how I did it. If you have a different way I would love to hear about it.

Prerequisite
Have a working dynamic malware analysis setup with inetsim or fakenet (potentially others) that controls and returns DNS as the IP of the fake system and redirects IP addresses to the fake system as well. There is a test plan at the bottom to verify a fully functioning system. DNS is normal but I have seen setups that did not redirect IP based traffic. If you are setting up your very first analysis rig don't use these instructions, there are better resources.

My existing setup
Virtual box

Host only network for Inetsim and victim VMs. Inetsim is setup to resolve DNS names back to itself and redirect direct IP based addresses to itself as well.

The victim VM is setup normally as an office user with some tools installed but no AV and it does have our EDR installed which points back to the DMX just like a workstation.

Target setup
Add pfSense to the lab to provide positive control of outbound traffic to the WAN (Virtual Box NAT network) while keeping everything else on the host only network.


pfSense setup

Create a new virtualbox host and attach the pfsense iso.

Add two networks
Host only (for the victim machine and inetsim or fakenet)
NAT for Internet access

Make a note of the mac address for the LAN for later setup.

Power up the VM and let it install.

Option 1 Assign Interfaces
Match up the LAN interface with the correct MAC address
Assign the upstream gateway to your inetsim or fakenet address 192.168.56.101
(you can also do this later in the web interface under interfaces)

Option 2 Set interface(s) IP address
I leave a gap in the low range DHCP from Virtual Box host only network so that I can assign static addresses if necessary. In this case I use the next available address up from my Inetsim address (currently the gateway address on the victims)
192.168.56.102/24

Now you will see the URL for pfsense http://192.168.56.102

The rest of the setup will occur in the web interface.

Setup default DNS IP
Since Inetsim is providing my resolution in the hostonly network I set that IP as the default DNS address. I will actually turn off DNS on pfsense so this may not be necessary. Once the install is complete, turn off  Services/ DNS Resolver and turn off  Services / DNS Forwarder.




Make sure to save changes at each step

Default Gateway
If the overall default gateway was not already set we can set it in System / Routing / Gateways
We want the overall gateway to be the inetsim server (LAN) which is handling all the DNS and IP redirecting for traffic spoofing.




Hybrid NAT
Not sure why this needs to be changed but it does.
Go to Firewall / NAT / Outbound and select Hybrid NAT and save the changes to allow rules to be created.
Create a rule for any to WAN




Firewall rules
The original ruleset looks something like this. I am not using IPV6 so that rule will be turned off.





At first I thought to disable the default rule allowing any any for LAN to WAN but that kills all traffic. The way this is working is that the default gateway is the LAN so while traffic is allowed to the WAN there is no gateway for it to get there until we specifically add rules for each destination we want to allow out.


Testing
At this point we need to fire up our inetsim or fakenet and the victim/analysis VMs to make sure things are working as expected. I need to modify the gateway address on the victim to be the pfsense firewall address 192.168.56.102. Once that is done test the different scenarios. Since we haven't added any rules yet NO traffic should be able to leave the host only network nor get a valid DNS from outside the host only network.

DNS resolution
  • Should return the default address from inetsim that is used to spoof traffic.

Ping a domain
  • Should resolve the name to the inetsim IP and ping correctly

Ping an IP address
  • Should ping correctly

Web browser to FQDN / url
  • Should resolve to the default inetsim address and return the fake page

Web browser to IP address
  • Should return the fake page from inetsim



Add a destination for outbound traffic
Do a lookup for the target you want to allow out of the host only network and add that FQDN and address to your inetsim/fakenet static dns entries.

Here is an example
api.ipify.org 54.225.92.64

Add the rule to pfSense
Add a new rule and put in the destination IP or network address, then open Advanced Options in the Extra Options section to select the WAN network gateway.




Save the rule and allow the changes.

Here is the finished rule. Note that the gateway is the WAN. Earlier we set the default gateway for pfSense to the LAN forcing everything into host only. Having this rule above the others changes the gateway for this specific traffic only.





Next do the same thing for the destination network for your EDR. This was the important traffic that we needed out in the first place.


Disable gateway monitoring
There is a constant ping which will fill up our wireshark traces so lets disable it.



Back to testing
Make sure the original tests still work as designed.

Test traffic to allowed destinations
  • Web access to api.ipify.org works as expected
  • EDR traffic is flowing normally

Wrap up
That should be it, now instead of running two VMs for analysis you'll need to run three but the victim can now be rebooted, snap shot or whatever without risking traffic leaving the host only network. If pfSense is off the victim gateway is incorrect so you'll quickly see the problem.

Happy hunting.


Comments

  1. hi. i have a question about some material on this post. You said in pfsense setup section like this "In this case I use the next available address up from my Inetsim address (currently the gateway address on the victims)". What do you mean by "currently the gateway address on the victims"? Is it the inetsim server address or this pfsense address? What should be the gateway of the victim?

    ReplyDelete

Post a Comment

Popular posts from this blog

Misleading extensions Xls.exe Doc.exe Pdf.exe

Netconn from suspicious directories

Powershell DNS C2 Notes