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.


356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/msf/core/exploit/remote/http_client.rb', line 356

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 = opts['client'] || 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