我正在尝试了解XSS漏洞,并且在掌握该概念时遇到了一些问题。我有一个测试站点http://mytestpage/index.html,正在尝试从辅助页面http://xsstest.html通过xss启动警报框。我似乎无法得到警报的发生。我认为我的问题是我的xsstest页面中的代码没有注入到mytestpage / index.html页面中。我正在尝试使用innerhtml,因为我阅读的帖子似乎在XSS测试中利用了这一点。我可以肯定的是,我没有正确使用innerhtml,或者它可能不是正确的“工作工具”,而且我走错了路。任何建议,将不胜感激。
我的XSS测试代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>XSS TEST PAGE</title>
</head>
<body>
<body onload="document.forms[0].submit()">
<form method="POST" id="test" onsubmit="test()" action="http://mytestpage/index.html" >
</form>
</body>
<script>
function test(){
alert("Hiya buddy!");
}
document.getElementById().innerHTML = test();
</script>
</html>
测试主页代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>My Test Home Page</title>
</head>
<body>
<form method="post">
<label>Enter Your Name:</label>
<input type="text" name="myname">
<button class="btn" type="submit" name="action" value="submit">Submit</button>
</form>
</body>
</html>
这里没有布宜诺斯艾利斯:
<script>
function test( ){
alert("Hiya buddy!");
}
document.getElementById().innerHTML = test();
</script>
document.getElementById()
要求您向其传递元素的ID。因此,例如,如果页面上有一个ID为div
的#alert
,则您将执行document.getElementById('alert')
。
您也不能将函数分配给元素的内部HTML。您需要创建script
元素,然后将其附加到文档或其他元素。相反,请尝试:
<script>
let myTest = document.createElement('script')
myTest.text = `
function test() {
alert('Hiya buddy!')
};
test();
`
const body = document.querySelector('body')
body.appendChild(myTest)
</script>