2011-08-13 01:51:38 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""
|
|
|
|
This example shows how to build a proxy based on mitmproxy's Flow
|
|
|
|
primitives.
|
|
|
|
|
2014-09-05 13:16:20 +00:00
|
|
|
Heads Up: In the majority of cases, you want to use inline scripts.
|
|
|
|
|
2013-03-13 20:19:43 +00:00
|
|
|
Note that request and response messages are not automatically replied to,
|
|
|
|
so we need to implement handlers to do this.
|
2011-08-13 01:51:38 +00:00
|
|
|
"""
|
2016-09-01 00:11:00 +00:00
|
|
|
from mitmproxy import flow, controller, options
|
2016-02-16 19:49:10 +00:00
|
|
|
from mitmproxy.proxy import ProxyServer, ProxyConfig
|
2011-08-13 01:51:38 +00:00
|
|
|
|
2014-09-08 14:02:31 +00:00
|
|
|
|
2016-10-19 00:22:50 +00:00
|
|
|
class MyMaster(master.Master):
|
2011-08-13 01:51:38 +00:00
|
|
|
def run(self):
|
|
|
|
try:
|
2016-10-19 00:22:50 +00:00
|
|
|
master.Master.run(self)
|
2011-08-13 01:51:38 +00:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
self.shutdown()
|
|
|
|
|
2016-05-29 00:54:52 +00:00
|
|
|
@controller.handler
|
2016-05-29 08:51:30 +00:00
|
|
|
def request(self, f):
|
2016-09-01 00:11:00 +00:00
|
|
|
print("request", f)
|
2011-08-13 01:51:38 +00:00
|
|
|
|
2016-05-29 00:54:52 +00:00
|
|
|
@controller.handler
|
2016-05-29 08:51:30 +00:00
|
|
|
def response(self, f):
|
2016-09-01 00:11:00 +00:00
|
|
|
print("response", f)
|
2011-08-13 01:51:38 +00:00
|
|
|
|
2016-09-01 00:11:00 +00:00
|
|
|
@controller.handler
|
|
|
|
def error(self, f):
|
|
|
|
print("error", f)
|
|
|
|
|
|
|
|
@controller.handler
|
2016-09-01 00:32:09 +00:00
|
|
|
def log(self, l):
|
|
|
|
print("log", l.msg)
|
2011-08-13 01:51:38 +00:00
|
|
|
|
2016-09-01 00:11:00 +00:00
|
|
|
opts = options.Options(cadir="~/.mitmproxy/")
|
|
|
|
config = ProxyConfig(opts)
|
2011-08-13 01:51:38 +00:00
|
|
|
state = flow.State()
|
2014-09-08 21:34:43 +00:00
|
|
|
server = ProxyServer(config)
|
2016-09-01 00:11:00 +00:00
|
|
|
m = MyMaster(opts, server, state)
|
2011-08-13 01:51:38 +00:00
|
|
|
m.run()
|