Created
July 14, 2020 19:06
-
-
Save honoki/fd8c7fa29f5c5e2c5587786288784c9d to your computer and use it in GitHub Desktop.
mitmdump script to dump incoming HTTP requests to Slack
This file contains hidden or 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
#!/usr/bin/python3 | |
import requests | |
def is_blacklisted(domain): | |
blacklist = open("/path/to/blacklist.txt") | |
return domain in [w.strip() for w in blacklist.readlines()] | |
def request(flow): | |
req = flow.request.method + ' ' + flow.request.path + ' ' + flow.request.http_version + '\n' | |
for k, v in flow.request.headers.items(): | |
if k == 'X-MITMProxy-Real-IP': | |
fromip = v | |
continue | |
if k.lower() == 'host' and v == 'localhost': | |
continue | |
if k == 'X-MITMProxy-Host': | |
if is_blacklisted(v): | |
return | |
req = req + ("Host: %s" % v)+'\n' | |
continue | |
req = req + ("%s: %s" % (k, v))+'\n' | |
req = req + '\n'+flow.request.content.decode("utf-8") | |
print(req) | |
jload = {"text": "[http] request from "+fromip,"blocks":[{"type":"section","text":{"type":"mrkdwn","text":"[http] request from `"+fromip+"`"}},{"type":"section","text":{"type":"mrkdwn","text":"```"+req+"```"}}]} | |
requests.post('https://hooks.slack.com/services/.../.../...', json=jload) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has been integrated in https://github.com/honoki/wilson-cloud-respwnder