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()
()
| 1706 | raise SqlmapMissingDependence(errMsg) |
| 1707 | |
| 1708 | def 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 |
no test coverage detected
searching dependent graphs…