【问题标题】:How to perform a simple DOM-based XSS attack如何执行简单的基于 DOM 的 XSS 攻击
【发布时间】:2013-11-20 01:48:28
【问题描述】:

这是我的 index.html(易受攻击):

<!DOCTYPE html>
<html>

  <head>
    <link rel="stylesheet" href="style.css">
    <script src="script.js"></script>
  </head>
<script>
    document.write("<form><select>"); 

    document.write("<option value=1>" + 
    document.location.href.substring(document.location.href.indexOf("default=") + 8)
+ "</option>");

    document.write("<option value=2> French </option>");

    document.write("</select> </form>");
    document.write(document.location.href);
</script>
  <body>

  </body>

</html>

它应该从../index.html?default=English 获取默认语言,这会将默认语言设置为英语。

我正在尝试使用../index.html?default=&lt;script&gt;alert(document.cookie)&lt;/script&gt; 在屏幕上显示cookie,但浏览器似乎将&gt; 编码为%3E。我也用过\x3Cscript&gt;alert(document.cookie)\x3C/script&gt;\x3Cscript\3Ealert(document.cookie)\x3C/script\3E and &amp;lt;script&amp;gt;alert(document.cookie)&amp;lt;/script&amp;gt;,但没有运气。

【问题讨论】:

  • 您是否尝试过通过控制台向该页面发送直接获取请求?
  • 我已经重新格式化了你的代码和also made a plunkr out of it

标签: javascript html dom xss


【解决方案1】:

您的易受攻击的代码需要在解析出该位置的字符串上使用decodeURIComponent,才能使攻击起作用:

document.write("<option value=1>" + 
    decodeURIComponent(
        document.location.href.substring(
            document.location.href.indexOf("default=") + 8)) 
    + "</option>");

这样做是“有意义的”(对于编写易受攻击的代码的人......),因为来自 URL 的字符串可能合法地包含诸如 &gt; 之类的字符。

有关演示,请参阅http://plnkr.co/edit/Vctoj7GOLMvlvhS98Mk4?p=preview

【讨论】:

  • 感谢您的回复。有人根据您的解释编写该代码是有意义的。
猜你喜欢
  • 1970-01-01
  • 2016-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-05
  • 2023-03-08
  • 1970-01-01
相关资源
最近更新 更多