Method: Msf::Exploit::Remote::HttpClient#send_request_raw

Defined in:
lib/msf/core/exploit/remote/http_client.rb

#send_request_raw(opts = {}, timeout = 20, disconnect = false) ⇒ Object

Connects to the server, creates a request, sends the request, reads the response

Passes opts through directly to Rex::Proto::Http::Client#request_raw.


316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/msf/core/exploit/remote/http_client.rb', line 316

def send_request_raw(opts = {}, timeout = 20, disconnect = false)
  if datastore['HttpClientTimeout'] && datastore['HttpClientTimeout'] > 0
    actual_timeout = datastore['HttpClientTimeout']
  else
    actual_timeout = opts[:timeout] || timeout
  end

  c = connect(opts)
  r = opts[:cgi] ? c.request_cgi(opts) : c.request_raw(opts)

  if datastore['HttpTrace']
    request_color, response_color =
      (datastore['HttpTraceColors'] || '').split('/').map { |color| "%bld%#{color}" }

    request = r.to_s(headers_only: datastore['HttpTraceHeaders'])

    print_line('#' * 20)
    print_line('# Request:')
    print_line('#' * 20)
    print_line("%clr#{request_color}#{request}%clr")
  end

  res = c.send_recv(r, actual_timeout)

  if datastore['HttpTrace']
    print_line('#' * 20)
    print_line('# Response:')
    print_line('#' * 20)

    if res
      response = res.to_terminal_output(headers_only: datastore['HttpTraceHeadersOnly'])

      print_line("%clr#{response_color}#{response}%clr")
    else
      print_line('No response received')
    end
  end

  disconnect(c) if disconnect

  res
rescue ::Errno::EPIPE, ::Timeout::Error => e
  print_line(e.message) if datastore['HttpTrace']
  nil
rescue Rex::ConnectionError => e
  vprint_error(e.to_s)
  nil
rescue ::Exception => e
  print_line(e.message) if datastore['HttpTrace']
  raise e
end