Burp Web Academy Business Logic Vulnerabilities
0x01. PortSwigger Web Security Academy
PortSwigger Web Security Academy 是 Burp Suite 官方推出的免费 Web 安全学习靶场,在学习 Web 安全知识的同时,还可以练习 Burp Suite 的实战技能。
本篇文章讲解 Web Security Academy 之中的 Business Logic Vulnerabilities。
0x02. Business Logic Vulnerabilities
2.1 Lab: Excessive trust in client-side controls
This lab doesn’t adequately validate user input. You can exploit a logic flaw in its purchasing workflow to buy items for an unintended price. To solve the lab, buy a “Lightweight l33t leather jacket”.
You can log in to your own account using the following credentials:
wiener:peter
登录账号后加购物车,然后购买,发现加购物车是发送 POST 实现的:
1 | POST /cart |
清空购物车,修改 price
后重新添加,即可修改物品金额。
2.2 Lab: High-level logic vulnerability
This lab doesn’t adequately validate user input. You can exploit a logic flaw in its purchasing workflow to buy items for an unintended price. To solve the lab, buy a “Lightweight l33t leather jacket”.
You can log in to your own account using the following credentials:
wiener:peter
同样是 POST 添加购物车,发现可以把物品个数修改为负数,但是购物时需要结算金额大于 0
。
所以,可以通过添加其他物品(负数个数),控制结算价格在余额范围内即可。
1 | productId=16&redir=PRODUCT&quantity=-14 |
1 | POST /cart |
2.3 Lab: Inconsistent security controls
This lab’s flawed logic allows arbitrary users to access administrative functionality that should only be available to company employees. To solve the lab, access the admin panel and delete the user
carlos
.
访问 /admin
,提示 Admin interface only available if logged in as a DontWannaCry user
。
先注册账号,登陆后把自己的邮箱修改为 @DontWannaCry.com
即可。
2.4 Lab: Flawed enforcement of business rules
This lab has a logic flaw in its purchasing workflow. To solve the lab, exploit this flaw to buy a “Lightweight l33t leather jacket”.
You can log in to your own account using the following credentials:
wiener:peter
页面顶部有一个优惠码:New customers use code at checkout: NEWCUST5
,可以优惠五块。
页面底部有一个订阅功能,订阅后提示:Use coupon SIGNUP30 at checkout!
,可以打七折。
间隔输入这两个优惠码,可以持续优惠(注意不可以一致重复提交一个优惠码)。
尝试过随机爆破优惠码,但不可行。
2.5 Lab: Low-level logic flaw
This lab doesn’t adequately validate user input. You can exploit a logic flaw in its purchasing workflow to buy items for an unintended price. To solve the lab, buy a “Lightweight l33t leather jacket”.
You can log in to your own account using the following credentials:
wiener:peter
看起来底层是用 int32
来计算购物车金额的,所以持续添加物品,可以让整数溢出。再适当调整购物车的物品,可以让余额在 0 - 100
之间。注意不能是负数,负数不让提交。
因为单个物品一次提交最多 99
个,所以涉及到在 Burp 中如何快速重复发送 HTTP 请求的问题。在 Burp Intruder 中,先清除所有标记,然后将 Payload type 设置为 Null Payloads,即可在 Payload options 中指定 Generate 多少个 payload。
1 | pow(2,31) |
看到 214748...
就应该联想到 int32
。
2.6 Lab: Inconsistent handling of exceptional input
This lab doesn’t adequately validate user input. You can exploit a logic flaw in its account registration process to gain access to administrative functionality. To solve the lab, access the admin panel and delete the user
carlos
.
参考官方解答,有点开脑洞:利用子域名和字符串截断伪造一个指定后缀的邮箱地址。
首先,使用超长的邮箱注册一个账户,激活后登录,发现用户中心邮件地址被截断了,邮箱长度最大 255
。因此,可以构造 xxxx...xxxx@dontwannacry.com.exploit-0a75002d04f7595e80cec5ba011500f9.exploit-server.net
,只需要确保截断后后缀为 @dontwannacry.com
即可。
2.7 Lab: Weak isolation on dual-use endpoint
This lab makes a flawed assumption about the user’s privilege level based on their input. As a result, you can exploit the logic of its account management features to gain access to arbitrary users’ accounts. To solve the lab, access the
administrator
account and delete the usercarlos
.You can log in to your own account using the following credentials:
wiener:peter
在修改密码界面,需要提交如下四个字段:
- 用户名
- 当前密码
- 新密码
- 确认新密码
尝试修改 administrator
的密码,提示当前密码不对。换个思路,如果管理员要重置一个人的密码,很可能并不知道原始密码,但是管理员需要有这个权限。所以尝试不填写当前密码,但是会提示这是必填字段。因此,修改 POST 发包参数:
1 | POST /my-account/change-password |
成功修改了 carlos
的密码,并可登录。然后,普通用户没法删除自身,所以,尝试修改 administrator
的密码,登陆后删除 carlos
即可。
2.8 Lab: Insufficient workflow validation
This lab makes flawed assumptions about the sequence of events in the purchasing workflow. To solve the lab, exploit this flaw to buy a “Lightweight l33t leather jacket”.
You can log in to your own account using the following credentials:
wiener:peter
看题目意思可能是可以条件竞争,不过不太知道怎么在 Burp 中操作,参考接替答案,发现不是条件竞争。
购物完成后,会跳转到 /cart/order-confirmation?order-confirmed=true
,因此,尝试加购物车后直接访问该页面即可:
1 | GET /cart/order-confirmation?order-confirmed=true |
2.9 Lab: Authentication bypass via flawed state machine
This lab makes flawed assumptions about the sequence of events in the login process. To solve the lab, exploit this flaw to bypass the lab’s authentication, access the admin interface, and delete the user
carlos
.You can log in to your own account using the following credentials:
wiener:peter
登陆后会有一个角色选择,尝试将角色修改为 admin
或者 administrator
都没有效果。而 /admin
只有管理员才可以访问。看了官方题解,把角色选择的请求拦截掉即可。注意,登陆后会重定向到 /role-selector
,不要发出这个请求,因此登录前就要开启拦截功能。
2.10 Lab: Infinite money logic flaw
This lab has a logic flaw in its purchasing workflow. To solve the lab, exploit this flaw to buy a “Lightweight l33t leather jacket”.
You can log in to your own account using the following credentials:
wiener:peter
题目有两个值得关注的功能:
- 底部订阅功能,可以得到一个七折优惠码
SIGNUP30
- 商品列表有一个 10 块的礼品卡可以购买
- 礼品卡购买后可以充值到账户
利用上面的功能组合,可以无限膨胀金额。充值礼品卡可以使用 Burp Intruder,不用一个一个手工充值。
2.11 Lab: Authentication bypass via encryption oracle
This lab contains a logic flaw that exposes an encryption oracle to users. To solve the lab, exploit this flaw to gain access to the admin panel and delete the user
carlos
.You can log in to your own account using the following credentials:
wiener:peter
所谓 Encryption Oracle,即加密预言机,攻击者能接触到一个黑盒,他可以任意输入明文并输出密文,但是攻击者对黑盒的内部构造一无所知。
首先,登录时有个 Stay logged in
选项,选中并登录后,会生成一个 Cookie 用来保持登录态。
1 | stay-logged-in=k%2fhROkc31%2fF5Uz9SeehfGRaYG%2bX1izvb4Nyt0XLSt5E%3d |
在评论时如果提交不合法的 Email 地址,比如 testATgmail.com
,会提示 Invalid email address: testATgmail.com
。
正常的评论 HTTP Response Header:
1 | 302 Found |
使用不合法 Email 提交评论后的 HTTP Response Header:
1 | 302 Found |
重定向之后的请求:
1 | GET /post?postId=2 |
只要携带这个 notification
Cookie,响应页面就会出现:
1 | <header class="notification-header"> |
尝试使用 stay-logged-in
的值替换 notification
字段,得到 wiener:1741507092076
。
同时,如果使用 wiener:1741507092076
作为 Email 地址,则得到:
1 | jUYPViaXrK%2bv25jVI4zHorgHLf5rAjIMcmLWEg0YaV2eNF65seq%2fE1CjxFuzetr5 |
经过 URL 编码解码,再经过 Base64 解码,得到:
1 | 8D 46 0F 56 26 97 AC AF AF DB 98 D5 23 8C C7 A2 |
这跟原始的 stay-logged-in
的值解码后不太一样:
1 | 93 F8 51 3A 47 37 D7 F1 79 53 3F 52 79 E8 5F 19 |
如果使用 notification=jUYPViaXrK%2bv25jVI4zHorgHLf5rAjIMcmLWEg0YaV2eNF65seq%2fE1CjxFuzetr5
访问页面,得到 Invalid email address: wiener:1741507092076
,说明在生成 notification
时,明文内容可能添加了 Invalid email address:
这个字符串。
加解密内容看起来是 16 字节对齐的,如果进行如下操作:
1 | 8D 46 0F 56 26 97 AC AF AF DB 98 D5 23 8C C7 A2 // 删除这一行 |
使用 notification=uAct/msCMgxyYtYSDRhpXZ40Xrmx6r8TUKPEW7N62vk=
访问页面,得到 dress: wiener:1741507092076
。这里 Invalid email ad
刚好 16
字节,所以,我们可以构造如下 Email 地址:
1 | Invalid email address: 456789012administrator:1741507092076 |
使用 456789012administrator:1741507092076
作为 Email 地址评论文章,得到:
1 | jUYPViaXrK%2bv25jVI4zHov%2bxa0JpLwMiozj4Q4rYDLWvfxCiVaNnhUkhMxL%2bpCtRnjReubHqvxNQo8Rbs3ra%2bQ%3d%3d |
使用 Python 切割:
1 | import urllib.parse |
使用 stay-logged-in=r38QolWjZ4VJITMS/qQrUZ40Xrmx6r8TUKPEW7N62vk=
即可登录 administrator 账号。
0x03. 小结
- 使用 Burp Intruder 重复发送 HTTP Request
- 简单的 Encryption Oracle 应用
0x04. Attack models in cryptography
原文来自 Attack models in cryptography,我觉得写的简单明了,复制过来存档:
现代密码学的一个重要原则被称为Kerckhoff’s principle,要求密码系统的安全性不能依赖于算法的保密性,而只能依赖于密钥的保密性。由此,密码学算法对攻击者总是已知的。
在此之上,根据攻击者能够获取的不同明密文信息将其攻击能力分为几个模型。能力由弱到强有唯密文攻击,已知明文攻击,选择明文攻击,选择密文攻击等模型。以下结合具体实例介绍这样几个攻击模型。
另一方面,攻击者的目标其实也可以分为两种,一是破解密钥;二是获取某一特定密文的明文。显然后者的难度不会高于前者。
1 唯密文攻击
唯密文攻击(Ciphertext-only Attack-COA),即攻击者只获得了若干密文,而没有任何的明文信息。这是最强的一种假设,即攻击者能力最弱,当然也是最低安全性要求。要实施这种攻击也很简单,只要监听信道就可以抓取密文信息了。
2 已知明文攻击
已知明文攻击(Known-Plaintext Attack-KPA),指攻击者有若干明密文对,在此基础上进行密钥破解或者明文推测。现实中如何获取明密文对呢,很多协议开头有magic number或者类似的标识信息,这些协议的内容加密后显然就是这些magic number或者标识信息对应的密文。
3 选择明文攻击
选择明文攻击(Chosen-Plaintext Attack-CPA),指攻击者占据加密机(encryption oracle),从而可以构造任意明文并用加密机得到其密文,据此进行密钥破解或者明文推测。此处加密机应当理解为内含加密密钥和加密算法的一个黑盒,攻击者不能从中取出密钥,但是可以输入任意明文由该黑盒吐出用密钥加密后的密文。
选择明文攻击的经典例子来自二战。日军在珊瑚海战后即将中途岛确定为下一个攻击目标,美海军情报局由于破译了日军部分密码,了解到了这一计划,但是具体攻击目标未能成功破译(日军密电中称为’AF’),综合其他因素推断也不能明确,一部分人认为是中途岛,另一部分人则认为是阿留申群岛。后来,美军想到一个绝妙的主意,他们通过无线电向珍珠港报告,说中途岛上的海水净化装置故障导致岛上缺水,不久从日军截获的密电中即出现了’AF’缺水的内容,从而明确了日军目标即中途岛。
4 选择密文攻击
选择密文攻击(Chosen-Ciphertext Attack-CCA),指攻击者能实施选择明文攻击,即能够得到任意明文对应的密文的情况下,还占据解密机(decryption oracle)从而可以构造任意密文并使用解密机解密得到其明文,据此进行密钥破解或者明文推测,当然这里要排除攻击者期望攻击的密文。与选择明文攻击类似,这里所谓占据解密机,也是指攻击者能够在不知道密钥的情况下构造任意的密文获得其明文。
根据攻击者能够构造密文的阶段不同,CCA又可进一步分为CCA1(Non-adaptive CCA),CCA2(Adaptive CCA)两个模型。二者的差别在于,在CCA1中,攻击者一次性将构造好的一组密文输入解密机得到它们对应的明文;而在CCA2中,攻击者可以在前一个密文解密得到的明文基础上构造后续要解密的密文。
一个实际的CCA2攻击的例子是针对PKCS#1 random padding的Bleichenbacher攻击。