Insomnia

Description

Welcome back to Insomnia Factory, where you might have to work under the enchanting glow of the moon, crafting dreams and weaving sleepless tales.

URL: https://app.hackthebox.com/challenges/Insomniaarrow-up-right

Source

entrypoint.sh

#!/bin/bash

# Initialize SQLite database with a table and an initial user
touch /var/www/html/Insomnia/database/insomnia.db
chmod 666 /var/www/html/Insomnia/database/insomnia.db

sqlite3 /var/www/html/Insomnia/database/insomnia.db <<'EOF'
CREATE TABLE IF NOT EXISTS users (
    id INTEGER PRIMARY KEY,
    username TEXT NOT NULL,
    password TEXT NOT NULL
);
INSERT INTO users (username, password) VALUES ('administrator', LOWER(hex(randomblob(16))));
EOF

# Create JWT secret key
echo "JWT_SECRET='$(openssl rand -hex 32)'" >> /var/www/html/Insomnia/.env

# Start Apache server
apache2-foreground

apache.conf

web_insomnia/Insomnia/app/Controllers/ProfileController.php

web_insomnia/Insomnia/app/Controllers/UserController.php

Solution

Insomnia.png

If we register with creds x:y we get redirected to /profile

Insomnia-1.png

I thought this would be SQLi, but all query statements are prepared queries so we can't do anything about it.

But the application is JWT based, and in login code we see some wacky statement:

The condition is almost always the False, so in the SQL query we can query the username since they are unique and become any user.

Insomnia-2.png

Set the cookie and visit /index.php/profile

Insomnia-3.png
circle-check

Last updated