Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@honoki
Created July 14, 2020 19:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save honoki/fd8c7fa29f5c5e2c5587786288784c9d to your computer and use it in GitHub Desktop.
Save honoki/fd8c7fa29f5c5e2c5587786288784c9d to your computer and use it in GitHub Desktop.
mitmdump script to dump incoming HTTP requests to Slack
#!/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)
@honoki
Copy link
Author

honoki commented Jul 17, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment