Skip to content

Fix multi-colon port parsing in target URLs and proxy URIs - #6199

Closed
sakhi383 wants to merge 1 commit into
sqlmapproject:masterfrom
sakhi383:fix/target-and-proxy-multi-colon-ports
Closed

sakhi383 wants to merge 1 commit into
sqlmapproject:masterfrom
sakhi383:fix/target-and-proxy-multi-colon-ports

Conversation

@sakhi383

@sakhi383 sakhi383 commented Dec 5, 2026

Copy link
Copy Markdown

Summary

Resolves silent misparsing and acceptance of malformed multi-colon ports (e.g., :80:90, :8443:9000, :1080:90) in parseTargetUrl() and _setHTTPHandlers().

Root Cause

  • lib/core/common.py (parseTargetUrl): Non-IPv6 netloc values were split with netloc.split(:). For inputs like http://example.com:80:90/path, this produced 3 segments, failed len(hostnamePort) == 2, skipped port validation, and silently fell back to the scheme default port (80 / 443) while leaving the url value inconsistent with the fallback.
  • lib/core/option.py (_setHTTPHandlers): Proxy host:port extraction used .rsplit(:, 1), which parsed 127.0.0.1:80:90 as hostname 127.0.0.1:80 and port 90 (or [::1]:80:90 as hostname [::1]:80 and port 90), bypassing port validation and passing malformed proxy addresses downstream. It also split inside unbracketed/bare IPv6 hosts without bracket handling.

Changes

  • Updated parseTargetUrl() in lib/core/common.py to split non-IPv6 netloc values at the first colon (netloc.split(:, 1)), matching the existing IPv6 maxsplit=1 branch so extra colons in the port fail numeric/range validation with SqlmapSyntaxException.
  • Updated _setHTTPHandlers() in lib/core/option.py to use the same bracket-aware host:port split (hostPort.split(:, 1) for non-IPv6 and re.split(r(?<=\]):, hostPort, maxsplit=1) for bracketed IPv6).
  • Added regression tests in tests/test_targeturl.py and tests/test_option.py covering multi-colon HTTP/HTTPS/WS/WSS target URLs, userinfo + malformed ports, multi-colon HTTP/SOCKS5 proxies (IPv4 and bracketed IPv6), missing IPv6 proxy ports, and valid IPv6 proxies with credentials.

Verification

  • Verified new regression tests fail against unpatched master (4 failures in test_targeturl / test_option).
  • Ran python -B -m unittest tests.test_targeturl tests.test_option tests.test_target_parsing tests.test_urls tests.test_common -> Ran 476 tests in 0.901s / OK.
  • Ran python -m pyflakes lib/core/common.py lib/core/option.py tests/test_targeturl.py tests/test_option.py -> clean (exit 0).
  • Ran python -B sqlmap.py --payload-lint -> PASSED (51,041 payloads across 31/31 DBMSes checked, 0 malformed).
  • Ran python -B extra/esperanto/run.py --self-test -> SELF-TEST PASSED.

Split non-IPv6 host:port values at the first colon in parseTargetUrl() and _setHTTPHandlers() so malformed ports like ':80:90' are rejected with SqlmapSyntaxException instead of silently falling back to default ports or passing through as proxy addresses.
@stamparm

stamparm commented Dec 6, 2026

Copy link
Copy Markdown
Member

Thanks, but closing — this only affects malformed input (host:80:90) that doesn't occur in real use. Not worth the extra code/tests.

@stamparm stamparm closed this Dec 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants