如何在HTML环境中执行JavaScript
对于一个测试项目,我想创建一个 xss clibnerable站点。我的基本结构是一个论坛,人们可以在其中通过输入字段和提交按钮添加论坛帖子。目前,我呈现新帖子,该帖子应通过InnerHTML显示,但是使用此方法,恶意(例如< script> arter(“ 123”)</script>
)脚本,我想插入它攻击者没有被执行。我搜索了Innerhtml的其他替代方案,但它们都没有起作用。如何在代码中实现JavaScript渲染?
我尝试的事情
appendChild();
eval();
insertAdjacentElement();
创建新帖子的输入字段
<form>
<label for="topic"
>Topic:
<br />
<input id="topic" required
/></label>
<br />
<br />
<label for="text"
>Text:
<br />
<input id="text" type="text" required
/></label>
<br />
<button type="submit" id="submit">submit</button>
</form>
输入示例文本字段(localstorage是输入字段的存储)
<div id="post">
<script>
if (localStorage.length > 0) {
post.innerHTML += localStorage.key(0);
}
</script>
</div>
For a testing project I want to create a XSS vulnerable site. My basic structure is a forum where people can add forum posts via input fields and a submit button. Currently I render the new post which should be displayed via innerHTML but with this method the malicious (e.g. <script>alert("123")</script>
) script which I want to insert as an attacker gets not executed. I searched for other alternatives to innerHTML but none of them worked. How can I achieve JavaScript rendering in my code?
Things I tried
appendChild();
eval();
insertAdjacentElement();
Input fields for creation new post
<form>
<label for="topic"
>Topic:
<br />
<input id="topic" required
/></label>
<br />
<br />
<label for="text"
>Text:
<br />
<input id="text" type="text" required
/></label>
<br />
<button type="submit" id="submit">submit</button>
</form>
Input example text field (localStorage is the storage from the input fields)
<div id="post">
<script>
if (localStorage.length > 0) {
post.innerHTML += localStorage.key(0);
}
</script>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案
此功能实际上为我提供了所需的行为。
Solution
This function gives me actually the desired behaviour.