Skip to content

Commit 79a3981

Browse files
committed
Move the punycode check to get_hostname_options
1 parent d7d3a03 commit 79a3981

2 files changed

Lines changed: 12 additions & 17 deletions

File tree

aikido_zen/vulnerabilities/ssrf/find_hostname_in_context.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@ def find_hostname_in_context(hostname, context: Context, port):
1919
if is_request_to_itself(context.url, hostname, port):
2020
return None
2121

22-
# Punycode detected in hostname, while user input may not be in Punycode
23-
# We need to convert it to ensure we compare the right values
24-
if "xn--" in hostname:
25-
try:
26-
hostname = hostname.encode("ascii").decode("idna")
27-
except Exception:
28-
# Seems to be a malformed Punycode sequence, retain original
29-
# hostname
30-
pass
31-
3222
for user_input, path, source in extract_strings_from_context(context):
3323
found = find_hostname_in_userinput(user_input, hostname, port)
3424
if found:

aikido_zen/vulnerabilities/ssrf/find_hostname_in_userinput.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,19 @@ def find_hostname_in_userinput(user_input, hostname, port=None):
3838

3939

4040
def get_hostname_options(raw_hostname: str) -> List[str]:
41-
options = []
42-
hostname_url = try_parse_url(f"http://{raw_hostname}")
43-
if hostname_url and hostname_url.hostname:
44-
options.append(hostname_url.hostname)
41+
options_urls = [try_parse_url(f"http://{raw_hostname}")]
4542

4643
# Add a case for hostnames like ::1 or ::ffff:127.0.0.1, who need brackets to be parsed
47-
hostname_url_ipv6 = try_parse_url(f"http://[{raw_hostname}]")
48-
if hostname_url_ipv6 and hostname_url_ipv6.hostname:
49-
options.append(hostname_url_ipv6.hostname)
44+
options_urls.append(try_parse_url(f"http://[{raw_hostname}]"))
45+
46+
# Add a case when the hostname is in punycode (like xn--pp-oia.aikido.dev)
47+
if "xn--" in raw_hostname:
48+
hostname_decoded = raw_hostname.encode("ascii", errors="").decode("idna")
49+
options_urls.append(try_parse_url(f"http://{hostname_decoded}"))
5050

51+
# Map to url.hostname
52+
options = []
53+
for options_url in options_urls:
54+
if options_url and options_url.hostname:
55+
options.append(options_url.hostname)
5156
return options

0 commit comments

Comments
 (0)