Mitmproxy: Pentest Guide, Commands, and Tools for HTTPS

How to use mitmproxy to intercept HTTPS and Android traffic: CA certificate, mitmdump, mitmweb, WireGuard, transparent proxy, and Python addon in pentest.
- Posted on 2026-01-22
- Reading time: 10 min
Mitmproxy: How to Intercept and Modify HTTP and HTTPS Traffic (A Practical Pentest Guide) #
Mitmproxy is an open-source man-in-the-middle proxy that sits between a client and a server, decrypts HTTP and HTTPS traffic, and lets you read, modify, and replay it. In a pentest, it helps you see what an app and its backend are really saying to each other: headers, cookies, tokens, JSON, WebSockets.
In this guide, you'll install it, intercept your first HTTPS traffic, install the mitmproxy certificate , switch to Android , write a Python addon, and learn how to protect yourself from those who use it against you. Each command is designed to work as-is, in your own lab.
Use mitmproxy only on your own traffic or on systems for which you have written authorization. Intercepting other people's traffic without permission is a crime.
What is mitmproxy and what is it used for in pentesting? #
A mitm proxy is a proxy that doesn't just forward packets: it opens them. Technically, it's an interception tool written in Python that supports HTTP/1, HTTP/2, HTTP/3, WebSockets, and even raw TCP and UDP.
In the work of a red teamer you use it to:
- Analyze APIs and web apps when you want to see every request without opening the browser (useful for IDOR , JWT and session problems).
- Intercept mobile app traffic, especially Android, to find hidden endpoints and secrets in traffic.
- Automate changes to requests and responses with Python scripts.
- Save and replay traffic from the command line, without an interface.
If you're familiar with Burp Suite , mitmproxy will seem similar in purpose but very different in use: fewer clicks, more terminal and scripting.
How HTTPS Interception Works #
HTTPS is encrypted between client and server, so a proxy in the middle normally doesn't see anything. Mitmproxy solves this problem by opening two separate TLS sessions . One with the client, using a fake certificate generated on the fly. One with the real server, using the real certificate.
When you first run mitmproxy, it creates its own CA (certificate authority) . When the client requests a site, mitmproxy first contacts the real server, copies its certificate data (name, organization, SAN), and generates an identical one signed by its CA. The client only accepts it if it trusts that CA. To do this, you must install the certificate on the device you want to intercept.
If you want the bigger picture of the attack, also read the guide to Man in the Middle and How HTTP and HTTPS Works.
Installing mitmproxy on Kali Linux, Linux, and Windows #
On Kali Linux (and Debian/Ubuntu) it is in the repositories:
# Install from the distro repository
sudo apt update && sudo apt install -y mitmproxy
# Check that it works
mitmproxy --versionOn any Linux or macOS you can use pipx, which isolates it from the rest of the system:
# Install in an isolated environment
pipx install mitmproxySu Windows (Are you looking for “mitm windows”?) Download the installer from the official mitmproxy website. On Windows, the console version mitmproxy not supported: use mitmweb o mitmdump.
The three tools: mitmproxy, mitmweb, and mitmdump #
With one installation, you get three commands. They do the same thing, but the interface changes.
| Command | Interface | When to use it |
|---|---|---|
mitmproxy | Interactive console in the terminal | Analysis and editing by hand, all from the keyboard |
mitmweb | Web interface (port 8081) | For those who prefer the browser, great for starting out |
mitmdump | Only log lines, no UI | Script, automation, traffic saving and replay |
Mitmdump is the equivalent of tcpdump for HTTP: It doesn't show anything interactive, but you can put it in a pipeline or script. If you're used to tcpdump
o Wireshark
, the difference is that here you see the traffic already decrypted at the application level.
Mitmproxy Tutorial: Intercepting Your First HTTPS Traffic #
Let's do a full test locally, without phones. Terminal 1, start the proxy:
# Start the console proxy, it listens on port 8080 by default
mitmproxyTerminal 2, send an HTTPS request through the proxy:
# Send an HTTPS request through the proxy, trusting the mitmproxy CA
curl --proxy http://127.0.0.1:8080 \
--cacert ~/.mitmproxy/mitmproxy-ca-cert.pem \
https://httpbin.org/getIn Terminal 1 you will see the request appear. Press Invio To open it: you'll find headers, cookies, and a cleartext response. This is HTTPS traffic. intercepted: curl trusts the fake certificate because you passed it the mitmproxy CA with --cacert.
The keys you use most in the console:
| Key | What does he do |
|---|---|
i | Set up an interception filter (block matching requests) |
a | Let the blocked request pass |
e | Edit the selected request or response |
r | Replay the request (replay) |
f | Filter the stream list |
? | Contextual help |
q | Logout |
Practical example: prizes i, you write ~u httpbin & ~q and confirm. Now all requests to httpbin will stop. before to leave: you change it with e, then you pass it with a.
For the web version:
# Start the web interface, open the URL printed in the terminal (it includes an access token)
mitmwebMitmProxy Certificate: Where to Find It and How to Install It #
On first start mitmproxy creates its CA in ~/.mitmproxyThese are the files:
| File | Content | Use |
|---|---|---|
mitmproxy-ca.pem | Certificate and private key | Never distribute it |
mitmproxy-ca-cert.pem | Certificate only, PEM format | Linux, macOS, most clients |
mitmproxy-ca-cert.p12 | PKCS12 format | Windows |
mitmproxy-ca-cert.cer | Same as PEM, different extension | Some Androids |
The CA is generated unique for each installation: No one else can use yours to intercept you. Whoever has yours mitmproxy-ca.pem Yes, you can, so protect it like a private key.
The fastest way to install it is the magic domain mitm.it: set proxy on your device, open http://mitm.it from your browser and download the certificate for your system. If you can't use it, install it manually.
Linux (Debian, Ubuntu, Kali), to make the whole system trustworthy:
# Copy the CA into the system trust store and refresh it
sudo cp ~/.mitmproxy/mitmproxy-ca-cert.pem /usr/local/share/ca-certificates/mitmproxy.crt
sudo update-ca-certificatesWindows, from a prompt with administrator privileges:
:: Add the mitmproxy CA to the trusted root store
certutil -addstore root mitmproxy-ca-cert.cerIf you see a certificate error ( mitmproxy certificate error ), the client usually doesn't trust the CA, or the app is using pinning (more on this below). Firefox has its own certificate store and doesn't use the system one; you import it separately.
Mitmproxy Modes: Which One to Choose? #
The regular proxy is the one you used above: the client knows it's talking to a proxy. It only works if the application respects the proxy settings. When it doesn't (many Android apps), other methods are needed.
| modality | Command | When to use it |
|---|---|---|
| Regular | mitmproxy | The client supports an HTTP proxy. Always start from here. |
| Local capture | mitmproxy --mode local | Intercept apps on the same machine |
| wire guard | mitmweb --mode wireguard | External devices and apps that bypass the proxy |
| Reverse | mitmdump --mode reverse:https://httpbin.org | Put mitmproxy in front of a server |
| Transparent | mitmdump --mode transparent | Changing the gateway of a network without configuring the client |
| Upstream | mitmdump --mode upstream:http://127.0.0.1:3128 | Putting mitmproxy in front of another proxy |
| SOCKS5 | mitmdump --mode socks5 | Clients who speak SOCKS |
| TUN | sudo mitmdump --mode tun | Virtual interface on Linux, manual routing |
| DNS | mitmdump --mode dns | Scriptable DNS server |
Three details that save hours:
- Local capture you can limit it to one process:
mitmproxy --mode local:curlonly catch curls,--mode local:42only PID 42. On Linux you need itsudo, it only captures outgoing traffic and official support is for kernel 6.8 or higher (use eBPF). Containers must use the host network. - wire guard It runs in userspace: no administrator privileges are required. However, you cannot use it to intercept traffic from the machine running mitmproxy.
- Transparent On Linux, it requires routing and redirection rules. For a lab:
# Enable IP forwarding and stop sending ICMP redirects
sudo sysctl -w net.ipv4.ip_forward=1
sudo sysctl -w net.ipv4.conf.all.send_redirects=0
# Redirect incoming web traffic to mitmproxy (check your interface name with: ip -br a)
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8080
# Start mitmproxy in transparent mode
mitmdump --mode transparent --showhostThe client must use the machine with mitmproxy as its default gateway . If you want to send tool traffic through a proxy on the other side, also see proxychains and the case of an intermediate proxy like Squid on port 3128.
Mitmproxy Android: Intercepting App Traffic #
To intercept Android traffic you have two options: Wi-Fi proxy and WireGuard.
Route 1: Wi-Fi proxy. On your phone, in the Wi-Fi settings, set the proxy to manual: PC IP address with mitmproxy and port 8080. Then install the certificate. Starting with recent versions of Android, the CA certificate can no longer be installed by opening it in a browser: copy it to your phone and install it from Settings, Security, Encryption and credentials, Install a certificate, CA certificate.
# Push the CA certificate to the connected device (Android accepts the .cer extension)
adb push ~/.mitmproxy/mitmproxy-ca-cert.cer /sdcard/Download/If you use theAndroid emulator the PC is reachable at the fixed address 10.0.2.2, then you can set the proxy from adb:
# Set the global proxy on the emulator (the host machine is 10.0.2.2)
adb shell settings put global http_proxy 10.0.2.2:8080
# Remove the proxy when you are done
adb shell settings put global http_proxy :0The problem. Starting with Android 7, apps don't trust user-installed CA certificates by default ; they only trust system certificates. Chrome and the browser work fine. Any app, however, rejects the mitmproxy certificate. You have three options: install the CA as a system certificate (possible on an emulator or rooted device; the procedure is in the official mitmproxy documentation), use a debug build of your app with a network security config that accepts user CAs, or remove the pinning.
Route 2: WireGuard. Many apps bypass the proxy settings on your Wi-Fi and go straight to the server. With WireGuard, that doesn't matter: all your device's traffic passes through the tunnel.
# Start mitmweb as a WireGuard server (listens on 51820/udp by default)
mitmweb --mode wireguardMitmweb displays a QR code with the configuration: you scan it with the WireGuard app on your phone, and the traffic goes to mitmproxy without touching your Wi-Fi settings. This also requires the CA installed, and the same rules apply as for Android 7 above.
SSL Pinning: When MitmProxy Sees Nothing #
If the app connects but you only see TLS handshake errors in mitmproxy, it's almost always certificate pinning : the app only accepts one specific certificate or key, so it ignores your CA.
You have two options. If you don't need the contents of those connections, tell mitmproxy not to touch them:
# Do not intercept traffic to the pinned domain, just tunnel it
mitmproxy --ignore-hosts '^httpbin\.org:443$'If you need it, you'll need to modify the app. The mitmproxy documentation lists tools designed for this: apk-mitm (removes pinning from APK), objection (runtime bypass with Frida) e android-unpinner
(injects Frida and unpinning script). On iOS with jailbreak there is ssl-kill-switch2These tools are used only on your apps or with permission.
Filters: Find the traffic that matters #
When traffic grows, filters are the difference between understanding and getting lost. They work in the console (f), in the interception (i) and as a topic of mitmdump.
| Filter | Meaning |
|---|---|
~d httpbin.org | Domain |
~u /api/ | URL that contains /api/ |
~m POST | HTTP method |
~c 401 | Response code |
~t json | Content-Type |
~b password | Body that contains the word |
~q / ~s | Requests only / Answers only |
&, |, ! | AND, OR, NOT |
Example from mitmdump: only show POSTS to a domain.
# Print only POST requests to httpbin.org
mitmdump "~m POST & ~d httpbin.org"Mitmproxy Python: Addons and Automation #
Here mitmproxy becomes a serious tool. A addon It's a Python script with functions that mitmproxy calls on every event: request when a request arrives, response when the response arrives. Save this file as aggiungi_header.py:
from mitmproxy import http
def request(flow: http.HTTPFlow) -> None:
# Add a custom header to every request going to httpbin.org
if flow.request.pretty_host == "httpbin.org":
flow.request.headers["X-Hackita-Test"] = "intercepted"Start it with mitmdump -s and make a request:
# Terminal 1: run the addon
mitmdump -s aggiungi_header.py
# Terminal 2: httpbin echoes back the headers it receives, including ours
curl --proxy http://127.0.0.1:8080 \
--cacert ~/.mitmproxy/mitmproxy-ca-cert.pem \
https://httpbin.org/headersIn the answer appears X-Hackita-Test: intercepted: the request has been modified in flight, the server has already received it changed.
Second addon, more for pentester: log all tokens and cookies that pass through, to understand how an app authenticates requests. Save it as estrai_token.py:
import logging
from mitmproxy import http
# Headers that usually carry credentials or session data
SENSITIVE_HEADERS = ("authorization", "cookie", "x-api-key")
def request(flow: http.HTTPFlow) -> None:
for header_name in SENSITIVE_HEADERS:
header_value = flow.request.headers.get(header_name)
if header_value:
logging.info(f"{flow.request.pretty_host} | {header_name}: {header_value}")# Run it and browse the target app through the proxy
mitmdump -s estrai_token.pyIf a token appears in the clear, you now know where to look: it's the starting point for session hijacking or to understand how that app's JWTs are constructed . For broader API attacks, see the guide to modern API attacks.
An addon can also respond instead of the server , to simulate a backend and see how the app reacts:
from mitmproxy import http
def request(flow: http.HTTPFlow) -> None:
# Answer directly from the proxy: the request never reaches the real server
if flow.request.pretty_url == "https://httpbin.org/anything":
flow.response = http.Response.make(
200,
b'{"role": "admin"}',
{"Content-Type": "application/json"},
)Mitmdump: Save, Read, and Replay Traffic #
With -w Save all your streams to a file. Then you can reread or replay them whenever you want, even offline.
# Capture traffic to a file while you browse through the proxy
mitmdump -w sessione.mitm
# Read the file back without starting a proxy server (-n = no server, -r = read)
mitmdump -nr sessione.mitm
# Replay the captured client requests against the real servers
mitmdump -n -C sessione.mitmReplay is useful for retrying a request after fixing a bug, or for replaying the same stream with a different token to see if the server is actually checking authorization.
Mitmproxy in a pentest workflow #
An order that works on a web app or mobile app:
- Start with the regular proxy. If traffic doesn't get through, switch to WireGuard or local capture.
- Navigate the entire app with
mitmweband look at the list of endpoints: you often find undocumented APIs. - Search streams with
~bwords liketoken,password,secret,key. - Edit with
eroles, IDs and parameters and see the responses. - When a test works, turn it into an addon and relaunch it automatically.
- Save session with
-w: you need it as evidence in the report.
Mitmproxy vs Burp Suite vs Wireshark #
| Mitmproxy | Burp Suite | Wireshark | |
|---|---|---|---|
| Subscription | Application (HTTP, WebSocket) | Application (web) | Network (packets) |
| Decrypt HTTPS | Yes, with his CA | Yes, with his CA | Only with session keys |
| Interface | Terminal, web, script | Graphics | Graphics |
| Strength | Python Automation, Mobile, Replay from CLI | Integrated scanner and web tools | Analysis of any protocol |
They're not alternatives: in serious pentests, you use them together. Mitmproxy for scripting and mobile apps, Burp for scanning and manual work, and Wireshark when the problem is HTTP-based.
How to Defend Against a MITM Proxy Attack #
If you work on the defensive side, these are the points that matter:
- HSTS It forces the browser to use HTTPS only and blocks downgrades. But it doesn't stop an attacker with a CA installed on the device.
- certificate pinning In sensitive apps: The app rejects any certificate other than its own, so even a fake CA won't do the trick.
- Check the root certificate store on endpoints. The mitmproxy certificate is named
mitmproxy, so you can find it right away:
:: Windows: list trusted root certificates that mention mitmproxy
certutil -store Root | findstr /i mitmproxy# Linux: look for the mitmproxy CA in the system certificates
grep -ril "mitmproxy" /usr/local/share/ca-certificates/ 2>/dev/null- Alerts in the browserA certificate error on a site you know is a warning, not an annoyance to ignore.
- Mesh: to stop those who get in the way with ARP spoofing, checks on the local network are needed, as explained in the guide to sniffing . On untrusted networks use a VPN .
Frequently Asked Questions about mitmproxy #
Is Mitmproxy legal? The software is legal and is used by developers and pentesters. Using it to intercept other people's traffic without authorization is not.
Does Mitmproxy intercept HTTPS? Yes, but only if the client trusts its CA. Without the certificate installed, you only see TLS errors.
What's the difference between mitmproxy, mitmweb, and mitmdump? Same engine, different interface: terminal console, web interface, command-line only for automation.
Does Mitmproxy work on Windows?
Yes. On Windows you use mitmweb e mitmdump: the console mitmproxy is not supported.
Why isn't my Android app showing traffic? There are three common causes: the app is bypassing the Wi-Fi proxy (using WireGuard), it doesn't trust user CAs from Android 7 onwards (system CAs or debug builds), or it's using pinning.
Is Mitmproxy better than Burp Suite? It depends on the job. For scripting and mobile apps, Mitmproxy is more convenient; for scanning and manual web work, Burp is more comprehensive.
Conclusion #
Mitmproxy shows you the part that's usually hidden: what an app actually says to its server. Start with the regular proxy, learn about filters, then move on to WireGuard for Android and Python add-ons for automation. To continue on the web journey, learn how the requests you just intercepted work in the guide to HTTP port 80 and attacks like CSRF . The official mitmproxy proxy mode documentation is the go-to source for details on each mode.








