acorn clicker

0xgnud17 pentester

acorn clicker - web - very_easy

Tên : acorn clicker
Description: Click acorns. Buy squirrels. Profit.
Có source code

Phân tích

Mục tiêu cần tích đủ 999999999999999999 acorn để mua được flag.

Phân tích source code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
app.post("/api/click", authenticate, async (req, res) => {
// increase user balance
const { username } = req.user;
const { amount } = req.body;

if (typeof amount !== "number") {
return res.status(400).send("Invalid amount");
}

if (amount > 10) {
return res.status(400).send("Invalid amount");
}

let bigIntAmount;

try {
bigIntAmount = BigInt(amount);
} catch (err) {
return res.status(400).send("Invalid amount");
}

await db
.collection("accounts")
.updateOne({ username }, { $inc: { balance: bigIntAmount } });

res.json({ earned: amount });
});

Ta thấy ở đây Mongodb sử dụng kiểu dữ liệu BigInt để lưu số acorn,điểm đặc biệt ở đây là kiểu dữ liệu này ko biểu diễn số âm.
-> Nếu ta làm cho số acorn thành âm thì Mongodb sẽ wrap thành số rất lớn.

Exploit

Race condition:
Gửi 2 request mua cùng 1 lúc để số acorn thành âm:
Dùng tính năng Send Group (paralleel) của Burp Suite:

Sau khi send,giá trị acorn âm sẽ được wrap thành rất lớn:

Lấy flag:

Flag: squ1rrel{1nc0rr3ct_d3s3r1al1zat10n?_1n_MY_m0ng0?}