Skip to content

Instantly share code, notes, and snippets.

@davehughes
Last active March 29, 2016 17:30
Show Gist options
  • Save davehughes/cf9bdbedd0bf8d48bd272473c9051616 to your computer and use it in GitHub Desktop.
Save davehughes/cf9bdbedd0bf8d48bd272473c9051616 to your computer and use it in GitHub Desktop.
mitmproxy scripting quickstart
'''
See http://docs.mitmproxy.org/en/stable/scripting/inlinescripts.html for
further documentation.
Sample workflow:
# In one shell:
> mitmdump --port 8888 -w mitm.out
# In another:
> curl -x http://localhost:8888 http://httpbin.org
> mitmdump -ns mitmstart.py -r mitm.out
This flow is pretty useless on its own, but is a good starting point for
exploring the lifecycle hooks that mitmproxy exposes. Drop a (i)pdb
breakpoint in the hook that your want to implement and look around!
'''
from __future__ import print_function
# Script lifecycle events
def start(context, argv):
print('Start hook')
def done(context):
print('Done hook')
# Connection events
def clientconnect(context, root_layer):
print('Client connect hook')
def clientdisconnect(context, root_layer):
print('Client disconnect hook')
def serverconnect(context, server_conn):
print('Server connect hook')
def serverdisconnect(context, server_conn):
print('Server disconnect hook')
# HTTP events
def request(context, flow):
print('HTTP request')
def responseheaders(context, flow):
print('HTTP response headers')
def response(context, flow):
print('HTTP response')
def error(context, flow):
print('HTTP error')
# TCP Events
def tcp_message(context, tcp_msg):
print('TCP message')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment