DiceCtf 2024 Quals Web WriteUps

本文最后更新于:7 个月前

dicedicegoose

image-20240205152407464F12审计源码,

image-20240205152114668

image-20240205152158905

简单理解一下,就是 history 数组长度要为9,也就是只能走9步(骰子往下,黑块往左

因为黑色是随机方向走,所以我们打开控制台,直接修改 history 中黑色的位置历史就行

先自己走8步

1
2
3
4
i=9;history.forEach(innerArray => {
innerArray[1][1] = i--;
innerArray[1][0] = 9;
});

image-20240205153610723

funnylogin

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const express = require('express');
const crypto = require('crypto');

const app = express();

const db = require('better-sqlite3')('db.sqlite3');
db.exec(`DROP TABLE IF EXISTS users;`);
db.exec(`CREATE TABLE users(
id INTEGER PRIMARY KEY,
username TEXT,
password TEXT
);`);

const FLAG = process.env.FLAG || "dice{test_flag}";
const PORT = process.env.PORT || 3000;

const users = [...Array(100_000)].map(() => ({ user: `user-${crypto.randomUUID()}`, pass: crypto.randomBytes(8).toString("hex") }));
db.exec(`INSERT INTO users (id, username, password) VALUES ${users.map((u,i) => `(${i}, '${u.user}', '${u.pass}')`).join(", ")}`);

const isAdmin = {};
const newAdmin = users[Math.floor(Math.random() * users.length)];
isAdmin[newAdmin.user] = true;

app.use(express.urlencoded({ extended: false }));
app.use(express.static("public"));

app.post("/api/login", (req, res) => {
const { user, pass } = req.body;

const query = `SELECT id FROM users WHERE username = '${user}' AND password = '${pass}';`;
try {
const id = db.prepare(query).get()?.id;
if (!id) {
return res.redirect("/?message=Incorrect username or password");
}

if (users[id] && isAdmin[user]) {
return res.redirect("/?flag=" + encodeURIComponent(FLAG));
}
return res.redirect("/?message=This system is currently only available to admins...");
}
catch {
return res.redirect("/?message=Nice try...");
}
});

app.listen(PORT, () => console.log(`web/funnylogin listening on port ${PORT}`));

image-20240205154302333

很明显需要sql注入,

1' or 1=1 limit 1,1 --

比较细的点,文件开头生成的 id 是从0开始的,所以需要 limit 1,1

第二个条件需要 users[id]isAdmin[user] ,没有回显,所以没办法得知具体user名

这里使用__proto__1' or 1=1 limit 1,1 --搭配绕过

image-20240205154921931


DiceCtf 2024 Quals Web WriteUps
http://example.com/posts/3f2e31d4/
作者
Fanllspd
发布于
2024年2月5日
更新于
2024年2月12日
许可协议