Attack-and-Defend Lab: pfSense or OPNsense Firewall Plus Vulnerable Targets
Part 7 of our home-lab series: segment your lab with a pfSense or OPNsense firewall VM and add deliberately vulnerable targets such as Metasploitable, DVWA and OWASP Juice Shop.
Part of our free Build Your Own Cyber Lab series. Work through it in order, or jump to the part you need.
- Plan your lab: hardware, hypervisors and safe networking
- VirtualBox and VMware basics, then Kali, Parrot and Windows 11
- Beyond VirtualBox: Hyper-V, VMware Workstation and Proxmox
- Dual boot Kali Linux and Windows safely
- Ubuntu in your lab: desktop, server, SSH and Docker
- Active Directory lab with Windows Server
- Attack-and-defend network: firewall and vulnerable targets (you are here)
- Metasploitable 2 and 3: install and first exploits
- Blue-team lab: Wazuh, Sysmon and Security Onion
- Android app testing lab: emulator, MobSF, Frida and Burp
- OT/ICS security lab: OpenPLC, Modbus and an HMI
- Network lab: build it in Packet Tracer or GNS3, read it in Wireshark
Why add a firewall VM
So far each lab network has been either fully isolated or fully open. A firewall VM gives you the middle ground real networks have: segments that can talk only where you allow it, a controlled path to the internet for updates, and logs of every connection - which is exactly what you need to practise both attacking and defending.
The target layout
| Segment | Network | Contains | Internet |
|---|---|---|---|
| WAN | NAT (hypervisor) | Firewall's outside leg | Yes |
| CORP | 10.20.0.0/24 | DC01, WS01 from part 6 | Updates only, via firewall |
| ATTACK | 10.30.0.0/24 | Kali, vulnerable targets | None |
Step 1: Build the firewall VM
pfSense CE and OPNsense are both free, FreeBSD-based firewalls with web interfaces. Pick either; the steps are nearly identical.
- Create a VM with 1-2 GB RAM, 1 CPU, a 16 GB disk and three network adapters: Adapter 1 on NAT (WAN), Adapter 2 on the CORP isolated network, Adapter 3 on the ATTACK isolated network.
- Install from the ISO with default options.
- At the console menu, assign interfaces: WAN to the first adapter, LAN to CORP, and OPT1 to ATTACK. Set LAN to
10.20.0.1/24and enable its DHCP server if you like. - From WS01 (on CORP) browse to
https://10.20.0.1and finish the setup wizard. Change the default admin password first. - Enable OPT1, give it
10.30.0.1/24, and rename it ATTACK.
Step 2: Write the rules
Firewall rules are evaluated per interface, top to bottom, first match wins.
- ATTACK interface: allow ATTACK net to ATTACK net; block ATTACK net to any other destination. Vulnerable machines must not reach CORP or the internet.
- CORP interface: allow CORP to the internet (for Windows Update), and block CORP to ATTACK unless an exercise needs it.
- Exercise rules: when you want Kali to attack the domain, add a specific rule (Kali's IP to DC01's IP), then disable it afterwards.
Turn on logging for block rules and watch Status > System Logs > Firewall while you scan from Kali - seeing your own nmap scan get blocked teaches more than any diagram.
Step 3: Add vulnerable targets
Put every target on ATTACK only.
- Metasploitable 2 and 3: Rapid7's intentionally vulnerable Linux and Windows VMs. Part 8 walks through installing both. Never put them on a bridged or NAT network.
- DVWA (Damn Vulnerable Web Application): a PHP/MySQL app with adjustable difficulty for SQL injection, XSS, command injection and file upload practice.
- OWASP Juice Shop: a modern, intentionally insecure web shop with a scoreboard of challenges covering the OWASP Top 10.
- VulnHub machines: hundreds of community-made vulnerable VMs. Read the description for the intended network setup and difficulty.
The easiest way to run DVWA and Juice Shop is Docker on a small Linux VM on the ATTACK network (temporarily give it internet via a rule while pulling images):
sudo apt install -y docker.io
sudo docker run -d -p 3000:3000 bkimminich/juice-shopThen browse to http://<vm-ip>:3000 from Kali. DVWA's own README describes its current Docker setup.
Step 4: Practise both sides
- Recon from Kali:
nmap -sV 10.30.0.0/24to find the targets. - Exploit a known-vulnerable web app such as DVWA, or work through Juice Shop's scoreboard.
- Defend: read the firewall logs, then add the rule that would have stopped the scan or the exploit, and confirm it works.
Our Haxplain lessons cover SQL injection, XSS, command injection and more, each with the detection and fix - perfect companions to DVWA and Juice Shop.
Keep it legal and contained
Only attack machines you own or have written permission to test. Vulnerable VMs and malware samples belong on an isolated network with no route to your home LAN or the internet, and never expose a deliberately vulnerable machine with a bridged adapter or a port forward.
Next step
Part 8 installs Metasploitable 2 and 3 and walks through your first exploits against them.
Sources & References
Daniel Agrici
CEH, Security+, PenTest+
Daniel is the founder of CyberCertPrep. With a background in penetration testing and security consulting, he has passed 8 cybersecurity certifications and writes about exam strategies and career development.
Ready to start practicing?
86 certifications. 157,000+ questions. 20 free per cert.