Networking
MITM setup
Connect both ethernet adopters to laptop, turn on bridged networking in vm config, make sure you see both with ip link as eth1and eth2 where eth0is the virtual device bridging to the host machine. Make note of which eth is plugged into which switch port and which you want to be on the VLAN. In this case I have eth1as the internet interface and eth2as the VLAN interface.
Log into UniFi, make a VLAN, assign it to the port for the device under test and your eth2port. In this case I called it VLAN ID 30 but gave it 192.168.2.1/24 which is bad hygiene tbqh but I was figuring it out. Make sure to turn DHCP mode to None so we can be the DHCP server.

Enable ipv4 forwarding
Set up DHCP, I'm not doing DNS in this case because I didn't care but this is where you would if you need it. Start by setting up your static IP for the gateway (you).
Now configure dnsmasq, don't forget to back up your config first.
Then (re)start dnsmasq
The Big iptables Section
Flush your rules (don't do this blindly)
Set default policies (optional) to drop forwarded traffic by default. If you're redoing this a second time and have problems start by not doing this.
Turn on forwarding between interfaces
Turn on NAT (for Internet access from VLAN)
Since we're using mitmproxywe need to redirect http traffic to it, if traffic is transmitted on different port you'll need to adjust. Also make sure to change the --to-portto mitmproxy's port if like me you frequently have something on 8080already.
Check your work
Use the MITM
Start mitmproxyor mitmweb for the first time to get the cert, it'll be dropped at ~/.mitmproxy/mitmproxy-ca-cert.pem and of course you'll need to load it onto the device under test.
For future reference, Matt Brown has a bunch of helper scripts at https://github.com/nmatt0/mitmtools which are great references.
Last updated