Mitmproxy CHEAT SHEET

mitmproxy is a free and open source interactive HTTPS proxy. This is a quick reference cheat sheet to the mitmproxy.

capturetrafficnetworkutility
4
Sections
14
Cards

#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
        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:

: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:

: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
|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"

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"

#Mitmproxy Scripts

Custom response
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
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