logo
🛠️ 开发工具

Mitmproxy

Mitmproxy Cheat Sheet - 快速参考指南,收录常用语法、命令与实践。

📂 分类 · 开发工具🧭 Markdown 速查🏷️ 2 个标签
#proxy#debug
向下滚动查看内容
返回全部 Cheat Sheets

Getting Started

Usage
OptionExampleDescription
-pmitmproxy -p 8001Start proxy on port 8001
-mmitmproxy -p 8001 -m reverse:http://127.0.0.1:4000Reverse proxy on port 8001 to port 4000
-wmitmproxy -p 8001 -w traffic.mitmStream flows to file as they arrive
-rmitmproxy -r traffic.mitmRead flows from file
-Cmitmproxy -C traffic.mitmReplay client requests from a saved file
-Smitmproxy -S traffic.mitmReplay server responses from a saved file
-smitmproxy -s myScript.pyExecute a script
-hmitmproxy -hmitmproxy quick help
Movement
CODE
滚动查看更多
        k                 Ctrl b
        ▲                   ▲▲
        │                   ││
h ◀ ─── + ─── ▶ l           ││ page
        │                   ││
        ▼                   ▼▼
        j             Ctrl f / Space

--
h, j, k ,lLeft, Down, Up, Right
Ctrl bPage up
Space / Ctrl fPage down
g / GGo to beginning / end
ArrowsUp, Down, Left, Right

{.shortcuts}

Copy to Clipboard

Command Syntax:

CODE
滚动查看更多
:export.clip format flow

Example:

DescriptionCommand 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.

Save to File

Command Syntax:

CODE
滚动查看更多
:export.file format flow path

Example:

DescriptionCommand 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.

Common Keybindings
--
qBack / Exit
zClear flow list
:Command prompt
EView event log
OView options
rReplay this flow
TabNext
EnterSelect

{.shortcuts}

Global Keybindings
--
-Cycle to next layout
?View help
BStart an attached browser
CView commands
IToggle intercept
KView key bindings
PView flow details
QExit immediately
WStream to file
iSet intercept
Ctrl rightFocus next layout pane
Shift tabFocus next layout pane

{.shortcuts}

Flow (View)
--
AResume all intercepted flows
DDuplicate flow
FSet focus follow
LLoad flows from file
MToggle viewing marked flows
SStart server replay
UUn-set all marks
VRevert changes to this flow
XKill this flow
ZPurge all flows not showing
aResume this intercepted flow
bSave response body to file
dDelete flow from view
eExport this flow to file
fSet view filter
mToggle mark on this flow
nCreate a new flow
oSet flow list order
rReplay this flow
vReverse flow list order
wSave listed flows to file
<code>|</code>Run a script on this flow
Ctrl lSend cuts to clipboard

{.shortcuts}

Mitmproxy Filter

Filter
--
fSet view filter (on flow view page)

{.shortcuts}


The regex are Python-style, it can be specified as quoted strings

Operators

| - | - | | ------- | --------- | --- | | ! | unary not | | & | and | | | | or | | (...) | grouping |

Expressions
--
~aMatch asset in response: CSS, Javascript, Flash, images.
~b regexBody
~bq regexRequest body
~bs regexResponse body
~c intHTTP response code
~d regexDomain
~dst regexMatch destination address
~eMatch error
~h regexHeader
~hq regexRequest header
~hs regexResponse header
~httpMatch HTTP flows
~m regexMethod
~markedMatch marked flows
~qMatch request with no response
~sMatch response
~src regexMatch source address
~t regexContent-type header
~tcpMatch TCP flows
~tq regexRequest Content-Type header
~ts regexResponse Content-Type header
~u regexURL
~websocketMatch WebSocket flows (and HTTP-WebSocket handshake flows)
Flow selectors

Expressions

--
@all All flows
@focus The currently focused flow
@shown All flows currently shown
@hidden All flows currently hidden
@marked All marked flows
@unmarkedAll unmarked flows

mitmproxy has a set of convenient flow selectors that operate on the current view

Examples

URL containing "google.com"

CODE
滚动查看更多
google\.com

Requests whose body contains the string "test"

CODE
滚动查看更多
~q ~b test

Anything but requests with a text/html content type:

CODE
滚动查看更多
!(~q & ~t "text/html")

Replace entire GET string in a request (quotes required to make it work):

CODE
滚动查看更多
":~q ~m GET:.*:/replacement.html"

Mitmproxy Scripts

Custom response
PYTHON
滚动查看更多
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

Add header
PYTHON
滚动查看更多
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

Also see

相关 Cheat Sheets

1v1免费职业咨询
logo

Follow Us

linkedinfacebooktwitterinstagramweiboyoutubebilibilitiktokxigua

We Accept

/image/layout/pay-paypal.png/image/layout/pay-visa.png/image/layout/pay-master-card.png/image/layout/pay-airwallex.png/image/layout/pay-alipay.png

地址

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 5000

Disclaimer

footer-disclaimerfooter-disclaimer

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