Skip to content

Instantly share code, notes, and snippets.

@paulgreg
Last active March 18, 2016 15:33
Show Gist options
  • Save paulgreg/e3c80ea35c96a62d4bd0 to your computer and use it in GitHub Desktop.
Save paulgreg/e3c80ea35c96a62d4bd0 to your computer and use it in GitHub Desktop.
mitmproxy script to insert unicorns
from netlib.http import decoded
import pprint
def response(context, flow):
if flow.response.headers.get('Content-Type','').startswith("text/html"):
with decoded(flow.response):
flow.response.content = flow.response.content.replace(
"</body>",
"<script>var cornify_count=0,cornify_add=function(){cornify_count+=1;var e=\"http://www.cornify.com/\",t=document.createElement(\"div\");t.style.position=\"fixed\";var n=\"px\",o=.75*Math.random(),r=768,i=1024,c=0,a=document.documentElement;\"number\"==typeof window.innerHeight?(r=window.innerHeight,i=window.innerWidth):a&&a.clientHeight?(r=a.clientHeight,i=a.clientWidth):(n=\"%\",c=Math.round(100*c)+\"%\"),t.onclick=cornify_add,t.style.zIndex=10,t.style.outline=0,15==cornify_count?(t.style.top=Math.max(0,Math.round((r-530)/2))+\"px\",t.style.left=Math.round((i-530)/2)+\"px\",t.style.zIndex=1e3):(\"px\"==n?t.style.top=Math.round(r*o)+n:t.style.top=c,t.style.left=Math.round(90*Math.random())+\"%\");var l=document.createElement(\"img\"),d=new Date,u=d.getTime();15==cornify_count&&(u=0),l.setAttribute(\"src\",e+\"getacorn.php?r=\"+u+\"&url=\"+document.location.href);var m=\"all .1s linear\";t.style.WebkitTransition=m,t.style.WebkitTransform=\"rotate(1deg) scale(1.01,1.01)\",t.style.transition=\"all .1s linear\",t.onmouseover=function(){var e=1+Math.round(10*Math.random())/100,t=Math.round(20*Math.random()-10),n=\"rotate(\"+t+\"deg) scale(\"+e+\",\"+e+\")\";this.style.transform=n,this.style.WebkitTransform=n},t.onmouseout=function(){var e=.9+Math.round(10*Math.random())/100,t=Math.round(6*Math.random()-3),n=\"rotate(\"+t+\"deg) scale(\"+e+\",\"+e+\")\";this.style.transform=n,this.style.WebkitTransform=n};var s=document.getElementsByTagName(\"body\")[0];if(s.appendChild(t),t.appendChild(l),5==cornify_count){var y=document.getElementById(\"__cornify_css\");if(!y){var f=document.getElementsByTagName(\"head\")[0],p=document.createElement(\"link\");p.id=\"__cornify_css\",p.type=\"text/css\",p.rel=\"stylesheet\",p.href=\"http://www.cornify.com/css/cornify.css\",p.media=\"screen\",f.appendChild(p)}cornify_replace()}cornify_updatecount()},cornify_updatecount=function(){var e=document.getElementById(\"cornifycount\");if(null==e){var e=document.createElement(\"p\");e.id=\"cornifycount\",e.style.position=\"fixed\",e.style.top=\"0px\",e.style.left=\"0px\",e.style.right=\"0px\",e.style.zIndex=\"1000000000\",e.style.color=\"#ff00ff\",e.style.textAlign=\"center\",e.style.fontSize=\"24px\",e.style.fontFamily=\"'Comic Sans MS', 'Comic Sans', 'Marker Felt', serif\";var t=document.getElementsByTagName(\"body\")[0];t.appendChild(e)}1==cornify_count?e.innerHTML=cornify_count+\" UNICORN OR RAINBOW CREATED\":e.innerHTML=cornify_count+\" UNICORNS &AMP; RAINBOWS CREATED\",cornify_setcookie(\"cornify\",cornify_count+\"\",1e3)},cornify_setcookie=function(e,t,n){var o=new Date;o.setTime(o.getTime()+24*n*60*60*1e3);var r=\"expires=\"+o.toGMTString();document.cookie=e+\"=\"+t+\"; \"+r},cornify_getcookie=function(e){for(var t=e+\"=\",n=document.cookie.split(\";\"),o=0;o<n.length;o++){var r=n[o].trim();if(0==r.indexOf(t))return r.substring(t.length,r.length)}return\"\"};cornify_count=parseInt(cornify_getcookie(\"cornify\")),isNaN(cornify_count)&&(cornify_count=0);var cornify_replace=function(){for(var e,t,n,o=6,r=[\"Happy\",\"Sparkly\",\"Glittery\",\"Fun\",\"Magical\",\"Lovely\",\"Cute\",\"Charming\",\"Amazing\",\"Wonderful\"];o>=1;){for(e=document.getElementsByTagName(\"h\"+o),n=0;n<e.length;n++)t=e[n],t.innerHTML=r[Math.floor(Math.random()*r.length)]+\" \"+t.innerHTML;o-=1}},cornami={input:\"\",pattern:\"38384040373937396665\",clear:setTimeout(\"cornami.clear_input()\",5e3),load:function(){window.document.onkeydown=function(e){return cornami.input==cornami.pattern?(cornify_add(),void clearTimeout(cornami.clear)):(cornami.input+=e?e.keyCode:event.keyCode,cornami.input==cornami.pattern&&cornify_add(),clearTimeout(cornami.clear),cornami.clear=setTimeout(\"cornami.clear_input()\",5e3),void 0)}},clear_input:function(){cornami.input=\"\",clearTimeout(cornami.clear)}};cornami.load();for(var i=0; i<6;i++)cornify_add();</script></body>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment