XSS 注入和 innerhtml

XSS injection and innerhtml

我正在尝试了解 XSS 漏洞,但在理解这个概念时遇到了一些问题。我有一个测试站点 http://mytestpage/index.html and am trying to launch an alert box via xss from a secondary page http://xsstest.html。我似乎无法让警报发生。我认为我的问题是我的 xsstest 页面中的代码没有注入我的 mytestpage/index.html 页面。我正在尝试使用 innerhtml,因为我阅读的帖子似乎在 XSS 测试中利用了它。我相当确定我没有正确使用 innerhtml 或者可能它不正确 "tool for the job" 而我 运行 走错了路。如有任何建议,我们将不胜感激。

我的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 为 #alertdiv,您将执行 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>

你不是在做XSS。您只是在提交表单时显示警报。这也有错误 document.getElementById() 需要一个 id 到 select 元素。

XSS 在您需要输入的地方完成。所以你不能在 XSStest 页面中执行 XSS,但你可以通过将其更改为

从测试主页代码中执行 XSS
<!DOCTYPE html> 
<html>
<head>
 <meta charset="UTF-8" />
 <title>My Test Home Page</title>
</head>

<body>

    <form method="post" action="some page url">
        <label>Enter Your Name:</label>
        <input type="text" name="myname">
        <button class="btn" type="submit" name="action" value="submit">Submit</button>
    </form> 

</body>

并且假设您在 action 属性中提供 url 的页面类似于

<!DOCTYPE html>
<HTML>
 <body>
  Name is: <%=request.getParameter("myname")%>
 </body> 
</HTML>  

我假设你在这里使用 jsp。

现在,当您在此页面的输入框中输入 XSS 有效载荷并提交时,您提供的 url 页面将打开并显示警报,因为您在第二次使用输入值之前未对输入值进行清理页。