Skip to content

Instantly share code, notes, and snippets.

@lukepearson
Created April 10, 2024 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukepearson/79e62c3635266612fd8644238b6f23b7 to your computer and use it in GitHub Desktop.
Save lukepearson/79e62c3635266612fd8644238b6f23b7 to your computer and use it in GitHub Desktop.
Mitmproxy image download script
from mitmproxy import http
import os
import hashlib
def response(flow: http.HTTPFlow) -> None:
save_dir = "downloaded_images"
os.makedirs(save_dir, exist_ok=True)
content_type = flow.response.headers.get("Content-Type", "")
if "image" in content_type:
url_hash = hashlib.sha256(flow.request.url.encode('utf-8')).hexdigest()
file_extension = content_type.split('/')[-1]
filename = f"{url_hash}.{file_extension}"
file_path = os.path.join(save_dir, filename)
with open(file_path, "wb") as f:
f.write(flow.response.content)
print(f"Image saved: {file_path}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment