Skip to content

Redirects and Raw Requests

This page covers following redirects and requests that send_request_cgi cannot handle.

res = send_request_cgi!(
{
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'old')
},
20, # timeout
3 # redirect_depth
)

For a 30x response, it follows the Location header. The URI reached is stored in opts['redirect_uri'].

reconfig_redirect_opts! changes POST to GET and clears data / vars_post. It is unsuitable if you need to follow a login POST while keeping the POST method. In that case, read Location yourself and construct the next send_request_cgi call.

res = send_request_cgi(...)
if res && res.redirect?
loc = res.redirection
res = send_request_cgi(
'method' => 'GET',
'uri' => loc.path
)
end

Use this when you need to depart from the HTTP specification or make the request look like a non-HTTP protocol.

send_request_raw({
'method' => 'DESCRIBE',
'proto' => 'RTSP',
'version' => '1.0',
'uri' => '/' + ('../' * 560) + "\xcc\xcc\x90\x90" + '.smi'
})
send_request_raw(
'method' => 'GET',
'uri' => '/index.php',
'headers' => {
'Host' => "x\r\nX-Injected: 1"
}
)

For ordinary requests that need query or form construction, use send_request_cgi.

# Third argument to cgi
send_request_cgi({ 'uri' => '/' }, 20, false) # Do not disconnect
send_request_cgi({ 'uri' => '/next' }, 20, true)

The default disconnect value for send_request_raw is false. This matters when you need to keep the connection open for keep-alive or findsock.

send_request_cgi(
'method' => 'GET',
'uri' => '/health',
'rhost' => '10.10.11.200',
'rport' => 8080,
'SSL' => false,
'vhost' => 'internal.htb'
)