2014-01-27 01:16:23 +00:00
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.
2015-05-18 00:05:29 +00:00
1. **Configure VirtualBox Network Adapters for the proxy machine**
The network setup is simple: `internet < -- > proxy vm < -- > (virtual) internal network`.
For the proxy machine, *eth0* represents the outgoing network. *eth1* is connected to the internal network that will be proxified, using a static ip (192.168.3.1).
2014-01-27 01:16:23 +00:00
< hr > VirtualBox configuration:
2015-05-24 02:09:51 +00:00
< img class = "img-responsive" src = "@!urlTo('tutorials/transparent-dhcp/step1_vbox_eth0.png')!@" / > < br > < br >
< img class = "img-responsive" src = "@!urlTo('tutorials/transparent-dhcp/step1_vbox_eth1.png')!@" / >
2014-01-27 01:16:23 +00:00
< br > Proxy VM:
2015-05-24 02:09:51 +00:00
< img class = "img-responsive" src = "@!urlTo('tutorials/transparent-dhcp/step1_proxy.png')!@" / >
2014-01-27 01:16:23 +00:00
< hr >
2015-05-18 00:05:29 +00:00
2. **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.
2014-01-27 01:16:23 +00:00
2015-05-18 00:05:29 +00:00
- Before we get to that, we need to fix some Ubuntu quirks:
**Ubuntu >12.04** runs an internal dnsmasq instance (listening on loopback only) by default
2014-01-27 01:16:23 +00:00
< a href = "https://www.stgraber.org/2012/02/24/dns-in-ubuntu-12-04/" > [1]< / a > . For our use case, this needs to be
2015-05-18 00:05:29 +00:00
disabled by changing < br > `dns=dnsmasq` to `#dns=dnsmasq` in */etc/NetworkManager/NetworkManager.conf*
2014-01-27 01:16:23 +00:00
and running `sudo restart network-manager` afterwards.
2015-05-18 00:05:29 +00:00
- Now, dnsmasq can be be installed and configured:
`sudo apt-get install dnsmasq`
Replace */etc/dnsmasq.conf* with the following configuration:
2014-01-27 01:16:23 +00:00
< pre > \# 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.1
< / pre >
2015-05-18 00:05:29 +00:00
Apply changes:
2014-01-27 01:16:23 +00:00
`sudo service dnsmasq restart`
< hr >
Your proxied machine's network settings should now look similar to this:
2015-05-24 02:09:51 +00:00
< img class = "img-responsive" src = "@!urlTo('tutorials/transparent-dhcp/step2_proxied_vm.png')!@" / >
2014-01-27 01:16:23 +00:00
< hr >
2015-05-18 00:05:29 +00:00
3. **Set up traffic redirection to mitmproxy**
To redirect traffic to mitmproxy, we need to add two iptables rules:
2014-01-27 01:16:23 +00:00
< pre class = "terminal" >
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
< / pre >
2015-05-18 00:05:29 +00:00
4. If required, < a href = "@!urlTo('certinstall.html')!@" > install the mitmproxy
2014-01-27 01:16:23 +00:00
certificates on the test device< / a > .
2015-05-18 00:05:29 +00:00
5. Finally, we can run < code > mitmproxy -T< / code > .
2014-01-27 01:16:23 +00:00
The proxied machine cannot to leak any data outside of HTTP or DNS requests.