This walkthrough illustrates how to set up transparent proxying with mitmproxy. We use VirtualBox VMs with an Ubuntu proxy machine in this example, but the general principle can be applied to other setups.
internet <--> proxy vm <--> (virtual) internal network
. Configure DHCP and DNS
We use dnsmasq to provide DHCP and DNS in our internal network.
Dnsmasq is a lightweight server designed to provide DNS (and optionally DHCP and TFTP) services to a small-scale
network.
dns=dnsmasq
to #dns=dnsmasq
in /etc/NetworkManager/NetworkManager.conf sudo restart network-manager
afterwards.sudo apt-get install dnsmasq
# Listen for DNS requests on the internal network interface=eth1 # Act as a DHCP server, assign IP addresses to clients dhcp-range=192.168.3.10,192.168.3.100,96h # Broadcast gateway and dns server information dhcp-option=option:router,192.168.3.1 dhcp-option=option:dns-server,192.168.3.1Apply changes:
sudo service dnsmasq restart
Set up traffic redirection to mitmproxy
To redirect traffic to mitmproxy, we need to add two iptables rules:
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 \ -j REDIRECT --to-port 8080 iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 443 \ -j REDIRECT --to-port 8080
If required, install the mitmproxy certificates on the test device.
Finally, we can run mitmproxy -T
.
The proxied machine cannot to leak any data outside of HTTP or DNS requests.