【问题标题】:Input form to demonstrate XSS输入表单来演示 XSS
【发布时间】:2016-09-13 11:13:53
【问题描述】:

我想使用输入表单在本地使用 HTML 和 JavaScript 演示 XSS。问题是通过 URL 传递参数并在 JavaScript 代码中获取参数后,它不会执行。我知道它不会执行,因为我没有重新加载 DOM。

我该怎么做?

目前我的代码如下所示:

<!DOCTYPE html>
<html>
<head>
    <title>XSS</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
    <form method="GET" action="test.html">
        <input type="text" name="search" id="search">
        <input type="submit" value="Senden">
    </form>
</body>
</html>

<!doctype html>
<html>
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
      <input type="text" name="search" id="search">
      <a href="start.html">Start</a>
</body>
<script>
    function getParameterByName(name) {
        name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
        var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
            results = regex.exec(location.search);
        return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
    }
    var x = getParameterByName('search');
    $('input[type="text"]').val(x);
</script>
</html>

提前致谢。

【问题讨论】:

  • 通过 URL 发送 dom 怎么不重新加载?

标签: javascript jquery html forms xss


【解决方案1】:

要演示 de XSS 漏洞,您需要评估来自 URL 的字符串,而不是将其设置为输入

尝试使用&lt;script&gt;alert('test')&lt;/script&gt;进行测试

<!doctype html>
<html>
<head>
    <script type="text/javascript" src="https://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
      <input type="text" name="search" id="search">
      <a href="start.html">Start</a>
      <script>
    function getParameterByName(name) {
        name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
        var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
            results = regex.exec(location.search);
        return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
    }
    $(function(){
    var x = getParameterByName('search');
    $('input[type="text"]').after(x);//or eval(x);
    });
</script>
</body>

</html>

【讨论】:

  • 非常感谢!我现在觉得很傻。我不知道为什么我没有尝试这个。祝你有美好的一天!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-14
相关资源
最近更新 更多