Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ipv6 compatibility issue in build_url #347

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ Rook1e <https://github.com/0x2E>

ekszz <https://github.com/ekszz>
* contributing to customize poc protocol and default port #321

HomerQing <https://github.com/HomerQing>
* contributing to fix ipv6 compatibility issue in build_url
6 changes: 2 additions & 4 deletions pocsuite3/lib/core/poc.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def build_url(self):

try:
pr = urlparse(target)
is_ipv6 = pr.netloc.startswith('[')
self.scheme = pr.scheme
self.rhost = pr.hostname
self.rport = pr.port or self.current_protocol_port
Expand All @@ -209,7 +210,7 @@ def build_url(self):
# adjust port
if not self.rport:
self.rport = protocol_default_port_map[self.current_protocol]
self.netloc = f'{self.rhost}:{self.rport}'
self.netloc = f'[{self.rhost}]:{self.rport}' if is_ipv6 else f'{self.rhost}:{self.rport}'
pr = pr._replace(scheme=self.scheme)
pr = pr._replace(netloc=self.netloc)
target = pr.geturl()
Expand Down Expand Up @@ -366,9 +367,6 @@ def _check(self, dork='', allow_redirects=False, return_obj=False, is_http=True,
if self.url.split('://')[0] != self.scheme:
logger.warn(f'auto correct url: {mosaic(origin_url)} -> {mosaic(self.url)}')
self.scheme = 'https' if self.url.startswith('https') else 'http'
port = urlparse(self.url).port
self.rport = port if port else 443 if self.scheme.startswith('https') else 80
self.netloc = f'{self.rhost}:{self.rport}'

if return_obj:
return res
Expand Down
17 changes: 17 additions & 0 deletions tests/test_build_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ def _verify(self):
self.assertEqual(res[0]["result"]["VerifyInfo"]["rport"], 8443)
self.assertEqual(res[0]["result"]["VerifyInfo"]["netloc"], "127.0.0.1:8443")

# [fd12:3456:789a:1::2]:8443
f.seek(0)
config = {
"url": "[fd12:3456:789a:1::2]:8443",
"poc": f.name,
}
init_pocsuite(config)
start_pocsuite()
res = get_results()
self.assertEqual(
res[0]["result"]["VerifyInfo"]["url"], "https://[fd12:3456:789a:1::2]:8443"
)
self.assertEqual(res[0]["result"]["VerifyInfo"]["scheme"], "https")
self.assertEqual(res[0]["result"]["VerifyInfo"]["rhost"], "fd12:3456:789a:1::2")
self.assertEqual(res[0]["result"]["VerifyInfo"]["rport"], 8443)
self.assertEqual(res[0]["result"]["VerifyInfo"]["netloc"], "[fd12:3456:789a:1::2]:8443")

def test_url_protocol_correct(self):
with CustomNamedTemporaryFile("w+t") as f:
poc_content = textwrap.dedent(
Expand Down