Introduction
Penetration testing tools such as mitmproxy and Burp Suite are invaluable for intercepting, inspecting, and manipulating HTTP requests. To maintain a focused scope, this article will concentrate on the versatile mitmproxy utility, though Burp Suite could be employed just as effectively for similar tasks.
Note
Running mitmproxy on Docker
While mitmproxy can be installed directly through a binary package or via pip, we'll utilise Docker containers for a cleaner, more isolated setup. We'll work with the official mitmproxy Docker image.
First, let's create a directory for our certificates in an XDG-compatible location:
mkdir -p $HOME/.config/mitmproxy
Important
We can now launch the mitmproxy container:
docker run --rm -it -v $HOME/.config/mitmproxy:/home/mitmproxy/.mitmproxy -p 8080:8080 mitmproxy/mitmproxy
The mitmproxy image also provides access to the mitmdump utility:
docker run --rm -it -p 8080:8080 mitmproxy/mitmproxy mitmdump
To access the mitmweb graphical interface, we need to expose port 8081:
docker run --rm -it -p 8080:8080 -p 127.0.0.1:8081:8081 mitmproxy/mitmproxy mitmweb --web-host 0.0.0.0
Once the container is running, you can access the web interface by pointing your browser to http://localhost:8081/.
Configure browser network proxy
With mitmproxy running, we need to configure our browser to redirect traffic through it. In Firefox Developer Edition, we can modify the network settings through about:config by setting the following values:
network.proxy.httpto127.0.0.1network.proxy.http_portto8080network.proxy.typeto1
Alternatively, these values can be configured in the browser's Settings (look for Network Settings at the bottom of the General panel).
After configuring the browser's proxy settings, redirected traffic will appear as mitmproxy flows in your terminal, allowing you to inspect and manipulate requests and responses.
Proxying curl and wget
Command-line tools like curl and wget can also be configured to route their traffic through mitmproxy. This can be accomplished either by setting environment variables or by providing inline instructions:
export http_proxy=localhost:8080
export https_proxy=localhost:8080
curl ifconfig.io
wget -O /dev/null ifconfig.io
## or ##
http_proxy=localhost:8080 https_proxy=localhost:8080 curl ifconfig.io
http_proxy=localhost:8080 https_proxy=localhost:8080 wget -O /dev/null ifconfig.io
Tip
These redirected curl and wget requests should now be visible in your mitmproxy terminal as interactive flows, allowing for inspection and modification.