Shocker is an easy-rated Linux machine from HackTheBox, created by mrb3n. In the current writeup, my IP is 10.10.14.210, and the target IP is 10.129.37.21
Recon
The first steps are about getting basic information about the target, by using nmap and searching information from the website.
By the TTL, we can assume that is a Linux Machine, because it's close to 63.
Local Terminal
nmap-p---open-sS--min-rate5000-vvv-n10.129.37.21
Someclosedportsmaybereportedasfiltereddueto--defeat-rst-ratelimitPORTSTATESERVICEREASON80/tcpopenhttpsyn-ackttl622222/tcpopenEtherNetIP-1syn-ackttl62Readdatafilesfrom:/usr/bin/../share/nmapNmapdone:1IPaddress (1 hostup) scanned in 16.62 secondsRawpacketssent:78689 (3.462MB) |Rcvd:76654 (3.066MB)
And then we try to get the version and run basic scripts with Nmap in each port.
Se encontraron dos puertos relevantes, el puerto 80, donde se hostea el servicio web objetivo, y el puerto ssh que esta ubicado en el puerto 2222.
Como detalle, si buscas en Google "OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 launchpad", encontraras el tipo de build que utiliza, en este caso es un Ubuntu Xenial. Si ingresamos a la maquina y comprobamos que es el mismo, se puede suponer que no es un contenedor
A simple vista, no hay nada importante, veamos el sitio web directamente
Web Exploring
At the source-code, there is absolutely nothing... let's fuzz it!
Al parecer hay varios paths extraños, pero al ingresar, el más curioso es /cgi-bin/user.sh, que al ingresar, descargas un archivo.
Exploit CGI-based web server
Fragmento de un request? Al parecer es un mal manejo del navegador... la alternativa seria ver que ve Burpsuite al enviar una peticion al mismo lugar.
Ahora sabemos que se descarga por el espacio que hay en la linea 8, o mostraria en texto plano tu tiempo actual, de todas formas, la informacion es la misma. Es un script que corre en bash.
Finding
Al buscar más al respecto, se encuentra que existe una serie de vulnerabilidades tipo CGI-based Web Server que nos permitiria cambiar el comando que esta ejecutando el script simple y realizar un RCE. Para explotarlo, tienes que cambiar en Burpsuite el User-Agent a lo siguiente:
Al buscar más al respecto, se encuentra que existe una serie de vulnerabilidades tipo CGI-based Web Server que nos permitiria cambiar el comando que esta ejecutando el script simple y realizar un RCE. Para comprobar su existencia, nmap tiene un script que detectara si es vulnerable o no.
Como podemos apreciar, el target si es vulnerable a Shellshock, es bueno tener presente este script ante paths que finalicen en .sh
Exploit
Ahora para explotarlo, tienes que cambiar en Burpsuite el User-Agent a lo siguiente:
Funciono! Acabamos de ejecutar el comando "id", ahora solo falta ejecutar una reverse shell. Primero hay que abrir con netcat un vector y luego inyectar el codigo
Nmap scan report for 10.129.37.21
Host is up (0.16s latency).
PORT STATE SERVICE VERSION
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Site doesn't have a title (text/html).
2222/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 c4:f8:ad:e8:f8:04:77:de:cf:15:0d:63:0a:18:7e:49 (RSA)
| 256 22:8f:b1:97:bf:0f:17:08:fc:7e:2c:8f:e9:77:3a:48 (ECDSA)
|_ 256 e6:ac:27:a3:b5:a9:f1:12:3c:34:a5:5d:5b:eb:3d:e9 (ED25519)
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 13.29 seconds
Nmap scan report for 10.129.37.21
Host is up (0.040s latency).
PORT STATE SERVICE VERSION
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
| http-shellshock:
| VULNERABLE:
| HTTP Shellshock vulnerability
| State: VULNERABLE (Exploitable)
| IDs: CVE:CVE-2014-6271
| This web application might be affected by the vulnerability known
| as Shellshock. It seems the server is executing commands injected
| via malicious HTTP headers.
|
| Disclosure date: 2014-09-24
| References:
| http://www.openwall.com/lists/oss-security/2014/09/24/10
| https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-6271
| http://seclists.org/oss-sec/2014/q3/685
|_ https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-7169
shelly@Shocker:/home/shelly$ id
uid=1000(shelly) gid=1000(shelly) groups=1000(shelly),4(adm),24(cdrom),30(dip),46(plugdev),110(lxd),115(lpadmin),116(sambashare)
shelly@Shocker:/home/shelly$ whoami
shelly
shelly@Shocker:/home/shelly$ uname -a
Linux Shocker 4.4.0-96-generic #119-Ubuntu SMP Tue Sep 12 14:59:54 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
shelly@Shocker:/home/shelly$ sudo -l
Matching Defaults entries for shelly on Shocker:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User shelly may run the following commands on Shocker:
(root) NOPASSWD: /usr/bin/perl
shelly@Shocker:/home/shelly$