Skip to content

Instantly share code, notes, and snippets.

@bmannix
Last active March 23, 2016 04:36
Show Gist options
  • Save bmannix/f8c5dcddf19489c3f6c4 to your computer and use it in GitHub Desktop.
Save bmannix/f8c5dcddf19489c3f6c4 to your computer and use it in GitHub Desktop.
import json
from browsermobproxy import Server
import requests
from selenium import webdriver
bmp_path = "browsermob-proxy-2.1.0-beta-3/bin/browsermob-proxy"
sut = "http://the-internet.herokuapp.com/"
server = Server(bmp_path)
server.start()
proxy = server.create_proxy()
profile = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)
def inject():
"""
Injects javascript content passed in immediately after the <head>
"""
# The error seems to be caused by the charaters $'
script = """
contentType = response.headers().get("content-type");
if (contentType.indexOf("text/html") === 0) {{
og_contents = contents.getTextContents();
h4x0r3d = og_contents.replace("<head>", "<head><script>'^' + '$';#####################</script>");
contents.setTextContents(h4x0r3d);
}}
"""
headers = { 'Content-Type': 'text/plain' }
post_url = '{}/proxy/{}/filter/response'.format(proxy.host, proxy.port)
response = requests.post(post_url, script, headers=headers)
if response.status_code == 200:
print "200 OK"
else:
print "Error"
return response
inject()
driver.get(sut)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment