MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / parseTargetUrl

Function parseTargetUrl

lib/core/common.py:1708–1810  ·  view source on GitHub ↗

Parse target URL and set some attributes into the configuration singleton >>> pushValue(conf.url) >>> conf.url = "https://www.test.com/?id=1" >>> parseTargetUrl() >>> conf.hostname 'www.test.com' >>> conf.scheme 'https' >>> conf.url = popValue()

()

Source from the content-addressed store, hash-verified

1706 raise SqlmapMissingDependence(errMsg)
1707
1708def parseTargetUrl():
1709 """
1710 Parse target URL and set some attributes into the configuration singleton
1711
1712 >>> pushValue(conf.url)
1713 >>> conf.url = "https://www.test.com/?id=1"
1714 >>> parseTargetUrl()
1715 >>> conf.hostname
1716 'www.test.com'
1717 >>> conf.scheme
1718 'https'
1719 >>> conf.url = popValue()
1720 """
1721
1722 if not conf.url:
1723 return
1724
1725 originalUrl = conf.url
1726
1727 if re.search(r"://\[.+\]", conf.url) and not socket.has_ipv6:
1728 errMsg = "IPv6 communication is not supported "
1729 errMsg += "on this platform"
1730 raise SqlmapGenericException(errMsg)
1731
1732 if not re.search(r"^(http|ws)s?://", conf.url, re.I):
1733 if re.search(r":443\b", conf.url):
1734 conf.url = "https://%s" % conf.url
1735 else:
1736 conf.url = "http://%s" % conf.url
1737
1738 if kb.customInjectionMark in conf.url:
1739 conf.url = conf.url.replace('?', URI_QUESTION_MARKER)
1740
1741 try:
1742 urlSplit = _urllib.parse.urlsplit(conf.url)
1743 except ValueError as ex:
1744 errMsg = "invalid URL '%s' has been given ('%s'). " % (conf.url, getSafeExString(ex))
1745 errMsg += "Please be sure that you don't have any leftover characters (e.g. '[' or ']') "
1746 errMsg += "in the hostname part"
1747 raise SqlmapGenericException(errMsg)
1748
1749 hostnamePort = urlSplit.netloc.split(":") if not re.search(r"\[.+\]", urlSplit.netloc) else filterNone((re.search(r"\[.+\]", urlSplit.netloc).group(0), re.search(r"\](:(?P<port>\d+))?", urlSplit.netloc).group("port")))
1750
1751 conf.scheme = (urlSplit.scheme.strip().lower() or "http")
1752 conf.path = urlSplit.path.strip()
1753 conf.hostname = hostnamePort[0].strip()
1754
1755 if conf.forceSSL:
1756 conf.scheme = re.sub(r"(?i)\A(http|ws)\Z", r"\g<1>s", conf.scheme)
1757
1758 conf.ipv6 = conf.hostname != conf.hostname.strip("[]")
1759 conf.hostname = conf.hostname.strip("[]").replace(kb.customInjectionMark, "")
1760
1761 try:
1762 conf.hostname.encode("idna")
1763 conf.hostname.encode(UNICODE_ENCODING)
1764 except (LookupError, UnicodeError):
1765 invalid = True

Callers 1

startFunction · 0.90

Calls 13

getUnicodeFunction · 0.90
urldecodeFunction · 0.85
intersectFunction · 0.85
getHostHeaderFunction · 0.85
debugMethod · 0.80
getSafeExStringFunction · 0.70
filterNoneFunction · 0.70
urlencodeFunction · 0.70
searchMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…