I'm trying to implement a simple XSS attack for a (non-malicious) proof of concept and am having some issues. The goal is to populate a form and submit it within an iframe.
function grab() {
alert('yess');
};
function makeLink() {
return "http://mysite.com/?" + encodeURIComponent("<script" + ">" + grab.toString() +
";grab();</script" + ">");
// returns "http://mysite.com/?%3Cscript%3Efunction%20grab()%20%7B%0A%20%20%20%20alert('yess')%3B%0A%7D%3Bgrab()%3B%3C%2Fscript%3E"
}
var iframe = document.createElement('iframe');
iframe.src = makeLink(xssdefense, target, attacker);
iframe.height = 600;
iframe.width = 800;
// not sure if I need this line, but un-commenting doesn't seem to change anything.
// iframe.sandbox = "allow-scripts allow-same-origin allow-forms"
document.body.appendChild(iframe);
Ideally when this html file is opened, an iframe with the javascript injected will be sitting there. Upon console investigation, grab() is defined and callable in the main window, but not in the frame, which puzzles me.
Anyway, any help is appreciated. Thanks a bunch!