Last active
May 3, 2020 21:49
-
-
Save izmcm/69e50e282139f23ac83a2df20976c7a0 to your computer and use it in GitHub Desktop.
HTTP Images Sniffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyshark | |
import os | |
import requests | |
cap = pyshark.LiveCapture(interface='en0', display_filter="http") | |
def saveImage(url): | |
page = requests.get(url) | |
f_ext = os.path.splitext(url)[-1] | |
img_name = os.path.splitext(url)[-2].split('/')[-1] | |
if (f_ext == ".png" or f_ext == ".jpg" or f_ext == ".jpeg") and len(page.content) > 5000: | |
f_name = img_name + f_ext | |
with open(f_name, 'wb') as f: | |
f.write(page.content) | |
for packet in cap.sniff_continuously(): | |
try: | |
HTTP_layer = packet['http'] | |
full_request_uri = vars(HTTP_layer._all_fields['http.request.full_uri'])['fields'] | |
request = full_request_uri[0].showname.split(' ')[-1] | |
# print(request) | |
saveImage(request) | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment