|
4 | 4 | import urllib.parse
|
5 | 5 | import pprint
|
6 | 6 | import pkg_resources
|
| 7 | +import ipaddress |
7 | 8 |
|
8 | 9 | from sys import platform
|
9 | 10 | from typing import Tuple, Type
|
@@ -68,6 +69,7 @@ def __init__(self,
|
68 | 69 | self._scans = self._parse_scan_list(scans) # only the ones we call using `_do_scan()`
|
69 | 70 |
|
70 | 71 | self.scheme, self.subdomain, self.target_hostname = self._parse_target_url(target_url)
|
| 72 | + self.host_is_resolved = self.subdomain is None |
71 | 73 | self._default_general_scanner_args = {
|
72 | 74 | "scheme": self.scheme,
|
73 | 75 | "target_hostname": self.target_hostname,
|
@@ -111,14 +113,19 @@ def _parse_scan_list(self, scan_list: List[str]) -> List[Type[Scanner]]:
|
111 | 113 | scans.append(scanner)
|
112 | 114 | return scans
|
113 | 115 |
|
114 |
| - def _parse_target_url(self, target_url: str) -> Tuple[str, str, str]: |
115 |
| - parsed_target = urllib.parse.urlparse(target_url) |
116 |
| - scheme = parsed_target.scheme |
117 |
| - netloc = parsed_target.netloc |
118 |
| - sub = netloc.split(".")[0] if self._contains_subdomain(target_url) else ScannerDefaultParams.DefaultSubdomain |
119 |
| - hostname = netloc.split(".", 1)[-1] if self._contains_subdomain(target_url) else netloc |
120 |
| - |
121 |
| - return scheme, sub, hostname |
| 116 | + def _parse_target_url(self, target_url: str) -> Tuple[str, Union[str, None], str]: |
| 117 | + try: |
| 118 | + scheme, ip_hostname = target_url.split('://') |
| 119 | + ip_test = ipaddress.ip_address(ip_hostname) # check for valid ip address |
| 120 | + return scheme, None, ip_hostname |
| 121 | + except Exception as exc: # not an IP address |
| 122 | + parsed_target = urllib.parse.urlparse(target_url) |
| 123 | + scheme = parsed_target.scheme |
| 124 | + netloc = parsed_target.netloc |
| 125 | + sub = netloc.split(".")[0] if self._contains_subdomain( |
| 126 | + target_url) else ScannerDefaultParams.DefaultSubdomain |
| 127 | + hostname = netloc.split(".", 1)[-1] if self._contains_subdomain(target_url) else netloc |
| 128 | + return scheme, sub, hostname |
122 | 129 |
|
123 | 130 | def _start_scans_for_target(self, target: str) -> List[threading.Thread]:
|
124 | 131 | scanner_threads = list()
|
@@ -162,6 +169,9 @@ def _setup_targets(self) -> queue.Queue:
|
162 | 169 | domains = queue.Queue()
|
163 | 170 | domains.put(self.target_url)
|
164 | 171 | if self.dns_recursion:
|
| 172 | + if self.host_is_resolved: |
| 173 | + self._log_progress("skipping dns scan, host is resolved...") |
| 174 | + return domains |
165 | 175 | subdomain_scanner.DNSScanner(target_url=self.target_hostname, domains_queue=domains,
|
166 | 176 | **self._generate_scanner_args(DNSScanner.SCAN_NICKNAME)).start_scanner()
|
167 | 177 | return domains
|
@@ -201,8 +211,8 @@ def _get_scanner_name(self, *args, **kwargs) -> str:
|
201 | 211 |
|
202 | 212 |
|
203 | 213 | if __name__ == "__main__":
|
204 |
| - if "linux" not in platform: |
205 |
| - raise UnsupportedOS(platform) |
| 214 | + # if "linux" not in platform: |
| 215 | + # raise UnsupportedOS(platform) |
206 | 216 | with open("requirements.txt", "r") as reqs:
|
207 | 217 | pkg_resources.require(reqs.readlines())
|
208 | 218 |
|
|
0 commit comments