Table of Contents
Pennyworth is another starting point, In this video, we will be exploring precisely this typology of attack vectors.
Enumeration
Click on Spawn Machine and you can see the IP address of the target machine.
As always, we will be starting with the nmap scan. The -sC and -sV switches will be employed in order to force default script usage and advanced version detection for services identified on any of the open ports. This will help us get a better overview of the target and understand its' purpose on the network.
From the output of the scan, we find a singular result of
interest. Jetty version 9.4.39 is running on an open TCP port 8080.
Like any other HTTP
server, we will need to use our browser to explore this service easily.
Navigating the IP address along with the port combination of the target
through our URL search bar will yield the following result.
The HTTP server seems to be running a Jenkins service.
Jenkins Service and Default credential vulnerability
A small summary of this service can be found in the snippet below. It will give us a general idea of the capabilities of such a service and how it might interact with the backend. Any interactions are essential, as they can serve as a gateway to gaining a foothold on the host running everything in the backend. If any of them are misconfigured, they could prove to be an easy path of exploitation for an attacker.
Jenkins is a free and open-source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and delivery. It is a server-based system.
The only hint of leverage we currently have against this login screen would be to attempt logging in using default credentials. In the hopes that the server administrators have not yet finished configuring the Jenkins service. Let’s try to log in with the default Jenkins login credential.
Fortunately, we were right. Attempting multiple
combinations, we land on successful login and are presented with the
administrative panel for the Jenkins service. Now, it is time to look around.
Foothold
After looking around the website, I found a script console. This
script console indicates to us that it only executes the Groovy Script.
Since it only executes the Groovy commands, we will need to create a payload in Groovy to execute the reverse shell connection. Specifically, we will make the remote server connect to us by specifying our IP address and the port that we will listen on for new connections. Through that listening port, the target will end up sending us a connection request, which our host will accept, forming an interactive shell with control over the target's backend system.
Obtaining a Reverse Shell in Jenkins Using Groovy Commands
In order to do that, we will need a specially crafted payload, which we can find in this GitHub cheatsheet . The payload we are looking at looks like this:
Copy this code to Notepad. Now change the IP address to the currently deployed VPN connection. In order to get your IP address for the currently deployed VPN connection, switch the tab to OpenVPN, scroll down, and then you see the IP address.
After finding out your IP address and replacing it in the Script Console.
Now copy the whole script and paste it to the console:
Before running the command pasted in the Jenkins Script Console, we need to make sure our listener script is up and running on the same port as specified in the command above, for int port=4242. To achieve this, we will use a tool called Netcat.
If you are also a Windows user then you have to download
Netcat by searching on Google. There is a problem with every Windows machine.
Windows Defender automatically detects Netcat as a virus. So, We have to disable
the Windows Defender before running this tool.
Run this tool from the command prompt by typing cmd in the bar. In order to see how to use this tool, we can input the nc -h command into our terminal window.
After a short analysis of the help output, we can open a new terminal tab and type in the following command to start a Netcat listener on the specified port. This will make our attacker host ready to receive connections from the target, the last remaining step before launching the script we placed in the Jenkins Script Console.
Now that our listener is turned on, we can execute the
payload by clicking the Run button.
Once the script is run, we can navigate to the Command Prompt, where Netcat is running, and check on the connection state. From the output, we understand that a connection has been received from an unknown source, and then blank space. We can try to interact with the shell by typing in the whoami and id commands.
These commands help verify our permission level on the target system. From the output, we can quickly determine that we rest at the highest level of privilege.
We have command execution. Navigate to the /root directory on the target and read the flag.
As you can see the flag on my screen. Copy this flag and
paste it to Hack the Box.
Task Answers
TASK 1: What does the acronym CVE stand for?
Ans. Common Vulnerabilities and ExposuresTASK 2: What do the three letters in CIA, referring to the CIA triad in cybersecurity, stand for?
Ans. confidentiality, integrity, availabilityTASK 3: What is the version of the service running on port 8080?
Ans. Jetty 9.4.39.v20210325TASK 4: What version of Jenkins is running on the target?
Ans. 2.289.1TASK 5: What type of script is accepted as input on the Jenkins Script Console?
Ans. GroovyTASK 6: What would the "String cmd" variable from the Groovy Script snippet be equal to if the Target VM was running Windows?
Ans. cmd.exeTASK 7: What is a different command than "ip a" we could use to display our network interfaces' information on Linux?
Ans. ifconfigTASK 8: What switch should we use with Netcat for it to use UDP transport mode?
Ans. -uTASK 9: What is the term used to describe making a target host initiate a connection back to the attacker host?
Ans. reverse shell