Skip to content

send_request_cgi

send_request_cgi is HttpClient’s CGI-compatible HTTP request API. Its implementation is in lib/msf/core/exploit/remote/http_client.rb; opts are defined in lib/rex/proto/http/client.rb / client_request.rb.

PageContents
Option referenceAvailable opts / datastore options
HTTP methods and parametersGET / POST / PUT / raw query / encoding
Authentication and cookiesBasic / form login / self-registration / cookie jar / CSRF
Body and multipartJSON / raw body / MIME / vars_form_data
Redirects and raw requestssend_request_cgi! / send_request_raw
Responses and debuggingResponse handling, parsers, RCE success checks, HttpTrace
res = send_request_cgi(
{
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'index.php'),
'vars_get' => { 'q' => '1' }
},
20 # timeout
)
return if res.nil?

The method arguments are as follows.

send_request_cgi(opts = {}, timeout = 20, disconnect = true)
ArgumentMeaning
optsHash containing the request
timeoutSeconds. Often passed as datastore['HttpClientTimeout']
disconnectWhether to disconnect after the response. Defaults to true

A timeout or connection failure returns nil. Always check for it.

Choosing between send_request_cgi and send_request_raw

Section titled “Choosing between send_request_cgi and send_request_raw”
APIBest suited for
send_request_cgivars_get / vars_post / forms / cookie jar
send_request_rawNonstandard methods, malformed HTTP, or HTTP-like protocols
send_request_cgi!Following 30x redirects
TaskKey / API
GET with a queryvars_get
Form POSTvars_post
Raw query stringquery
JSON / arbitrary bodydata + ctype
Manual multipartRex::MIME::Message + data + ctype
Simple multipartvars_form_data
Basic authenticationauthorization / basic_auth
Keep a form login sessionkeep_cookies
Self-registration → loginRegistration POST → login POST + keep_cookies
Authenticated JSON APIkeep_cookies on login; data + ctype for JSON
Fixed cookiecookie
Additional headersheaders
Override Hostvhost
Temporary request to another hostrhost / rport / SSL
Follow redirectssend_request_cgi!
Disable encodingencode_params: false
  • ctype sets the format of the outgoing body through the Content-Type header. For JSON, use 'ctype' => 'application/json'. If omitted for POST, application/x-www-form-urlencoded is added.
  • Accept specifies the desired response format. To request JSON, use 'headers' => { 'Accept' => 'application/json' }. Setting ctype does not add Accept automatically, so specify both for APIs that require content negotiation.