I’m posting this here primarily so that Future Quinn™ can reference it. Hopefully other folks will find it useful as well.
I’ve recently been playing around with mitmproxy, which is working out well for me. One feature I really like is the ability to programmatically extract information from traces created the
mitmproxy
tool. The workflow looks something like this:
Run
.mitmproxy
Use the
command to filter the flows it captures. For example,l
will only shows requests to~d example\.com
.example.com
Run my test.
Use the
command to save the flows to a file.w
Extract content from the file programmatically using the script facility built in to
. For example:mitmdump
$ mitmdump -r test1.flows -s filter.py -n -q … output from my filter …
The filters themselves are written in Python (yay Python!) and have deep access to the flows. For example:
from urlparse import urlparse
def response(context, flow):
u = urlparse(flow.request.url)
if u.hostname.endswith("example.com"):
cookie = flow.request.headers["Cookie"]
if cookie is None:
cookie = "-"
print "%d %s %s" % (
flow.response.status_code,
u.path,
cookie
)
will print a summary of the status, URL path and request cookies for all the requests to
example.com
.
The nice thing here is that you have access to the full power of Python, so you can write code to extract the data in the most useful way.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"