Skip to content

Commit 215174c

Browse files
committed
fix IPv6 loopback bug
1 parent 20875a2 commit 215174c

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

aikido_zen/vulnerabilities/ssrf/find_hostname_in_userinput.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Only exports find_hostname_in_userinput function
33
"""
44

5+
from typing import List
6+
57
from aikido_zen.helpers.get_port_from_url import get_port_from_url
68
from aikido_zen.helpers.try_parse_url import try_parse_url
79

@@ -13,14 +15,12 @@ def find_hostname_in_userinput(user_input, hostname, port=None):
1315
if len(user_input) <= 1:
1416
return False
1517

16-
hostname_url = try_parse_url(f"http://{hostname}")
17-
if not hostname_url:
18-
return False
18+
hostname_options = get_hostname_options(hostname)
1919

2020
variants = [user_input, f"http://{user_input}", f"https://{user_input}"]
2121
for variant in variants:
2222
user_input_url = try_parse_url(variant)
23-
if user_input_url and user_input_url.hostname == hostname_url.hostname:
23+
if user_input_url and user_input_url.hostname in hostname_options:
2424
user_port = get_port_from_url(user_input_url.geturl())
2525

2626
# We were unable to retrieve the port from the URL, likely because it contains an invalid port.
@@ -35,3 +35,17 @@ def find_hostname_in_userinput(user_input, hostname, port=None):
3535
return True
3636

3737
return False
38+
39+
40+
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)
45+
46+
# 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)
50+
51+
return options

0 commit comments

Comments
 (0)