Curso-lenguaje-python/python-ofensivo/15_hacking/05_images_sniffer.py

38 lines
704 B
Python
Raw Normal View History

2024-01-29 19:29:24 +01:00
#/usr/bin/env python3
"""
Images sniffer
"""
from mitmproxy import http
from mitmproxy import ctx
def response(flow):
"""
Sniff images
"""
content_type = flow.response.headers.get("Content-Type", "No Content-Type")
try:
if "image" in content_type:
url = flow.request.url
ext = content_type.split("/")[-1]
if ext == "jpeg":
ext = "jpg"
file_name = f"img/{url.replace('/', '_')}.{ext}"
image_data = flow.response.content
with open(file_name, "wb") as f:
f.write(image_data)
print(f"\n[+]Imagen guardada: {file_name}\n")
except:
pass