Skip to content

URI Helpers

URI handling and display helpers around HttpClient.

register_options(
[
OptString.new('TARGETURI', [true, 'Base path', '/app/'])
]
)
base = target_uri.path
# => "/app/"
uri = normalize_uri(base, 'admin', 'upload.php')
# => "/app/admin/upload.php"

normalize_uri follows these rules:

  1. The path starts with /.
  2. Duplicate slashes are collapsed.
  3. The caller’s intent determines whether the path ends with a slash.
send_request_cgi(
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'index.php')
)
print_status("Target URL: #{full_uri}")
# http://10.10.11.123/app/
path = path_from_uri('https://example.htb/a/b')
# "/a/b"
res = request_url('http://example.htb/file.txt')
data = download('http://example.htb/file.bin')

Use these methods to fetch temporarily from an absolute URL. For normal module requests, use send_request_cgi with normalize_uri.

print_status("#{peer} requesting...")
# 10.10.11.123:80
fail_with(Failure::Unreachable, "#{peer} - no response") if res.nil?
MethodDescription
rhostTarget IP address or host
rportTarget port
peerDisplay as host:port
vhostValue for the Host header
ssl / ssl?Whether TLS is in use
Rex::Text.uri_encode(cmd, 'hex-all')

vars_get and vars_post encode parameters by default through encode_params: true. Add 'encode_params' => false only when you intentionally need to send raw values.