| Titel | SourceCodester Online Food Ordering System 1.0 SQL Injection |
|---|
| Beschreibung | ## Description
The administrator creation handler trims the submitted username and inserts it directly into a `SELECT` used for the duplicate-account check. Trimming removes surrounding whitespace but does not escape quotes or bind the value. An attacker can change the query predicate and observe the result through the “username already exists” versus success/error branches.
## Source evidence and analysis
Repository root: `targets/web-scan-20261028/web/`.
`admin/add_admin.php` (lines 7–8 and 22–27):
```php
$fullname = trim($_POST['fullname']);
$username = trim($_POST['username']);
...
$password_hash = md5($password_raw);
$user = "select * from tbl_admin where username = '$username'";
$execute = mysqli_query($conn, $user);
$count = mysqli_num_rows($execute);
if ($count === 0) {
```
This is a source-to-sink path from `$_POST['username']` to SQL syntax with no SQL-specific protection. Later, the `INSERT` escapes `fullname` and `username` at lines 29–35. That later escaping does not protect the earlier duplicate-check `SELECT`; the two queries must be assessed separately.
## Reproduction (disposable local instance only)
Use a disposable test database containing at least one administrator. The payload changes the predicate to true, so the handler takes the “username already exists” branch:
```bash
BASE=http://127.0.0.1:8080
curl -i -X POST "$BASE/admin/add_admin.php" \
--data-urlencode 'submit=1' \
--data-urlencode 'fullname=Probe User' \
--data-urlencode "username=probe' OR '1'='1' -- " \
--data-urlencode 'password=TestPass1!'
```
The password satisfies the handler's uppercase/lowercase/digit/symbol checks. Inspect the response for the duplicate-name branch. Do not use an existing account or production database.
## Impact and scope
The caller controls a database predicate and can infer its truth through the account-creation branch. With suitable conditional expressions, that response can act as a boolean oracle against data visible to the database connection; this handler does not directly print the selected rows, so this report does not claim direct table dumping. The shared authentication guard also fails to stop unauthenticated execution (G01), which increases reachability.
## Recommended fix
Use a prepared statement for the duplicate check and enforce a unique database constraint on `username`; treat a duplicate-key result as the authoritative outcome. Keep the existing insert parameterized as well. Authentication must be enforced independently of these SQL controls.
|
|---|
| Quelle | ⚠️ https://gist.github.com/Ka7arotto/c74ecc431ff3df8150a66bd3063113c5 |
|---|
| Benutzer | Goku (UID 80486) |
|---|
| Einreichung | 28.10.2026 13:19 (vor 29 Tagen) |
|---|
| Moderieren | 26.11.2026 01:58 (29 days later) |
|---|
| Status | Akzeptiert |
|---|
| VulDB Eintrag | 444128 [SourceCodester Online Food Ordering System 1.0 Admin Panel admin/add_admin.php username SQL Injection] |
|---|
| Punkte | 20 |
|---|