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

Magic

18 Apr 2020 · 13 min read · root access
Magic - maquina de Hack The Box

Executive summary — Magic chains a SQL injection authentication bypass on a login form, an uploaded polyglot image that the server executes as PHP despite type and extension filters, the recovery of MySQL database credentials reused as a system user's password, and ends in root by abusing a SUID binary that calls other programs by name instead of by absolute path.

PlatformHack The Box
Operating systemLinux
DifficultyMedium
StatusRetired
Target IP10.129.44.34

Attack map

[80] Magic Portfolio — static gallery, login form at login.php
   │  SQL injection in the authentication query -> login bypass
   ▼
[302] upload.php — "Magic Upload"
   │  PNG+PHP polyglot image with double extension .php.png
   ▼
[RCE]  www-data
   │  db.php5 leaks MySQL credentials; the password stored in the
   │  login table turns out to be the real password of user theseus
   ▼
[su/SSH]  theseus  (user.txt)
   │  SUID /bin/sysinfo calls lshw/fdisk/free without an absolute path
   ▼
[ROOT]  PATH hijacking -> SUID copy of bash

1. Reconnaissance

nmap -sV -sC --top-ports 100 -Pn -oN recon/nmap-top.txt 10.129.44.34
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
|_http-title: Magic Portfolio

OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 + Apache 2.4.29 points to Ubuntu 18.04. Only two open ports: with SSH ruled out as an initial vector, the whole attack lives on port 80.

curl -s http://10.129.44.34/ | grep -oiE 'href="[^"]*"'
href="assets/css/main.css"
href="login.php"     <- login form

The homepage is an image gallery ("Magic Portfolio") linking to login.php, with username/password fields. Everything points to image uploads sitting behind that login.

🔒 Clearance required

This content is Root Access only. Everything else on the site — the free tier, the whole public library — stays open.

See Root Access plans

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