CVE Explained CVE-2024-23897
Explaining the jenkins arbitrary file read vulnerability
Last updated
Explaining the jenkins arbitrary file read vulnerability
Last updated
references
Exploits:
My python exploit Here
Vulnerability Type: Unauthenticated Remote Code Execution (RCE) CVE ID: CVE-2024-23897 CVSS Severity Score: 9.8 (Critical) Application: Jenkins Impact: Allows unauthenticated attackers to execute arbitrary code and read arbitrary files by exploiting a critical remote code execution vulnerability. Severity: Critical Affected Versions: Multiple versions of Jenkins are impacted. Check here Patch Available: Yes Mitigation: Organizations are strongly advised to apply the latest security updates and patches promptly. Affected Versions: Jenkins 2.441 and earlier, LTS 2.426.2 and earlier.
The exploitation is possible from HTTP
,CLI
, websockets
.
The flow
The attacker endpoint makes two different POST
request.
Post Request 1
The first POST
request makes an upload
request containing the commands and it's arguments.
Post Request 2
The second post request is for the commands to executed and contains the result by the first post request and download the contents of the result.
Why is it happening
Now the whole process involves these methods which start a domino effect that eventually leads to catastrophe , these methods are:
CliCrumbExecution : To Validate endpoint via process
function
FullDuplexHttpService : This handles the request
and response
via 3 methods:
generateResponse:
This method calls the other two methods on the basis of header called side
and seeing the uuid
string {which we generated random in exploit}
Download
Upload
PlainCLIProtocol: This is the method that continuously reads frames from the input stream and handles frame on it's length
CLICommand: This method actually contains the vulnerable code which is the CmdLineParser
which is the part of the args4j
library responsible for the vulnerability.
Now when we look at the code for this args4j
-> we find this parseArgument
function which eventually calls the expandAtFiles
method which is the actual vulnerable code:
now look at this function :
what it does:
For each element, if it starts with the character '@'
, it is treated as a file reference. It then:
Removes the '@'
character from the beginning to obtain the file path.
Checks if the file exists. If not, it throws a CmdLineException
with an appropriate error message.
Reads all lines from the file and adds them to the result
list.
Using the HACK-THE-BOX's machine called Builder for such.
Jenkins says that we can access the jenkins via the jenkins-cli
and download when we setup jenkins , now since we have the jenkins already setup , we can download it from here: See that's why I said earlier websocket
and HTTP
:
we send the request:
Looking at the wireshark for what it did in bg:
Reading Sensitive files
Now what I can do here is read the files which contains the hash of the user :
I can leverage this information and get the password by cracking it , considering the possibility , it's weak.
I also wrote the python exploit for the same , can be accessed here