Skip to content

Instantly share code, notes, and snippets.

@linktohack
Last active March 3, 2016 11:40
Show Gist options
  • Save linktohack/077b08468f99a6bb1a3a to your computer and use it in GitHub Desktop.
Save linktohack/077b08468f99a6bb1a3a to your computer and use it in GitHub Desktop.
MITM rule for bigger screen
# Usage: mitmdump -s "modify_response_body.py mitmproxy bananas"
# (this script works best with --anticache)
from libmproxy.models import decoded
script = '''
<script type="text/javascript">
(function() {
var width = 400;
big();
function big() {
width += 40;
var view = document.querySelector("meta[name=viewport]") || document.createElement('meta');
view.setAttribute("name", "viewport");
view.setAttribute("content", "width=" + width);
document.head.appendChild(view);
}
function small() {
width -= 40;
var view = document.querySelector("meta[name=viewport]") || document.createElement('meta');
view.setAttribute("name", "viewport");
view.setAttribute("content", "width=" + width);
document.head.appendChild(view);
}
document.addEventListener('DOMContentLoaded', function() {
var div = document.createElement('div')
var plus = document.createElement('span');
var minus = document.createElement('span');
plus.innerText = "+";
plus.style.cssText = ["",
"color: white",
"background-color: rgba(0, 0, 255, 0.5)",
"position: fixed",
"bottom: 70px",
"right: 20px",
"font-family: monospace",
"font-size: 28px",
"line-height: 40px",
"width: 40px",
"text-align: center",
""].join(";");
plus.addEventListener("click", small);
minus.innerText = "-";
minus.style.cssText = ["",
"color: white",
"background-color: rgba(0, 0, 255, 0.5)",
"position: fixed",
"bottom: 20px",
"right: 20px",
"font-family: monospace",
"font-size: 28px",
"line-height: 40px",
"width: 40px",
"text-align: center",
""].join(";")
minus.addEventListener("click", big);
div.appendChild(minus);
div.appendChild(plus);
document.body.appendChild(div);
});
})();
</script>
'''
def response(context, flow):
with decoded(flow.response): # automatically decode gzipped responses.
flow.response.content = flow.response.content.replace(
'</head>',
script + '</head>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment