Install (pip):
pip install mitmproxy```
A handy guide to using mitmproxy for intercepting, inspecting, modifying, and replaying network traffic. Covers basic commands, filtering, scripting, and common tasks.
Install (pip):
|
Install (Brew):
|
Run mitmproxy (terminal UI):
|
Run mitmweb (web UI):
|
Run mitmdump (scripting/headless):
|
Specify port (default 8080):
|
Basic help:
|
Generate CA certs (~/.mitmproxy): |
Transparent proxy: |
SOCKS proxy:
|
Reverse proxy:
|
Upstream proxy:
|
Certificates: Install |
Troubleshooting: Check firewall rules, OS proxy settings. |
Log level:
|
No server certificate verification:
|
|
Show help / command palette. |
|
Navigate within views/lists. |
|
View selected flow details. |
|
Close current view, go back. |
|
Set/modify filter expression. |
|
Clear flows. |
|
Save flows to a file. |
|
Load flows from a file. |
|
Set options. |
|
Delete flow(s). |
|
Replay flow(s) on the client side. |
|
Replay flow(s) on the server side. |
|
Edit flow (request/response). |
|
Mark/unmark flow. |
|
Pause/resume interception. |
|
View event log. |
|
Interrupt flow before sending to server (break request). |
|
Interrupt flow before sending to client (break response). |
|
Listen on port PORT (default 8080). |
|
Set proxy mode (regular, transparent, socks5, reverse, upstream). |
|
Run a Python script. |
|
Read flows from a file. |
|
Write flows to a file. |
|
Listen on IP address. |
|
Disable server TLS certificate verification. |
|
Set an option, e.g., |
|
Ignore connections to hosts matching regex. |
|
Match flows whose URL matches regex. |
|
Match flows whose headers match regex. |
|
Match flows whose request or response body matches regex. |
|
Match flows with no response yet. |
|
Match flows with status code. |
|
Match flows by HTTP method (GET, POST, etc.). |
|
Match flows by content type regex. |
|
Match by type (html, css, script, image, etc.). |
|
Match flows by domain. |
|
Logical AND. |
|
Logical OR. |
|
Logical NOT. |
|
Grouping. |
|
Match by host (exact string match). |
|
Access flow object attributes using Python-like syntax. |
|
Numeric comparison. |
|
Match flows slower than 1 second. |
|
Custom filters provided by addons. |
|
Switch to the request view. |
|
Switch to the response view. |
|
Switch to the request headers view. |
|
Switch to the response headers view. |
|
Switch to the request body view. |
|
Switch to the response body view. |
|
Switch to the request body parsed as form data. |
|
Switch to the response body parsed as form data. |
|
Toggle body display mode (raw, pretty, hex, etc.). |
|
Search forward using regex. |
|
Search backward using regex. |
|
Find next match. |
|
Find previous match. |
|
Search within the current flow view. |
|
Execute search. |
|
Cancel search. |
Tip: Searches respect the current filter. |
Tip: Searches are case-sensitive by default. Use regex flags. |
Tip: Use specific views (req/resp body/headers) for targeted search. |
|
|
Edit request/response headers, body, URL etc. Live editing. |
|
Apply changes after editing a flow. |
|
Replace content in request body matching path regex.
|
|
Replace content in response body matching path regex.
|
|
Replace content in request headers. |
|
Replace content in response headers. |
|
Map requests matching URL regex to a different URL.
|
|
Map requests matching URL regex to a local file.
|
Breakpoints: Use |
|
Run a script:
|
Script lifecycle methods:
|
Accessing flow components: |
Request/Response objects attributes: |
Modifying flow: |
Logging from script: |
Script arguments:
|
Accessing context ( |
Example: Redirect all requests:
|
Modify Request Header:
|
Modify Response Header:
|
Modify Request Body (Text):
|
Modify Response Body (Text):
|
Inject Script:
|
Block URLs:
|
Delay Response:
|
Modify Status Code:
|
Log specific requests:
|
Handle large bodies: Use |
Redirect:
|
Fake Response:
|
Extract Data:
|
|
Addons are Python scripts that provide custom functionality. |
Run multiple addons:
|
Addons can be installed via pip ( |
Examples of built-in addons: |
Running built-in addons:
|
Custom addons should implement the lifecycle methods ( |
Accessing addon context: Addons are classes, the |
Explore the |
Writing your own: Start with a simple script, then structure it as a class if needed for state or options. |
How it works: mitmproxy acts as a Man-in-the-Middle. It generates certificates for the sites you visit, signed by its own CA certificate. |
Client requirement: The mitmproxy CA certificate must be trusted by the client device/browser. |
Install CA Cert: Visit |
Default cert location: |
|
Disables server certificate verification. Useful for testing self-signed certs or issues, but insecure. |
|
Use a specific server certificate for interception (e.g., for a specific domain). |
|
Don’t intercept SSL/TLS for hosts matching regex (useful for sensitive sites or sites with issues). |
|
Specify TLS versions to support (e.g., |
|
Specify accepted cipher suites (OpenSSL format). |
Troubleshooting SSL: Check if the CA cert is correctly installed and trusted. Check |
Tip: Browsers often have their own certificate stores. |
Common Issue: HSTS (HTTP Strict Transport Security) can cause browsers to reject invalid certificates even if the CA is trusted. Clearing browser cache might help. |
|
Replays a request as if it came from the original client. |
Select flow(s) in the UI and press |
Creates a new flow with the replayed request. |
Useful for testing how a server handles repeated requests or slightly modified requests. |
Doesn’t preserve original client connection state (cookies, sessions might be affected if not in headers/body). |
Modify before replay: Use |
mitmdump: Not directly supported, use scripting to create and send requests programmatically. |
Replayed flows are marked in the UI. |
Replays a response for an incoming request from the client. |
Select a flow (containing the desired response) in the UI and press |
The next matching incoming request from any client will receive this replayed response instead of going to the server. |
Useful for simulating server responses (errors, specific data, etc.) without the server being involved. |
The replay happens based on matching request URL, method, and potentially headers/body (configurable). |
Replayed responses are also marked in the UI. |
To configure matching: |
mitmdump: Use the
|
Response is replayed only once by default. Repeat |
Install CA Cert: Always install the CA cert on client devices for proper HTTPS inspection. |
Filtering is your friend: Use filters ( |
Save Sessions: Save important sessions ( |
Scripting for Automation: Use mitmdump and Python scripts for complex modifications, data extraction, and automated testing. |
Stream large bodies: Use |
Ignored Hosts: Use |
Breakpoints: Use |
Explore Options: Type |
Performance: Large numbers of flows can impact performance. Clear flows regularly ( |