2016-07-08 01:37:33 +00:00
|
|
|
import mitmproxy
|
2011-08-04 22:47:43 +00:00
|
|
|
"""
|
2011-08-05 02:03:10 +00:00
|
|
|
This is a script stub, with definitions for all events.
|
2011-08-04 22:47:43 +00:00
|
|
|
"""
|
2015-05-30 00:03:28 +00:00
|
|
|
|
|
|
|
|
2016-07-15 01:22:20 +00:00
|
|
|
def start():
|
|
|
|
"""
|
|
|
|
Called once on script startup before any other events
|
|
|
|
"""
|
|
|
|
mitmproxy.ctx.log("start")
|
|
|
|
|
|
|
|
|
2016-07-14 04:20:27 +00:00
|
|
|
def configure(options):
|
2011-08-04 22:47:43 +00:00
|
|
|
"""
|
2016-07-14 04:20:27 +00:00
|
|
|
Called once on script startup before any other events, and whenever options changes.
|
2011-08-04 22:47:43 +00:00
|
|
|
"""
|
2016-07-14 04:20:27 +00:00
|
|
|
mitmproxy.ctx.log("configure")
|
2011-08-04 22:47:43 +00:00
|
|
|
|
2015-05-30 00:03:28 +00:00
|
|
|
|
2016-07-08 01:37:33 +00:00
|
|
|
def clientconnect(root_layer):
|
2011-08-04 22:47:43 +00:00
|
|
|
"""
|
|
|
|
Called when a client initiates a connection to the proxy. Note that a
|
|
|
|
connection can correspond to multiple HTTP requests
|
|
|
|
"""
|
2016-07-09 02:57:57 +00:00
|
|
|
mitmproxy.ctx.log("clientconnect")
|
2011-08-04 22:47:43 +00:00
|
|
|
|
2015-05-30 00:03:28 +00:00
|
|
|
|
2016-07-08 01:37:33 +00:00
|
|
|
def request(flow):
|
2013-12-16 21:10:06 +00:00
|
|
|
"""
|
2015-09-03 22:46:42 +00:00
|
|
|
Called when a client request has been received.
|
2013-12-16 21:10:06 +00:00
|
|
|
"""
|
2016-07-09 02:57:57 +00:00
|
|
|
mitmproxy.ctx.log("request")
|
2013-12-16 21:10:06 +00:00
|
|
|
|
2015-05-30 00:03:28 +00:00
|
|
|
|
2016-07-08 01:37:33 +00:00
|
|
|
def serverconnect(server_conn):
|
2011-08-04 22:47:43 +00:00
|
|
|
"""
|
2015-09-03 22:46:42 +00:00
|
|
|
Called when the proxy initiates a connection to the target server. Note that a
|
|
|
|
connection can correspond to multiple HTTP requests
|
2011-08-04 22:47:43 +00:00
|
|
|
"""
|
2016-07-09 02:57:57 +00:00
|
|
|
mitmproxy.ctx.log("serverconnect")
|
2011-08-04 22:47:43 +00:00
|
|
|
|
2014-07-21 19:06:55 +00:00
|
|
|
|
2016-07-08 01:37:33 +00:00
|
|
|
def responseheaders(flow):
|
2014-07-21 19:06:55 +00:00
|
|
|
"""
|
|
|
|
Called when the response headers for a server response have been received,
|
|
|
|
but the response body has not been processed yet. Can be used to tell mitmproxy
|
|
|
|
to stream the response.
|
|
|
|
"""
|
2016-07-09 02:57:57 +00:00
|
|
|
mitmproxy.ctx.log("responseheaders")
|
2014-07-21 19:06:55 +00:00
|
|
|
|
2015-05-30 00:03:28 +00:00
|
|
|
|
2016-07-08 01:37:33 +00:00
|
|
|
def response(flow):
|
2011-08-04 22:47:43 +00:00
|
|
|
"""
|
|
|
|
Called when a server response has been received.
|
|
|
|
"""
|
2016-07-09 02:57:57 +00:00
|
|
|
mitmproxy.ctx.log("response")
|
2011-08-04 22:47:43 +00:00
|
|
|
|
2015-05-30 00:03:28 +00:00
|
|
|
|
2016-07-08 01:37:33 +00:00
|
|
|
def error(flow):
|
2011-08-04 22:47:43 +00:00
|
|
|
"""
|
|
|
|
Called when a flow error has occured, e.g. invalid server responses, or
|
|
|
|
interrupted connections. This is distinct from a valid server HTTP error
|
2012-12-09 21:57:11 +00:00
|
|
|
response, which is simply a response with an HTTP error code.
|
2011-08-04 22:47:43 +00:00
|
|
|
"""
|
2016-07-09 02:57:57 +00:00
|
|
|
mitmproxy.ctx.log("error")
|
2011-08-04 22:47:43 +00:00
|
|
|
|
2015-05-30 00:03:28 +00:00
|
|
|
|
2016-07-08 01:37:33 +00:00
|
|
|
def serverdisconnect(server_conn):
|
2015-08-31 15:05:52 +00:00
|
|
|
"""
|
|
|
|
Called when the proxy closes the connection to the target server.
|
|
|
|
"""
|
2016-07-09 02:57:57 +00:00
|
|
|
mitmproxy.ctx.log("serverdisconnect")
|
2015-08-31 15:05:52 +00:00
|
|
|
|
|
|
|
|
2016-07-08 01:37:33 +00:00
|
|
|
def clientdisconnect(root_layer):
|
2011-08-04 22:47:43 +00:00
|
|
|
"""
|
|
|
|
Called when a client disconnects from the proxy.
|
|
|
|
"""
|
2016-07-09 02:57:57 +00:00
|
|
|
mitmproxy.ctx.log("clientdisconnect")
|
2011-08-04 22:47:43 +00:00
|
|
|
|
2015-05-30 00:03:28 +00:00
|
|
|
|
2016-07-08 01:37:33 +00:00
|
|
|
def done():
|
2011-08-04 22:47:43 +00:00
|
|
|
"""
|
|
|
|
Called once on script shutdown, after any other events.
|
|
|
|
"""
|
2016-07-09 02:57:57 +00:00
|
|
|
mitmproxy.ctx.log("done")
|