猿问

使用有意的 HTML 注入创建 HTML

我是一名网络安全学生,试图了解一些基本的 HTML 注入。我已经研究这段代码几天了,无法理解我做错了什么。我目前拥有的代码确实允许注入,例如,如果我放入<h1>test</h1>文本框,它会将测试显示为标题。但是如果我尝试<script>alert(1)</script>它实际上不会运行脚本。我曾尝试将文本框的值设置为 "" 或认为我可以通过在文本框中输入以下内容来关闭该行:"><script>alert(1)</script>


我还尝试通过在末尾添加注释来取消代码的其余部分,如下所示: <script>alert(1)</script><!--


我已经尝试了多种组合,但都没有运气。现在我实际上需要能够注入脚本,因为我正在使用 CSP 以及它如何影响将脚本注入网页。我目前没有指定会限制 JavaScript 运行的 csp。我尝试过的其他一些事情包括使用不同的浏览器、更改浏览器安全性以及确保在浏览器中启用 JavaScript。任何帮助将不胜感激!!


<html>

    <script language='JavaScript'>

    function getwords(){

        textbox = document.getElementById('words');

        label = document.getElementById('label');

        label.innerHTML = textbox.value;

    }

    </script>


    <body>

        <input type="text" id="words">

        <input type="button" onclick="getwords()" id="Button" value="Enter" />

        <label id="label">

        </label>

    </body>

</html>


慕后森
浏览 189回答 3
3回答

米琪卡哇伊

要从您的表单执行 javascript,您可以尝试:<iframe&nbsp;src=javascript:alert(1)>或者<img&nbsp;src=x&nbsp;onerror=alert(1)>另外值得注意的是:script使用插入的元素在插入innerHTML时不会执行。

HUH函数

要手动执行 JavaScript,您可以执行以下操作无需编辑 HTML 文件,将其添加到浏览器的输入字段中。<iframe onload="alert(1)" style="display:none"></iframe>关于为什么这在这里起作用的更多信息有关如何在此处执行此类操作的更多信息:developer.mozilla.org<html>&nbsp; &nbsp; <script language='JavaScript'>&nbsp; &nbsp; function getwords(){&nbsp; &nbsp; &nbsp; &nbsp; textbox = document.getElementById('words');&nbsp; &nbsp; &nbsp; &nbsp; label = document.getElementById('label');&nbsp; &nbsp; &nbsp; &nbsp; label.innerHTML = textbox.value;&nbsp; &nbsp; }&nbsp; &nbsp; </script>&nbsp; &nbsp; <body>&nbsp; &nbsp; &nbsp; &nbsp; <input type="text" id="words">&nbsp; &nbsp; &nbsp; &nbsp; <input type="button" onclick="getwords()" id="Button" value="Enter" />&nbsp; &nbsp; &nbsp; &nbsp; <label id="label">&nbsp; &nbsp; &nbsp; &nbsp; </label>&nbsp; &nbsp; </body></html>

智慧大石

这是因为<script>s 在页面加载时运行,并且当label的内容更改时,脚本已经运行。但是,如果您将<script>标签注入不同的页面(通过后端(XSS 意味着跨站点脚本)),它确实有效。或者,要使其在页面加载后注入内容的场景中工作(如您的情况),您可以使用 JS 事件(如onclick)来运行您的代码:<div&nbsp;onclick="alert(1)">Click&nbsp;me!</div>或者,要在没有用户交互的情况下执行它,您可以使用<iframe>'sonload事件:<iframe&nbsp;onload="alert(1)"&nbsp;style="display:none"></iframe>
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答