@@ -187,13 +187,66 @@ def check_setup
187
187
error_message
188
188
end
189
189
190
+ # Sends a HTTP request with Rex
191
+ #
192
+ # @param [Hash] Native support includes the following (also see Rex::Proto::Http::Request#request_cgi)
193
+ # @option opts[String] 'host' The remote host
194
+ # @option opts[Fixnum] 'port' The remote port
195
+ # @option opts[Boolean] 'ssl' The SSL setting, TrueClass or FalseClass
196
+ # @option opts[String] 'proxies' The proxies setting
197
+ # @option opts[Credential] 'credential' A credential object
198
+ # @option opts['Hash'] 'context' A context
199
+ # @raise [Rex::ConnectionError] One of these errors has occured: EOFError, Errno::ETIMEDOUT, Rex::ConnectionError, ::Timeout::Error
200
+ # @return [Rex::Proto::Http::Response] The HTTP response
201
+ # @return [NilClass] An error has occured while reading the response (see #Rex::Proto::Http::Client#read_response)
202
+ def send_request ( opts )
203
+ rhost = opts [ 'host' ] || host
204
+ rport = opts [ 'rport' ] || port
205
+ cli_ssl = opts [ 'ssl' ] || ssl
206
+ cli_ssl_version = opts [ 'ssl_version' ] || ssl_version
207
+ cli_proxies = opts [ 'proxies' ] || proxies
208
+ username = opts [ 'credential' ] ? opts [ 'credential' ] . public : ''
209
+ password = opts [ 'credential' ] ? opts [ 'credential' ] . private : ''
210
+ realm = opts [ 'credential' ] ? opts [ 'credential' ] . realm : nil
211
+ context = opts [ 'context' ] || { 'Msf' => framework , 'MsfExploit' => framework_module }
212
+
213
+ res = nil
214
+ cli = Rex ::Proto ::Http ::Client . new (
215
+ rhost ,
216
+ rport ,
217
+ context ,
218
+ cli_ssl ,
219
+ cli_ssl_version ,
220
+ cli_proxies ,
221
+ username ,
222
+ password
223
+ )
224
+ configure_http_client ( cli )
225
+
226
+ if realm
227
+ cli . set_config ( 'domain' => credential . realm )
228
+ end
229
+
230
+ begin
231
+ cli . connect
232
+ req = cli . request_cgi ( opts )
233
+ res = cli . send_recv ( req )
234
+ rescue ::EOFError , Errno ::ETIMEDOUT , Rex ::ConnectionError , ::Timeout ::Error => e
235
+ raise Rex ::ConnectionError , e . message
236
+ ensure
237
+ cli . close
238
+ end
239
+
240
+ res
241
+ end
242
+
243
+
190
244
# Attempt a single login with a single credential against the target.
191
245
#
192
246
# @param credential [Credential] The credential object to attempt to
193
247
# login with.
194
248
# @return [Result] A Result object indicating success or failure
195
249
def attempt_login ( credential )
196
-
197
250
result_opts = {
198
251
credential : credential ,
199
252
status : Metasploit ::Model ::Login ::Status ::INCORRECT ,
@@ -209,32 +262,13 @@ def attempt_login(credential)
209
262
result_opts [ :service_name ] = 'http'
210
263
end
211
264
212
- http_client = Rex ::Proto ::Http ::Client . new (
213
- host , port , { 'Msf' => framework , 'MsfExploit' => framework_module } , ssl , ssl_version ,
214
- proxies , credential . public , credential . private
215
- )
216
-
217
- configure_http_client ( http_client )
218
-
219
- if credential . realm
220
- http_client . set_config ( 'domain' => credential . realm )
221
- end
222
-
223
265
begin
224
- http_client . connect
225
- request = http_client . request_cgi (
226
- 'uri' => uri ,
227
- 'method' => method
228
- )
229
-
230
- response = http_client . send_recv ( request )
266
+ response = send_request ( 'credential' => credential , 'uri' => uri , 'method' => method )
231
267
if response && response . code == 200
232
268
result_opts . merge! ( status : Metasploit ::Model ::Login ::Status ::SUCCESSFUL , proof : response . headers )
233
269
end
234
- rescue :: EOFError , Errno :: ETIMEDOUT , Rex ::ConnectionError , :: Timeout :: Error => e
270
+ rescue Rex ::ConnectionError => e
235
271
result_opts . merge! ( status : Metasploit ::Model ::Login ::Status ::UNABLE_TO_CONNECT , proof : e )
236
- ensure
237
- http_client . close
238
272
end
239
273
240
274
Result . new ( result_opts )
0 commit comments