Networked
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.phpreveals how to build a.php.jpgfilename that passes both the extension whitelist and the MIME-type check, and that Apache still executes because of a badly anchoredAddHandlerdirective — RCE asapache. 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 asguly(user.txt). The final jump to root abuses asudoscript that writes a network configuration without quoting: once "sourced" byifup, a value containing a space is interpreted as a variable assignment followed by the execution of an arbitrary command as root.
| Platform | Hack The Box |
| Operating system | Linux (CentOS Linux 7.6.1810) |
| Difficulty | Easy |
| Status | Retired |
| Target IP | 10.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/]
Resumen ejecutivo — Networked expone un backup del código fuente por un listado de directorios olvidado, lo que convierte el ataque en caja blanca: la lectura de
upload.php/lib.phprevela cómo construir un nombre de fichero.php.jpgque pasa la whitelist de extensión y el chequeo de tipo MIME, y que Apache ejecuta igualmente por una directivaAddHandlermal anclada — RCE comoapache. Desde ahí, un cron que se supone vigila ataques (check_attack.php) resulta ser él mismo vulnerable a inyección de comandos vía el nombre de fichero, lo que da acceso comoguly(user.txt). El salto final a root abusa de un script desudoque escribe una configuración de red sin comillas: al ser "sourceada" porifup, un valor con espacio se interpreta como una asignación de variable seguida de la ejecución de un comando arbitrario como root.
| Plataforma | Hack The Box |
| Sistema operativo | Linux (CentOS Linux 7.6.1810) |
| Dificultad | Easy |
| Estado | Retired |
| IP objetivo | 10.129.48.147 |
Mapa del ataque
[80/HTTP] /backup -- listado de directorios habilitado -> backup.tar (fuente PHP)
│
▼
[upload.php] Bypass de la whitelist de subida -- doble extensión .php.jpg +
cabecera GIF (magic bytes)
│ AddHandler php5-script .php (sin anclar al final) -> Apache ejecuta el
│ ".php" intermedio del nombre
▼
[RCE] apache -- webshell polyglot subida a /uploads
│ cron de guly (check_attack.php) interpola el NOMBRE del fichero, sin
│ sanear, dentro de exec()
▼
[SSH] guly (user.txt)
│ sudo NOPASSWD /usr/local/sbin/changename.sh -> ifup hace "source" del
│ ifcfg generado como si fuera un script de bash
▼
[ROOT] NAME=x /tmp/x ejecutado como root al cargar la interfaz (root.txt)
1. Reconocimiento
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
Dos detalles útiles antes incluso de tocar los servicios: un ping devuelve ttl=63 — un solo salto de router desde un TTL inicial de 64, típico de Linux. Y el motivo de filtrado host-prohibited (ICMP tipo 3, código 10) es la respuesta característica de firewalld/iptables con REJECT --reject-with icmp-host-prohibited, la regla por defecto de RHEL/CentOS — se puede intuir la distribución antes de ver un solo banner.
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 confirman CentOS 7. PHP 5.4 lleva sin soporte desde 2015: buena señal de que el vector estará en la web.
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>
El comentario HTML upload and gallery not yet linked es la pista: existen funcionalidades desplegadas pero no enlazadas desde el índice. "No enlazado" no es un control de acceso.
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/]
This content is Root Access only. Everything else on the site — the free tier, the whole public library — stays open.
See Root Access plansNo account? Create one free then upgrade from your console.
Este contenido es solo para Root Access. Todo lo demás del sitio — el nivel gratuito, toda la biblioteca pública — sigue abierto.
Ver planes de Root Access¿Sin cuenta? Crea una gratis y luego mejora desde tu consola.