Mitmproxy Cheat Sheet - 快速参考指南,收录常用语法、命令与实践。
| Option | Example | Description |
|---|---|---|
-p | mitmproxy -p 8001 | Start proxy on port 8001 |
-m | mitmproxy -p 8001 -m reverse:http://127.0.0.1:4000 | Reverse proxy on port 8001 to port 4000 |
-w | mitmproxy -p 8001 -w traffic.mitm | Stream flows to file as they arrive |
-r | mitmproxy -r traffic.mitm | Read flows from file |
-C | mitmproxy -C traffic.mitm | Replay client requests from a saved file |
-S | mitmproxy -S traffic.mitm | Replay server responses from a saved file |
-s | mitmproxy -s myScript.py | Execute a script |
-h | mitmproxy -h | mitmproxy quick help |
k Ctrl b
▲ ▲▲
│ ││
h ◀ ─── + ─── ▶ l ││ page
│ ││
▼ ▼▼
j Ctrl f / Space
| - | - |
|---|---|
h, j, k ,l | Left, Down, Up, Right |
Ctrl b | Page up |
Space / Ctrl f | Page down |
g / G | Go to beginning / end |
Arrows | Up, Down, Left, Right |
{.shortcuts}
Command Syntax:
:export.clip format flow
Example:
| Description | Command Example |
|---|---|
| 1. Copy as a curl command | :export.clip curl @focus |
| 2. Copy as a httpie | :export.clip httpie @focus |
| 2. Copy as a raw | :export.clip raw @focus |
| 2. Copy as a raw HTTP request | :export.clip raw_request @focus |
| 2. Copy as a raw HTTP response | :export.clip raw_response @focus |
{.style-list}
Export a flow to the system clipboard.
Command Syntax:
:export.file format flow path
Example:
| Description | Command Example |
|---|---|
| 1. Export to /tmp/a.curl | :export.file curl @focus /tmp/a.curl |
| 2. Export to /tmp/a.httpie | :export.file httpie @focus /tmp/a.httpie |
| 2. Export to /tmp/a.raw | :export.file raw @focus /tmp/a.raw |
| 2. Export to /tmp/a.request | :export.file raw_request @focus /tmp/a.request |
| 2. Export to /tmp/a.response | :export.file raw_response @focus /tmp/a.response |
{.style-list}
Export a flow to the system clipboard.
| - | - |
|---|---|
q | Back / Exit |
z | Clear flow list |
: | Command prompt |
E | View event log |
O | View options |
r | Replay this flow |
Tab | Next |
Enter | Select |
{.shortcuts}
| - | - |
|---|---|
- | Cycle to next layout |
? | View help |
B | Start an attached browser |
C | View commands |
I | Toggle intercept |
K | View key bindings |
P | View flow details |
Q | Exit immediately |
W | Stream to file |
i | Set intercept |
Ctrl right | Focus next layout pane |
Shift tab | Focus next layout pane |
{.shortcuts}
| - | - |
|---|---|
A | Resume all intercepted flows |
D | Duplicate flow |
F | Set focus follow |
L | Load flows from file |
M | Toggle viewing marked flows |
S | Start server replay |
U | Un-set all marks |
V | Revert changes to this flow |
X | Kill this flow |
Z | Purge all flows not showing |
a | Resume this intercepted flow |
b | Save response body to file |
d | Delete flow from view |
e | Export this flow to file |
f | Set view filter |
m | Toggle mark on this flow |
n | Create a new flow |
o | Set flow list order |
r | Replay this flow |
v | Reverse flow list order |
w | Save listed flows to file |
| <code>|</code> | Run a script on this flow |
Ctrl l | Send cuts to clipboard |
{.shortcuts}
| - | - |
|---|---|
f | Set view filter (on flow view page) |
{.shortcuts}
The regex are Python-style, it can be specified as quoted strings
| - | - |
| ------- | --------- | --- |
| ! | unary not |
| & | and |
| | | or |
| (...) | grouping |
| - | - |
|---|---|
~a | Match asset in response: CSS, Javascript, Flash, images. |
~b regex | Body |
~bq regex | Request body |
~bs regex | Response body |
~c int | HTTP response code |
~d regex | Domain |
~dst regex | Match destination address |
~e | Match error |
~h regex | Header |
~hq regex | Request header |
~hs regex | Response header |
~http | Match HTTP flows |
~m regex | Method |
~marked | Match marked flows |
~q | Match request with no response |
~s | Match response |
~src regex | Match source address |
~t regex | Content-type header |
~tcp | Match TCP flows |
~tq regex | Request Content-Type header |
~ts regex | Response Content-Type header |
~u regex | URL |
~websocket | Match WebSocket flows (and HTTP-WebSocket handshake flows) |
Expressions
| - | - |
|---|---|
@all | All flows |
@focus | The currently focused flow |
@shown | All flows currently shown |
@hidden | All flows currently hidden |
@marked | All marked flows |
@unmarked | All unmarked flows |
mitmproxy has a set of convenient flow selectors that operate on the current view
URL containing "google.com"
google\.com
Requests whose body contains the string "test"
~q ~b test
Anything but requests with a text/html content type:
!(~q & ~t "text/html")
Replace entire GET string in a request (quotes required to make it work):
":~q ~m GET:.*:/replacement.html"
from mitmproxy import http
def request(flow: http.HTTPFlow) -> None:
if flow.request.pretty_url == "http://example.com/path":
flow.response = http.HTTPResponse.make(
200, # (optional) status code
b"Hello World", # (optional) content
{"Content-Type": "text/html"} # (optional) headers
)
Send a reply from the proxy without sending any data to the remote server
class AddHeader:
def __init__(self):
self.num = 0
def response(self, flow):
self.num = self.num + 1
flow.response.headers["count"] = str(self.num)
addons = [
AddHeader()
]
Add an HTTP header to each response
地址
Level 10b, 144 Edward Street, Brisbane CBD(Headquarter)Level 2, 171 La Trobe St, Melbourne VIC 3000四川省成都市武侯区桂溪街道天府大道中段500号D5东方希望天祥广场B座45A13号Business Hub, 155 Waymouth St, Adelaide SA 5000Disclaimer
JR Academy acknowledges Traditional Owners of Country throughout Australia and recognises the continuing connection to lands, waters and communities. We pay our respect to Aboriginal and Torres Strait Islander cultures; and to Elders past and present. Aboriginal and Torres Strait Islander peoples should be aware that this website may contain images or names of people who have since passed away.
匠人学院网站上的所有内容,包括课程材料、徽标和匠人学院网站上提供的信息,均受澳大利亚政府知识产权法的保护。严禁未经授权使用、销售、分发、复制或修改。违规行为可能会导致法律诉讼。通过访问我们的网站,您同意尊重我们的知识产权。 JR Academy Pty Ltd 保留所有权利,包括专利、商标和版权。任何侵权行为都将受到法律追究。查看用户协议
© 2017-2025 JR Academy Pty Ltd. All rights reserved.
ABN 26621887572