Reputation: 31
I want to route, using iptables, all the OUTGOING HTTP requests from my machine to mitmdump running on the same machine, and then to the original destination.
I'm using this iptables rule but it seems that it doesn't work:
$ sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination 127.0.0.1:8080
Can somebody explain me why it isn't the right solution and what is the correct way to accomplish this?
Upvotes: 1
Views: 2106
Reputation: 31
Solved using the owner module of iptables:
iptables -t nat -A OUTPUT -p tcp --dport 80 -m owner ! --uid-owner 0 -j DNAT --to 127.0.0.1:8080
And then launch mitmdump as root. Or better create a new user for mitmdump and replace 0 with the uid of the user.
Upvotes: 2
Reputation: 7676
In accordance with http://docs.mitmproxy.org/en/stable/transparent/linux.html , you want to add those rules to the PREROUTING table:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8080
Upvotes: -1