root@thehacksparrow:~/writeups$ SYSTEM ONLINE
root@sparrow:~/writeups$ cat falafel.md
// writeups

Falafel

3 Feb 2018 · 23 min read · root access
Falafel - maquina de Hack The Box

Executive summary — Falafel chains a vulnerable PHP web app with an unconventional Linux privilege escalation path. A forgotten text file (cyberlaw.txt) accidentally leaks the entire attack roadmap: that the login can be bypassed without knowing the password, and that the image upload filter has a gap. A boolean-based blind SQL injection in login.php extracts, character by character, the MD5 hashes of two users; one falls to a wordlist, the other is a "magic hash" exploiting a loose (==) PHP comparison. With admin access, a URL-based image upload feature falls victim to a wget filename truncation that smuggles a PHP webshell past the extension filter. From there, the escalation uses no SUID binary and no sudo rule at all: it relies on membership in the video and disk groups to, first, literally screenshot another user's graphical session by reading the raw framebuffer, and then read the entire disk bypassing filesystem permissions with debugfs.

PlatformHack The Box
Operating systemLinux (Ubuntu 16.04)
DifficultyHard
StatusRetired
Target IP10.129.229.139

Attack map

[80] Falafel Lovers (Apache 2.4.18 + PHP) — /cyberlaw.txt leaks 2 hints + admin/chris usernames
   │  boolean oracle in login.php ("Wrong identification" vs "Try again")
   ▼
[Blind SQLi]  character-by-character extraction (binary search) from mysql.user
   │  chris:juggling (MD5 cracked with rockyou) -> valid login, no access to upload.php
   │  admin: "magic" hash 0e462096... -> type juggling (PHP ==) -> password 240610708
   ▼
[admin] upload.php — downloads a URL with wget; the filter only checks the URL's extension
   │  wget truncates the on-disk filename to 236 bytes -> .php.png basename (240B) -> .php
   ▼
[RCE]  PHP webshell uploaded -> code execution as www-data
   │  connection.php leaks moshe:falafelIsReallyTasty -> SSH reuse
   ▼
[moshe]  (user.txt) — video group -> cat /dev/fb0 (raw framebuffer)
   │  reconstructs yossi's tty1 screen: password mistakenly typed as a passwd argument
   ▼
[yossi]  disk group -> debugfs -R 'cat ...' /dev/sda1 (reads inodes, bypassing permissions)
   ▼
[ROOT]  root.txt + /root/.ssh/id_rsa read raw off the disk -> SSH as root

1. Reconnaissance

sudo nmap -p- --min-rate 5000 -T4 -Pn -n 10.129.229.139
sudo nmap -sCV -p22,80 -Pn -n 10.129.229.139
22/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.4
80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
|_http-title: Falafel Lovers
| http-robots.txt: 1 disallowed entry /*.txt

Two recon details already point somewhere: the web service is called "Falafel Lovers" (a custom app, not a known CMS), and robots.txt explicitly disallows any path ending in .txt — almost always a tell that there's a .txt file somewhere the owner would rather Google not index.

gobuster dir -u http://10.129.229.139/ -w directory-list-2.3-medium.txt -x php,txt
/login.php       (200)
/profile.php     (200)
/upload.php      (200)
/uploads         (200)
/cyberlaw.txt    (200)
/connection.php  (200)

The combination of paths already sketches the app: an authentication system (login.php/profile.php), a file upload feature (upload.php plus the uploads/ directory), a database configuration file exposed by name (connection.php), and, thanks to robots.txt, a .txt worth checking first.

🔒 Clearance required

Root Access unlocks the content you can't see — everything else on the site is already open.

See Root Access plans

No account? Create one free then upgrade from your console.