Skip to content
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
2 changes: 1 addition & 1 deletion lib/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1830,7 +1830,7 @@ def parseTargetUrl():
singleTimeWarnMessage("credentials in the target URL are ignored. Use '--auth-cred' for HTTP authentication")
netloc = netloc.rsplit('@', 1)[-1]

hostnamePort = netloc.split(":") if not re.search(r"\[.+\]", netloc) else filterNone((re.search(r"\[.+\]", netloc).group(0), re.search(r"\](:(?P<port>\d+))?", netloc).group("port")))
hostnamePort = netloc.split(":") if not re.search(r"\[.+\]", netloc) else re.split(r"(?<=\]):", netloc, maxsplit=1)

conf.scheme = (urlSplit.scheme.strip().lower() or "http")
conf.path = urlSplit.path.strip()
Expand Down
33 changes: 32 additions & 1 deletion tests/test_targeturl.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@

from lib.core.common import parseTargetUrl
from lib.core.data import conf
from lib.core.exception import SqlmapSyntaxException

_TARGETURL_KEYS = ("url", "hostname", "port", "scheme", "path")
_TARGETURL_KEYS = ("url", "hostname", "port", "scheme", "path", "ipv6")
_saved = {}


Expand Down Expand Up @@ -101,5 +102,35 @@ def test_credentials_with_ipv6(self):
self.assertEqual((host, port), ("::1", 8443))


class TestIPv6Ports(unittest.TestCase):
def test_invalid_port_suffixes(self):
for port in ("abc", "-1", "8080junk", "80:90", ""):
for scheme in ("http", "https", "ws", "wss"):
url = "%s://[::1]:%s/path?id=1" % (scheme, port)
with self.assertRaises(SqlmapSyntaxException):
_parse(url)

def test_out_of_range_ports(self):
for port in (0, 65536):
with self.assertRaises(SqlmapSyntaxException):
_parse("http://[::1]:%s/" % port)

def test_valid_explicit_ports(self):
for host in ("::1", "2001:db8::1", "::ffff:192.0.2.1"):
for port in (1, 80, 443, 8080, 65535):
parsed = _parse("http://[%s]:%d/path?id=1" % (host, port))
self.assertEqual(parsed, (host, port, "http", "/path"))
self.assertTrue(conf.ipv6)

def test_default_ports(self):
for scheme, port in (("http", 80), ("https", 443), ("ws", 80), ("wss", 443)):
self.assertEqual(_parse("%s://[::1]/path" % scheme), ("::1", port, scheme, "/path"))
self.assertEqual(conf.url, "%s://[::1]/path" % scheme)

def test_userinfo_with_invalid_port(self):
with self.assertRaises(SqlmapSyntaxException):
_parse("http://user:pass@[::1]:8080junk/path")


if __name__ == "__main__":
unittest.main(verbosity=2)