Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Brief mitmdump module for dumping content of responses to a file, and keeping track of what files are which URIs in a map JSON.
Mitmdump extension script that can be used to dump content to disk in a way that can be processed after the fact by arbitrary tools.
import time
import uuid
import json
import os.path
from mitmproxy import http
class ContentToFlatFile(object):
def __init__(self, data_dir="content"):
self.last_dump = 0
self.dump_interval = 10
self.request_mapping = dict()
self.data_dir = data_dir
if not os.path.exists(self.data_dir):
with open(os.path.join(self.data_dir, ".map.json"), "w") as fp:
if not os.path.isdir(self.data_dir):
raise Exception(
"Target output location exists, but is not a directory")
if os.path.exists(os.path.join(self.data_dir, ".map.json")):
with open(os.path.join(self.data_dir, ".map.json"), "r") as fp:
self.request_mapping = json.loads(
def response(self, flow: http.HTTPFlow) -> None:
uri ="utf-8")
sni_host = flow.client_conn.sni
content_bytes = flow.response.content
request_uuid = str(uuid.uuid4())
self.request_mapping[request_uuid] = {"sni_host": sni_host, "uri": uri}
with open(os.path.join(self.data_dir, request_uuid), "wb") as fp:
if time.time() - self.last_dump > self.dump_interval:
self.last_dump = time.time()
with open(os.path.join(self.data_dir, ".map.json"), "w") as fp:
def request(self, flow: http.HTTPFlow) -> None:
# request_content = flow.request.content
addons = [ContentToFlatFile()]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment