Mitmproxy is an interactive, SSL/TLS-capable intercepting proxy for HTTP/1, HTTP/2, and WebSockets. It allows developers and security researchers to inspect, modify, and replay network traffic. Currently at version 12.2.1, it receives frequent patch and minor updates, with major versions introducing significant breaking changes less often.
pip install mitmproxyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a basic mitmproxy addon that intercepts and modifies HTTP requests and responses. It adds custom headers for traffic to 'example.com'. To run, save this code as a `.py` file (e.g., `myaddon.py`) and execute `mitmproxy -s myaddon.py` in your terminal, then configure your client to use mitmproxy as a proxy.
Ensure your Python environment meets the minimum requirement for your mitmproxy version. Upgrade to Python 3.12 or higher for mitmproxy 12+.
Replace `flow.request.url` with `flow.request.pretty_url` (for a user-friendly string) or reconstruct from `flow.request.scheme`, `flow.request.host`, `flow.request.port`, and `flow.request.path`. Use `flow.request.pretty_host` for the host name.
Ensure you are working with `bytes` for `content`. If you need string representation, explicitly decode (e.g., `flow.response.content.decode('utf-8')`) and encode back before setting (e.g., `b'new content'`).Rewrite asynchronous logic to be called synchronously, typically by wrapping `await` calls with `asyncio.run()` or using `loop.run_until_complete()` within your synchronous addon method, or run `asyncio.run()` in the main thread outside the addon.
After starting mitmproxy, configure your client to proxy through it, then navigate to `http://mitm.it` through that client to download and install the CA certificate. Refer to the mitmproxy documentation for detailed installation instructions for your specific client/OS.
On Alpine Linux, ensure `libgcc` and `build-base` packages are installed via `apk add libgcc build-base` before attempting to install `mitmproxy`. Alternatively, consider using a less minimal base image (e.g., Debian or Ubuntu) which typically includes these dependencies by default or has easier setup for Rust compilation.
Install the mitmproxy CA certificate on the client device. This is typically done by configuring the client to use mitmproxy as a proxy, then navigating to `http://mitm.it` and following the installation instructions for your specific OS/device. Alternatively, manually import `~/.mitmproxy/mitmproxy-ca-cert.pem` (or `.p12` for Windows) into your system's trust store.
Ensure mitmproxy (e.g., `mitmproxy`, `mitmweb`, or `mitmdump`) is actively running and listening on the expected port (default 8080). Verify the client's proxy settings correctly point to mitmproxy's IP address and port. Check firewall rules on the mitmproxy host to allow incoming connections.
Update your mitmproxy installation to a recent version (if applicable) and modify your addon script to use the current import structure, typically `from mitmproxy import ...` instead of `from libmproxy import ...`. If the issue persists with other modules, ensure mitmproxy was installed via `pip` or `pipx` into your Python environment, and then `pip install` any additional required modules, as standalone binaries include their own Python environment.
Verify that your client's proxy settings are accurately configured to point to the IP address and port where mitmproxy is listening (e.g., `localhost:8080` for a local setup). Ensure there are no network connectivity issues or firewalls blocking communication between the client and mitmproxy. If using transparent mode, double-check your `iptables` or routing configurations.
No dependency data recorded yet.