Created
August 12, 2019 09:05
-
-
Save zckevin/892d2e1f9f3adac54a1f37cc011cf363 to your computer and use it in GitHub Desktop.
Using mitmproxy to inject Javascript file.
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
# Mitmproxy: 4.0.4 | |
# Python: 3.6.5 | |
# OpenSSL: OpenSSL 1.1.0h-fips 27 Mar 2018 | |
# Platform: Linux-4.16.3-301.fc28.x86_64-x86_64-with-fedora-28-Twenty_Eight | |
# usage | |
# mitmdump -p $LISTEN_PORT -s ./mitm.py | |
import os | |
from bs4 import BeautifulSoup | |
from mitmproxy import http | |
class Injector: | |
def load(self, loader): | |
loader.add_option( | |
"script", str, "", "My Script Tag" | |
) | |
def response(self, flow: http.HTTPFlow) -> None: | |
if flow.response.headers.get("content-type").find("text/html") != -1: | |
html = BeautifulSoup(flow.response.content, "html.parser") | |
if html.head: | |
script = html.new_tag( | |
"script", id="mitmproxy", src="http://localhost:5000/apply-evasions.browser.js", type="application/javascript") | |
html.head.insert(0, script) | |
flow.response.content = str(html).encode("utf8") | |
addons = [Injector()] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment