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

Networked

24 Aug 2019 · 23 min read · root access
Networked - maquina de Hack The Box

Executive summary — Networked exposes a source-code backup through a forgotten directory listing, which turns the attack into a white-box exercise: reading upload.php/lib.php reveals how to build a .php.jpg filename that passes both the extension whitelist and the MIME-type check, and that Apache still executes because of a badly anchored AddHandler directive — RCE as apache. From there, a cron job that's supposed to watch for attacks (check_attack.php) turns out to be vulnerable to command injection through the filename itself, granting access as guly (user.txt). The final jump to root abuses a sudo script that writes a network configuration without quoting: once "sourced" by ifup, a value containing a space is interpreted as a variable assignment followed by the execution of an arbitrary command as root.

PlatformHack The Box
Operating systemLinux (CentOS Linux 7.6.1810)
DifficultyEasy
StatusRetired
Target IP10.129.48.147

Attack map

[80/HTTP] /backup -- directory listing enabled -> backup.tar (PHP source)
   │
   ▼
[upload.php] Upload whitelist bypass -- double extension .php.jpg +
              GIF header (magic bytes)
   │  AddHandler php5-script .php (not anchored to the end) -> Apache
   │  executes the intermediate ".php" in the filename
   ▼
[RCE] apache -- polyglot webshell uploaded to /uploads
   │  guly's cron job (check_attack.php) interpolates the unsanitized
   │  FILENAME straight into exec()
   ▼
[SSH] guly (user.txt)
   │  sudo NOPASSWD /usr/local/sbin/changename.sh -> ifup "sources" the
   │  generated ifcfg as if it were a bash script
   ▼
[ROOT] NAME=x /tmp/x executed as root when the interface loads (root.txt)

1. Reconnaissance

sudo nmap -p- --min-rate 3000 -T4 -Pn -oN nmap-allports.txt 10.129.48.147
Not shown: 65483 filtered tcp ports (no-response), 49 filtered tcp ports (host-prohibited)
PORT    STATE  SERVICE
22/tcp  open   ssh
80/tcp  open   http
443/tcp closed https

Two useful details before even touching the services: a ping comes back with ttl=63 — one router hop away from an initial TTL of 64, typical of Linux. And the host-prohibited filtering reason (ICMP type 3, code 10) is the characteristic response of firewalld/iptables with REJECT --reject-with icmp-host-prohibited, the default rule on RHEL/CentOS — the distro can be guessed before a single banner is seen.

sudo nmap -p22,80 -sCV -Pn -oN nmap-services.txt 10.129.48.147
22/tcp open  ssh     OpenSSH 7.4 (protocol 2.0)
80/tcp open  http    Apache httpd 2.4.6 ((CentOS) PHP/5.4.16)

OpenSSH 7.4 + Apache 2.4.6 + PHP 5.4.16 confirm CentOS 7. PHP 5.4 has been unsupported since 2015: a good sign the vector will be in the web app.

curl -s http://10.129.48.147/
<html>
<body>
Hello mate, we're building the new FaceMash!</br>
Help by funding us and be the new Tyler&Cameron!</br>
Join us at the pool party this Sat to get a glimpse
<!-- upload and gallery not yet linked -->
</body>
</html>

The HTML comment upload and gallery not yet linked is the tell: functionality has been deployed but not linked from the index page. "Not linked" isn't an access control.

gobuster dir -u http://10.129.48.147/ \
  -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt \
  -t 20 -x php,txt,html -q -o gobuster80.txt
/index.php            (Status: 200) [Size: 229]
/uploads              (Status: 301) [--> http://10.129.48.147/uploads/]
/photos.php           (Status: 200) [Size: 1302]
/upload.php           (Status: 200) [Size: 169]
/lib.php              (Status: 200) [Size: 0]
/backup               (Status: 301) [--> http://10.129.48.147/backup/]
🔒 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.