|
27 | 27 |
|
28 | 28 | from lib.core.common import parseTargetUrl |
29 | 29 | from lib.core.data import conf |
| 30 | +from lib.core.exception import SqlmapSyntaxException |
30 | 31 |
|
31 | | -_TARGETURL_KEYS = ("url", "hostname", "port", "scheme", "path") |
| 32 | +_TARGETURL_KEYS = ("url", "hostname", "port", "scheme", "path", "ipv6") |
32 | 33 | _saved = {} |
33 | 34 |
|
34 | 35 |
|
@@ -101,5 +102,35 @@ def test_credentials_with_ipv6(self): |
101 | 102 | self.assertEqual((host, port), ("::1", 8443)) |
102 | 103 |
|
103 | 104 |
|
| 105 | +class TestIPv6Ports(unittest.TestCase): |
| 106 | + def test_invalid_port_suffixes(self): |
| 107 | + for port in ("abc", "-1", "8080junk", "80:90", ""): |
| 108 | + for scheme in ("http", "https", "ws", "wss"): |
| 109 | + url = "%s://[::1]:%s/path?id=1" % (scheme, port) |
| 110 | + with self.assertRaises(SqlmapSyntaxException): |
| 111 | + _parse(url) |
| 112 | + |
| 113 | + def test_out_of_range_ports(self): |
| 114 | + for port in (0, 65536): |
| 115 | + with self.assertRaises(SqlmapSyntaxException): |
| 116 | + _parse("http://[::1]:%s/" % port) |
| 117 | + |
| 118 | + def test_valid_explicit_ports(self): |
| 119 | + for host in ("::1", "2001:db8::1", "::ffff:192.0.2.1"): |
| 120 | + for port in (1, 80, 443, 8080, 65535): |
| 121 | + parsed = _parse("http://[%s]:%d/path?id=1" % (host, port)) |
| 122 | + self.assertEqual(parsed, (host, port, "http", "/path")) |
| 123 | + self.assertTrue(conf.ipv6) |
| 124 | + |
| 125 | + def test_default_ports(self): |
| 126 | + for scheme, port in (("http", 80), ("https", 443), ("ws", 80), ("wss", 443)): |
| 127 | + self.assertEqual(_parse("%s://[::1]/path" % scheme), ("::1", port, scheme, "/path")) |
| 128 | + self.assertEqual(conf.url, "%s://[::1]/path" % scheme) |
| 129 | + |
| 130 | + def test_userinfo_with_invalid_port(self): |
| 131 | + with self.assertRaises(SqlmapSyntaxException): |
| 132 | + _parse("http://user:pass@[::1]:8080junk/path") |
| 133 | + |
| 134 | + |
104 | 135 | if __name__ == "__main__": |
105 | 136 | unittest.main(verbosity=2) |
0 commit comments