mitmproxy Onboarding Guide: Research & Best Practices
This document serves as the primary onboarding guide for any developer joining the LLMitM v2 project. It provides a high-level map of the mitmproxy documentation, followed by a curated set of deep-dive research reports that are essential for understanding our architecture, design patterns, and implementation choices. Each report is summarized to explain its relevance and provide context for why it is required reading.
mitmproxy Documentation Map
This section provides a comprehensive, hierarchically structured map of the mitmproxy documentation, based on the cloned source files. It is designed to serve as a top-level exploration guide for understanding how mitmproxy powers LLMitM v2's traffic interception layer.
Concepts (Entry Point)
- Core Architecture
- How mitmproxy Works: MITM Mechanism
- Proxy Modes: Regular, Reverse, Transparent, WireGuard, Local
- Protocol Support: HTTP/1, HTTP/2, HTTP/3, WebSocket, TCP, UDP
- Certificates: CA Generation, Pinning, mTLS
- Configuration & Filtering
Addon Development (Entry Point)
- Building Addons
- Reference
Overview (Entry Point)
How-To Guides (Entry Point)
Tutorials (Entry Point)
API Reference (Entry Point)
- Core Traffic: mitmproxy.http (Headers, Request, Response, HTTPFlow), mitmproxy.flow (Flow base, serialization), mitmproxy.connection (Client, Server, TLS metadata)
- Data Structures: mitmproxy.coretypes.multidict (MultiDict used by headers, cookies, query, forms)
- TLS/Certs: mitmproxy.tls (ClientHello, TlsData), mitmproxy.certs (Cert parsing, CA generation)
- Protocols: dns, tcp, udp, websocket
- Proxy: mode_specs, context, server_hooks
- Addon System: addonmanager, contentviews
Curated Research Reports
1. Core Architecture
Core MITM mechanism: explicit HTTP/HTTPS proxying, transparent proxying, SNI handling, upstream certificate sniffing. Foundational for troubleshooting fingerprinting and traffic capture phases.
All proxy modes: regular, transparent, reverse, WireGuard, local capture. LLMitM v2 uses regular proxy (explicit) and reverse proxy (in front of target). See API Research — Proxy Modes for the full mode reference table.
HTTP/1, HTTP/2, HTTP/3, WebSocket, DNS, TCP/TLS, UDP/DTLS. LLMitM v2 focuses on HTTP/HTTPS. WebSocket hooks exist for future extensions.
CA certificate system for HTTPS interception. Certificate pinning bypass via ignore_hosts or Android unpinning tools.
2. Python API (Critical for LLMitM v2)
Full API reference: api/_index.md — clean markdown docs for all 16 modules
Architecture insights: api_research.md — FlowReader patterns, bounded tool design, codebase integration notes
FlowReader — The Key Insight
The .mitm file IS the structured format. FlowReader (mitmproxy.io) is a deserializer that yields fully hydrated Python objects — no subprocess, no text parsing, no truncation:
from mitmproxy.io import FlowReader
with open("capture.mitm", "rb") as f:
for flow in FlowReader(f).stream():
flow.request.method # "POST"
flow.request.pretty_url # "http://localhost:3000/rest/user/login"
flow.request.json() # {"email": "admin@juice-sh.op", "password": "admin123"}
flow.request.cookies # MultiDict of cookies
flow.response.status_code # 200
flow.response.json() # {"authentication": {"token": "eyJ..."}}
flow.response.cookies # Set-Cookie values parsed
flow.response.headers # case-insensitive multidict
The CLI command mitmdump -nr capture.mitm --flow-detail 3 is literally FlowReader -> format as text -> print to stdout. Shelling out to mitmdump gives a lossy text representation of data that's already structured.
HTTPFlow Object — What's Available
Every flow captured by mitmproxy gives you (full signatures in mitmproxy.http):
| Category |
Attributes |
| Request basics |
method, url, pretty_url, scheme, host, port, path, http_version |
| Request data |
headers (Headers — case-insensitive MultiDict), content (decompressed bytes), text, json(), cookies, query, urlencoded_form, multipart_form |
| Response basics |
status_code, reason, http_version |
| Response data |
headers, content, text, json(), cookies |
| Connection/TLS |
Client/Server: sni, tls_version, alpn, cipher, certificate_list (Cert objects with subject, issuer, SANs) |
| Flow lifecycle |
Flow base: id (UUID), timestamp_created, is_replay, error, metadata (arbitrary dict), get_state()/set_state(), copy(), kill() |
Programmatic Flow Filtering
from mitmproxy import flowfilter
flt = flowfilter.parse("~d example.com & ~m POST")
if flowfilter.match(flt, flow):
# Flow matches
Same filter syntax as CLI (~u, ~m, ~c, ~h, ~b, ~t, ~d, &, |, !) but compiled and evaluated in Python. See api_research.md §7 for the full filter table.
Useful Utilities
| Utility |
What It Does |
flow.response.refresh() |
Update date/expires/cookie timestamps for replay freshness |
Response.make(status_code, content, headers) |
Factory for mock responses (mitmproxy.http) |
flow.get_state() / set_state() |
Serialize flow to/from dict (mitmproxy.flow) |
flow.copy() |
Deep copy with live=False |
FlowWriter(fo).add(flow) |
Write flows to .mitm binary format |
FilteredFlowWriter(fo, flt) |
Write only matching flows |
read_flows_from_paths(paths) |
Bulk read from multiple files |
3. Addon Development
Class-based addons respond to event hooks, define options, expose commands. For LLMitM v2, addons are the natural way to implement live traffic capture and real-time fingerprinting without subprocess-based mitmdump invocations.
Event Hooks — What Fires When
| Hook |
When |
Use Case |
request(flow) |
Full request received |
Capture for fingerprinting |
response(flow) |
Full response received |
Tech stack detection, token extraction |
requestheaders(flow) |
Headers only, before body |
Set flow.request.stream = True for large files |
responseheaders(flow) |
Headers only, before body |
Streaming decisions |
tls_clienthello(data) |
TLS ClientHello |
SNI, cipher suite analysis |
websocket_message(flow) |
WebSocket message |
Future: non-HTTP protocol testing |
See API Research — Event Hooks for the complete hook list.
Addons can define typed options (str, int, bool, sequences) and expose commands that accept flows, paths, and other typed arguments. Relevant for future: "compile ActionGraph from current flows" or "execute stored graph for domain X".
4. Configuration & Filtering
Global options via ~/.mitmproxy/config.yaml and --set. Key options: ignore_hosts, tcp_hosts, mode, anticache, stickycookie, stickyauth.
Flow matching language: ~u /api & ~m POST & ~c 200. Works both in CLI and programmatically via flowfilter.parse().
Built-in Features Worth Knowing
| Feature |
Flag |
Why It Matters |
| Anticache |
--anticache |
Forces full responses during fingerprinting |
| Sticky cookies |
--stickycookie "~d target" |
Auto-replay session cookies (our ExecutionContext.cookies does this manually) |
| Sticky auth |
--stickyauth "~d target" |
Auto-replay auth headers |
| Client replay |
-C replay.mitm |
Replay captured requests against live server |
| Streaming |
--stream_large_bodies=10m |
Forward large bodies without buffering |
5. Operations & Deployment
Network-layer setup via iptables (Linux), pf (macOS). Captures traffic from proxy-oblivious applications.
ignore_hosts option exempts traffic from interception. Filter out CDNs, analytics, etc.
6. API Compatibility
Key breaking changes: mitmproxy 9+ uses Python logging (not custom); mitmproxy 7+ revised connection events (.client_conn -> .peername).
7. Tutorials
Capture and replay HTTP login sequences: mitmdump -w (record) -> mitmdump -C (replay). Validates the core LLMitM v2 thesis: capture once, replay deterministically forever.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: mitmproxy-reference3description: mitmproxy and mitmdump documentation — proxy modes, addon development, event hooks, traffic capture, filtering, and replay. Use when working with HTTP interception, building capture addons, or debugging proxy behavior. Use when this capability is needed.4---56# mitmproxy Onboarding Guide: Research & Best Practices78This document serves as the primary onboarding guide for any developer joining the LLMitM v2 project. It provides a high-level map of the mitmproxy documentation, followed by a curated set of deep-dive research reports that are essential for understanding our architecture, design patterns, and implementation choices. Each report is summarized to explain its relevance and provide context for why it is required reading.910---1112## mitmproxy Documentation Map1314This section provides a comprehensive, hierarchically structured map of the mitmproxy documentation, based on the cloned source files. It is designed to serve as a top-level exploration guide for understanding how mitmproxy powers LLMitM v2's traffic interception layer.1516- **[Concepts (Entry Point)](../../docs/mitmproxy/concepts/_index.md)**17 - **Core Architecture**18 - [How mitmproxy Works: MITM Mechanism](../../docs/mitmproxy/concepts/how-mitmproxy-works.md)19 - [Proxy Modes: Regular, Reverse, Transparent, WireGuard, Local](../../docs/mitmproxy/concepts/modes.md)20 - [Protocol Support: HTTP/1, HTTP/2, HTTP/3, WebSocket, TCP, UDP](../../docs/mitmproxy/concepts/protocols.md)21 - [Certificates: CA Generation, Pinning, mTLS](../../docs/mitmproxy/concepts/certificates.md)22 - **Configuration & Filtering**23 - [Options System: YAML Config, Runtime Control](../../docs/mitmproxy/concepts/options.md)24 - [Filter Expressions: URL, Header, Method, Status Code Matching](../../docs/mitmproxy/concepts/filters.md)25 - [Commands: Interactive Console, Key Bindings](../../docs/mitmproxy/concepts/commands.md)2627- **[Addon Development (Entry Point)](../../docs/mitmproxy/addons/_index.md)**28 - **Building Addons**29 - [Addon Architecture: Event Hooks, Options, Commands](../../docs/mitmproxy/addons/overview.md)30 - [Event Hooks: `request`, `response`, Connection Lifecycle](../../docs/mitmproxy/addons/event-hooks.md)31 - [Custom Options: Typed Config, Validation](../../docs/mitmproxy/addons/options.md)32 - [Custom Commands: `@command.command`, Flow Arguments](../../docs/mitmproxy/addons/commands.md)33 - **Reference**34 - [Content Views: Pretty-Printing, Syntax Highlighting](../../docs/mitmproxy/addons/contentviews.md)35 - [API Changelog: Breaking Changes Across Versions](../../docs/mitmproxy/addons/api-changelog.md)3637- **[Overview (Entry Point)](../../docs/mitmproxy/overview/_index.md)**38 - [Built-in Features: Replay, Anticache, Map Local/Remote, Streaming](../../docs/mitmproxy/overview/features.md)39 - [Installation: macOS, Linux, Windows, Docker, PyPI](../../docs/mitmproxy/overview/installation.md)40 - [Getting Started: First Launch, Browser Config](../../docs/mitmproxy/overview/getting-started.md)4142- **[How-To Guides (Entry Point)](../../docs/mitmproxy/howto/_index.md)**43 - [Transparent Proxying: iptables, pf, Network-Layer Setup](../../docs/mitmproxy/howto/transparent.md)44 - [Ignoring Domains: `ignore_hosts`, Certificate Pinning Workarounds](../../docs/mitmproxy/howto/ignore-domains.md)4546- **[Tutorials (Entry Point)](../../docs/mitmproxy/tutorials/_index.md)**47 - [Client Replay: Capture Once, Replay Forever](../../docs/mitmproxy/tutorials/client-replay.md)4849- **[API Reference (Entry Point)](../../docs/mitmproxy/api/_index.md)**50 - **Core Traffic**: [mitmproxy.http](../../docs/mitmproxy/api/mitmproxy.http.md) (Headers, Request, Response, HTTPFlow), [mitmproxy.flow](../../docs/mitmproxy/api/mitmproxy.flow.md) (Flow base, serialization), [mitmproxy.connection](../../docs/mitmproxy/api/mitmproxy.connection.md) (Client, Server, TLS metadata)51 - **Data Structures**: [mitmproxy.coretypes.multidict](../../docs/mitmproxy/api/mitmproxy.coretypes.multidict.md) (MultiDict used by headers, cookies, query, forms)52 - **TLS/Certs**: [mitmproxy.tls](../../docs/mitmproxy/api/mitmproxy.tls.md) (ClientHello, TlsData), [mitmproxy.certs](../../docs/mitmproxy/api/mitmproxy.certs.md) (Cert parsing, CA generation)53 - **Protocols**: [dns](../../docs/mitmproxy/api/mitmproxy.dns.md), [tcp](../../docs/mitmproxy/api/mitmproxy.tcp.md), [udp](../../docs/mitmproxy/api/mitmproxy.udp.md), [websocket](../../docs/mitmproxy/api/mitmproxy.websocket.md)54 - **Proxy**: [mode_specs](../../docs/mitmproxy/api/mitmproxy.proxy.mode_specs.md), [context](../../docs/mitmproxy/api/mitmproxy.proxy.context.md), [server_hooks](../../docs/mitmproxy/api/mitmproxy.proxy.server_hooks.md)55 - **Addon System**: [addonmanager](../../docs/mitmproxy/api/mitmproxy.addonmanager.md), [contentviews](../../docs/mitmproxy/api/mitmproxy.contentviews.md)5657---5859## Curated Research Reports6061### 1. Core Architecture6263#### [How mitmproxy Works](../../docs/mitmproxy/concepts/how-mitmproxy-works.md)64Core MITM mechanism: explicit HTTP/HTTPS proxying, transparent proxying, SNI handling, upstream certificate sniffing. Foundational for troubleshooting fingerprinting and traffic capture phases.6566#### [Proxy Modes](../../docs/mitmproxy/concepts/modes.md)67All proxy modes: regular, transparent, reverse, WireGuard, local capture. LLMitM v2 uses **regular proxy** (explicit) and **reverse proxy** (in front of target). See [API Research — Proxy Modes](../../docs/mitmproxy/api_research.md#12-proxy-modes-reference) for the full mode reference table.6869#### [Protocol Support](../../docs/mitmproxy/concepts/protocols.md)70HTTP/1, HTTP/2, HTTP/3, WebSocket, DNS, TCP/TLS, UDP/DTLS. LLMitM v2 focuses on HTTP/HTTPS. WebSocket hooks exist for future extensions.7172#### [Certificates](../../docs/mitmproxy/concepts/certificates.md)73CA certificate system for HTTPS interception. Certificate pinning bypass via `ignore_hosts` or Android unpinning tools.7475### 2. Python API (Critical for LLMitM v2)7677> **Full API reference**: [api/_index.md](../../docs/mitmproxy/api/_index.md) — clean markdown docs for all 16 modules78> **Architecture insights**: [api_research.md](../../docs/mitmproxy/api_research.md) — FlowReader patterns, bounded tool design, codebase integration notes7980#### FlowReader — The Key Insight8182**The `.mitm` file IS the structured format.** `FlowReader` (`mitmproxy.io`) is a deserializer that yields fully hydrated Python objects — no subprocess, no text parsing, no truncation:8384```python85from mitmproxy.io import FlowReader86with open("capture.mitm", "rb") as f:87 for flow in FlowReader(f).stream():88 flow.request.method # "POST"89 flow.request.pretty_url # "http://localhost:3000/rest/user/login"90 flow.request.json() # {"email": "admin@juice-sh.op", "password": "admin123"}91 flow.request.cookies # MultiDict of cookies92 flow.response.status_code # 20093 flow.response.json() # {"authentication": {"token": "eyJ..."}}94 flow.response.cookies # Set-Cookie values parsed95 flow.response.headers # case-insensitive multidict96```9798The CLI command `mitmdump -nr capture.mitm --flow-detail 3` is literally `FlowReader` -> format as text -> print to stdout. Shelling out to mitmdump gives a **lossy text representation** of data that's already structured.99100#### HTTPFlow Object — What's Available101102Every flow captured by mitmproxy gives you (full signatures in [mitmproxy.http](../../docs/mitmproxy/api/mitmproxy.http.md)):103104| Category | Attributes |105|----------|-----------|106| **Request basics** | `method`, `url`, `pretty_url`, `scheme`, `host`, `port`, `path`, `http_version` |107| **Request data** | `headers` ([Headers](../../docs/mitmproxy/api/mitmproxy.http.md#headers) — case-insensitive [MultiDict](../../docs/mitmproxy/api/mitmproxy.coretypes.multidict.md)), `content` (decompressed bytes), `text`, `json()`, `cookies`, `query`, `urlencoded_form`, `multipart_form` |108| **Response basics** | `status_code`, `reason`, `http_version` |109| **Response data** | `headers`, `content`, `text`, `json()`, `cookies` |110| **Connection/TLS** | [Client](../../docs/mitmproxy/api/mitmproxy.connection.md#client)/[Server](../../docs/mitmproxy/api/mitmproxy.connection.md#server): `sni`, `tls_version`, `alpn`, `cipher`, `certificate_list` ([Cert](../../docs/mitmproxy/api/mitmproxy.certs.md) objects with subject, issuer, SANs) |111| **Flow lifecycle** | [Flow](../../docs/mitmproxy/api/mitmproxy.flow.md) base: `id` (UUID), `timestamp_created`, `is_replay`, `error`, `metadata` (arbitrary dict), `get_state()`/`set_state()`, `copy()`, `kill()` |112113#### Programmatic Flow Filtering114115```python116from mitmproxy import flowfilter117flt = flowfilter.parse("~d example.com & ~m POST")118if flowfilter.match(flt, flow):119 # Flow matches120```121122Same filter syntax as CLI (`~u`, `~m`, `~c`, `~h`, `~b`, `~t`, `~d`, `&`, `|`, `!`) but compiled and evaluated in Python. See [api_research.md §7](../../docs/mitmproxy/api_research.md#7-flow-filtering-mitmproxyflowfilter) for the full filter table.123124#### Useful Utilities125126| Utility | What It Does |127|---------|-------------|128| `flow.response.refresh()` | Update date/expires/cookie timestamps for replay freshness |129| `Response.make(status_code, content, headers)` | Factory for mock responses ([mitmproxy.http](../../docs/mitmproxy/api/mitmproxy.http.md#response)) |130| `flow.get_state()` / `set_state()` | Serialize flow to/from dict ([mitmproxy.flow](../../docs/mitmproxy/api/mitmproxy.flow.md)) |131| `flow.copy()` | Deep copy with `live=False` |132| `FlowWriter(fo).add(flow)` | Write flows to `.mitm` binary format |133| `FilteredFlowWriter(fo, flt)` | Write only matching flows |134| `read_flows_from_paths(paths)` | Bulk read from multiple files |135136### 3. Addon Development137138#### [Addon Architecture Overview](../../docs/mitmproxy/addons/overview.md)139Class-based addons respond to event hooks, define options, expose commands. For LLMitM v2, addons are the natural way to implement live traffic capture and real-time fingerprinting without subprocess-based mitmdump invocations.140141#### Event Hooks — What Fires When142| Hook | When | Use Case |143|------|------|----------|144| `request(flow)` | Full request received | Capture for fingerprinting |145| `response(flow)` | Full response received | Tech stack detection, token extraction |146| `requestheaders(flow)` | Headers only, before body | Set `flow.request.stream = True` for large files |147| `responseheaders(flow)` | Headers only, before body | Streaming decisions |148| `tls_clienthello(data)` | TLS ClientHello | SNI, cipher suite analysis |149| `websocket_message(flow)` | WebSocket message | Future: non-HTTP protocol testing |150151See [API Research — Event Hooks](../../docs/mitmproxy/api_research.md#8-addon-event-hooks) for the complete hook list.152153#### [Custom Options](../../docs/mitmproxy/addons/options.md) & [Custom Commands](../../docs/mitmproxy/addons/commands.md)154Addons can define typed options (str, int, bool, sequences) and expose commands that accept flows, paths, and other typed arguments. Relevant for future: `"compile ActionGraph from current flows"` or `"execute stored graph for domain X"`.155156### 4. Configuration & Filtering157158#### [Options System](../../docs/mitmproxy/concepts/options.md)159Global options via `~/.mitmproxy/config.yaml` and `--set`. Key options: `ignore_hosts`, `tcp_hosts`, `mode`, `anticache`, `stickycookie`, `stickyauth`.160161#### [Filter Expressions](../../docs/mitmproxy/concepts/filters.md)162Flow matching language: `~u /api & ~m POST & ~c 200`. Works both in CLI and programmatically via `flowfilter.parse()`.163164#### Built-in Features Worth Knowing165| Feature | Flag | Why It Matters |166|---------|------|----------------|167| **Anticache** | `--anticache` | Forces full responses during fingerprinting |168| **Sticky cookies** | `--stickycookie "~d target"` | Auto-replay session cookies (our `ExecutionContext.cookies` does this manually) |169| **Sticky auth** | `--stickyauth "~d target"` | Auto-replay auth headers |170| **Client replay** | `-C replay.mitm` | Replay captured requests against live server |171| **Streaming** | `--stream_large_bodies=10m` | Forward large bodies without buffering |172173### 5. Operations & Deployment174175#### [Transparent Proxying](../../docs/mitmproxy/howto/transparent.md)176Network-layer setup via iptables (Linux), pf (macOS). Captures traffic from proxy-oblivious applications.177178#### [Ignoring Domains](../../docs/mitmproxy/howto/ignore-domains.md)179`ignore_hosts` option exempts traffic from interception. Filter out CDNs, analytics, etc.180181### 6. API Compatibility182183#### [API Changelog](../../docs/mitmproxy/addons/api-changelog.md)184Key breaking changes: mitmproxy 9+ uses Python `logging` (not custom); mitmproxy 7+ revised connection events (`.client_conn` -> `.peername`).185186### 7. Tutorials187188#### [Client Replay Tutorial](../../docs/mitmproxy/tutorials/client-replay.md)189Capture and replay HTTP login sequences: `mitmdump -w` (record) -> `mitmdump -C` (replay). Validates the core LLMitM v2 thesis: capture once, replay deterministically forever.190191---192> Converted and distributed by [TomeVault](https://tomevault.io/claim/cybersharkvin) — claim your Tome and manage your conversions.193<!-- tomevault:4.0:skill_md:2026-04-11 -->