πŸ•΄οΈJenkins

We could try to spam default credentials and from there gain access via the groovy console using a reverse shell.

If we cant then we should try to create a new account and create a job.

If we dont have the build options then we can get code execution via scheduling.

Method 1: Schedule

Clicking the β€œConfigure” link in the sidebar leads back to the settings for the job, where I’ll look more closely at the β€œBuild Triggers” section:

image-20220227065323109

β€œBuild periodically” seems promising. I’ll check that box, which gives a empty text field. Jenkins uses a schedule system similar to cron. I’ll enter β€œ* * * * *”, and it warns me that this will run every minute:

image-20220227065621251

I’ll save and after a minute, refresh the page, and there’s a build in the history:

image-20220227065719113

Hovering over the β€œ#1” there’s a dropdown:

image-20220227065741004

β€œConsole Output” shows the job ran:

image-20220227065815838

Method 2: Trigger Remotely

Running different commands waiting one minute between each one is a bit exhausting. I’ll disable the scheduled trigger. Looking at the other options for β€œBuild Triggers”, β€œTrigger builds remotely (e.g., from scripts)” seems interesting. Checking it expands out asking for an β€œAuthentication Token”:

image-20220227113123491

I can try just adding a string as the token (say β€œTestToken”) and requesting the endpoint they give, but it doesn’t work:

Back during enumeration I found where I could create API tokens in my profile. I’ll head there and click β€œAdd new Token”:

image-20220227113733612

I’ll name it 0xdfToken and click generate:

image-20220227113810458

I’ll also update the batch script with the job so that it’s clear why it triggered:

image-20220227124131900

This post shows how to actually trigger the job. I’ll need to use the url of the form:

So for me, that’s:

There’s no response from the server, but the job triggers, and a moment later there’s console output:

image-20220227124212845

Jenkins Enumeration

Look for Creds

I’ll look for the creds associated with the admin account. This could get more access in Jenkins, or perhaps give WinRM access to the host. This article talks about how each user’s information is stored in a config.xml file. This article talks about the encryption used to store secrets.

Note: I’m still running commands by editing the job, triggering it, and then checking the console output. For the sake of readability, I’ll just be showing the output from this point on unless there’s a reason to show it.

Looking at the previous console returns, it’s clear the job is running from C:\Users\oliver\AppData\Local\Jenkins\.jenkins\workspace\0xdf's job. Looking up a couple directories:

The user information is stored in /users/:

In that admin directory, there’s a config.xml:

I’ll dump that file and save it to my local workstation:

There’s both a hash and an encrypted password.

Decrypt Password

I could try to brute force the hash, but decrypting the password will be easier. Most of the references that will come up on Google (like this one) show how to do this through the script console (/script), but as I showed above, I don’t have access to that.

I found two repos on Github that had methods for decrypting user passwords stored on Jenkins. This one is written in Go, and this one has a ton of Python scripts for pentesting Jenkins.

Both require the config.xml, as well as master.key and hudson.util.Secret, but from /secrets/:

master.key looks like it’s stored in hex:

In any case that the thing is not 256 bytes we can trim the new line by using the following commands.

I can verify I got the full thing by making sure it’s the same length, 256 bytes:

hudson.util.Secret looks like a binary file:

image-20220228165017916

I’ll use PowerShell to base64 encode it:

Now I can copy that string and echo it into base64 -d on my local system to save it to a file.

Downloading the Go binary from jenkins-credential-decryptor like in these instructions works great:

The pwn_jenkins Python script works as well:

Last updated