【问题标题】:Create an simple XSS situation创建一个简单的 XSS 情况
【发布时间】:2022-11-10 18:00:51
【问题描述】:

我想创建一个简单的 XSS。下面是我的代码

<body> 
    <script>
        function update(){
            const message = document.getElementById("message").value;
            document.getElementById("show_message").innerHTML = message
        }
    </script>
    <h1 class="title">Cross-Site Scripting</h1>
    <div class="input">
        <input type="text" id="message"/><br/>
        <button type="button" onclick="update()">submit</button>
    </div>
    <hr/>
    <div id="root">
        You typed : 
        <span id="show_message">
        </span>
    </div>
</body>

然后我尝试输入&lt;script&gt;alert(1);&lt;/script&gt;。但它不起作用。
问题出在哪里?

【问题讨论】:

  • 现在的浏览器不是在运动某种xss protection吗?最简单的测试是做一个stored xss,由于浏览器的反xss,好的旧反射(就像你做的那样)很少起作用。
  • .innerHTML不执行&lt;script&gt;&lt;/script&gt;内的代码,考虑使用document.write()执行

标签: javascript html xss


【解决方案1】:

script 标签不会运行,因为浏览器不会让你这样做。正是为了防止此类 XSS 攻击。

无论如何,如果你想看到它运行你可以查看其他answers

如果您只想要一个可以运行的输入,请使用img 创建一个

<image/src/onerror=alert(8)>

List

Codepen Demo

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-28
    • 1970-01-01
    • 2013-05-19
    • 2010-11-25
    • 2020-08-27
    • 1970-01-01
    相关资源
    最近更新 更多