-
morpheuslord committed with GitHub 1 year ago1 parent 93a66c74
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
Showing first 47 files as there are too many
-
-
vuln_analyzer/lib/python3.11/site-packages/idna/__pycache__/__init__.cpython-311.pycBinary file.
-
vuln_analyzer/lib/python3.11/site-packages/idna/__pycache__/codec.cpython-311.pycBinary file.
-
vuln_analyzer/lib/python3.11/site-packages/idna/__pycache__/compat.cpython-311.pycBinary file.
-
vuln_analyzer/lib/python3.11/site-packages/idna/__pycache__/core.cpython-311.pycBinary file.
-
vuln_analyzer/lib/python3.11/site-packages/idna/__pycache__/idnadata.cpython-311.pycBinary file.
-
vuln_analyzer/lib/python3.11/site-packages/idna/__pycache__/intranges.cpython-311.pycBinary file.
-
vuln_analyzer/lib/python3.11/site-packages/idna/__pycache__/package_data.cpython-311.pycBinary file.
-
vuln_analyzer/lib/python3.11/site-packages/idna/__pycache__/uts46data.cpython-311.pycBinary file.
-
-
-
-
vuln_analyzer/lib/python3.11/site-packages/idna/idnadata.pyDiff is too large to be displayed.
-
-
vuln_analyzer/lib/python3.11/site-packages/idna/uts46data.pyDiff is too large to be displayed.
-
-
-
vuln_analyzer/lib/python3.11/site-packages/multidict/__pycache__/__init__.cpython-311.pycBinary file.
-
vuln_analyzer/lib/python3.11/site-packages/multidict/__pycache__/_abc.cpython-311.pycBinary file.
-
vuln_analyzer/lib/python3.11/site-packages/multidict/__pycache__/_compat.cpython-311.pycBinary file.
-
vuln_analyzer/lib/python3.11/site-packages/multidict/__pycache__/_multidict_base.cpython-311.pycBinary file.
-
vuln_analyzer/lib/python3.11/site-packages/multidict/__pycache__/_multidict_py.cpython-311.pycBinary file.
-
-
-
vuln_analyzer/lib/python3.11/site-packages/multidict/_multidict.cpython-311-x86_64-linux-gnu.soBinary file.
-
-
-
1 + # -*- coding: latin-1 -*- 2 + 3 + """ 4 + python-nmap - 2010.12.17 5 + 6 + python-nmap is a python library which helps in using nmap port scanner. 7 + It allows to easilly manipulate nmap scan results and will be a perfect 8 + tool for systems administrators who want to automatize scanning task 9 + and reports. It also supports nmap script outputs. 10 + 11 + 12 + Author : 13 + 14 + * Alexandre Norman - [email protected] 15 + 16 + Contributors: 17 + 18 + * Steve 'Ashcrow' Milner - [email protected] 19 + * Brian Bustin - brian at bustin.us 20 + * old.schepperhand 21 + * Johan Lundberg 22 + * Thomas D. maaaaz 23 + 24 + Licence : GPL v3 or any later version 25 + 26 + 27 + This program is free software: you can redistribute it and/or modify 28 + it under the terms of the GNU General Public License as published by 29 + the Free Software Foundation, either version 3 of the License, or 30 + any later version. 31 + 32 + This program is distributed in the hope that it will be useful, 33 + but WITHOUT ANY WARRANTY; without even the implied warranty of 34 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 35 + GNU General Public License for more details. 36 + 37 + You should have received a copy of the GNU General Public License 38 + along with this program. If not, see <http://www.gnu.org/licenses/>. 39 + """ 40 + 41 + from .nmap import * # noqa 42 + from .nmap import __author__ # noqa 43 + from .nmap import __version__ # noqa 44 + from .nmap import __last_modification__ # noqa 45 + -
vuln_analyzer/lib/python3.11/site-packages/nmap/__pycache__/__init__.cpython-311.pycBinary file.
-
vuln_analyzer/lib/python3.11/site-packages/nmap/__pycache__/nmap.cpython-311.pycBinary file.
-
vuln_analyzer/lib/python3.11/site-packages/nmap/__pycache__/test_nmap.cpython-311.pycBinary file.
-
1 + #!/usr/bin/env python 2 + # -*- coding: utf-8 -*- 3 + 4 + """ 5 + nmap.py - version and date, see below 6 + 7 + Source code : https://bitbucket.org/xael/python-nmap 8 + 9 + Author : 10 + 11 + * Alexandre Norman - norman at xael.org 12 + 13 + Contributors: 14 + 15 + * Steve 'Ashcrow' Milner - steve at gnulinux.net 16 + * Brian Bustin - brian at bustin.us 17 + * old.schepperhand 18 + * Johan Lundberg 19 + * Thomas D. maaaaz 20 + * Robert Bost 21 + * David Peltier 22 + * Ed Jones 23 + 24 + Licence: GPL v3 or any later version for python-nmap 25 + 26 + 27 + This program is free software: you can redistribute it and/or modify 28 + it under the terms of the GNU General Public License as published by 29 + the Free Software Foundation, either version 3 of the License, or 30 + any later version. 31 + 32 + This program is distributed in the hope that it will be useful, 33 + but WITHOUT ANY WARRANTY; without even the implied warranty of 34 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 35 + GNU General Public License for more details. 36 + 37 + You should have received a copy of the GNU General Public License 38 + along with this program. If not, see <http://www.gnu.org/licenses/>. 39 + 40 + 41 + ************** 42 + IMPORTANT NOTE 43 + ************** 44 + 45 + The Nmap Security Scanner used by python-nmap is distributed 46 + under it's own licence that you can find at https://svn.nmap.org/nmap/COPYING 47 + 48 + Any redistribution of python-nmap along with the Nmap Security Scanner 49 + must conform to the Nmap Security Scanner licence 50 + 51 + """ 52 + import csv 53 + import io 54 + import os 55 + import re 56 + import shlex 57 + import subprocess 58 + import sys 59 + from multiprocessing import Process 60 + from xml.etree import ElementTree as ET 61 + 62 + 63 + __author__ = "Alexandre Norman ([email protected])" 64 + __version__ = "0.7.1" 65 + __last_modification__ = "2021.10.26" 66 + 67 + 68 + ############################################################################ 69 + 70 + 71 + class PortScanner(object): 72 + """ 73 + PortScanner class allows to use nmap from python 74 + 75 + """ 76 + 77 + def __init__( 78 + self, 79 + nmap_search_path=( 80 + "nmap", 81 + "/usr/bin/nmap", 82 + "/usr/local/bin/nmap", 83 + "/sw/bin/nmap", 84 + "/opt/local/bin/nmap", 85 + ), 86 + ): 87 + """ 88 + Initialize PortScanner module 89 + 90 + * detects nmap on the system and nmap version 91 + * may raise PortScannerError exception if nmap is not found in the path 92 + 93 + :param nmap_search_path: tupple of string where to search for nmap executable. 94 + Change this if you want to use a specific version of nmap. 95 + :returns: nothing 96 + 97 + """ 98 + self._nmap_path = "" # nmap path 99 + self._scan_result = {} 100 + self._nmap_version_number = 0 # nmap version number 101 + self._nmap_subversion_number = 0 # nmap subversion number 102 + self._nmap_last_output = "" # last full ascii nmap output 103 + is_nmap_found = False # true if we have found nmap 104 + 105 + self.__process = None 106 + 107 + # regex used to detect nmap (http or https) 108 + regex = re.compile(r"Nmap version [0-9]*\.[0-9]*[^ ]* \( http(|s)://.* \)") 109 + # launch 'nmap -V', we wait after 110 + # > 'Nmap version 5.0 ( http://nmap.org )' 111 + # This is for Mac OSX. When idle3 is launched from the finder, PATH is not set so nmap was not found 112 + for nmap_path in nmap_search_path: 113 + try: 114 + if ( 115 + sys.platform.startswith("freebsd") 116 + or sys.platform.startswith("linux") 117 + or sys.platform.startswith("darwin") 118 + ): 119 + p = subprocess.Popen( 120 + [nmap_path, "-V"], 121 + bufsize=10000, 122 + stdout=subprocess.PIPE, 123 + close_fds=True, 124 + ) 125 + else: 126 + p = subprocess.Popen( 127 + [nmap_path, "-V"], bufsize=10000, stdout=subprocess.PIPE 128 + ) 129 + 130 + except OSError: 131 + pass 132 + else: 133 + self._nmap_path = nmap_path # save path 134 + break 135 + else: 136 + raise PortScannerError( 137 + f"nmap program was not found in path. PATH is : {os.getenv('PATH')}" 138 + ) 139 + 140 + self._nmap_last_output = bytes.decode(p.communicate()[0]) # sav stdout 141 + for line in self._nmap_last_output.split(os.linesep): 142 + if regex.match(line) is not None: 143 + is_nmap_found = True 144 + # Search for version number 145 + regex_version = re.compile("[0-9]+") 146 + regex_subversion = re.compile(r"\.[0-9]+") 147 + 148 + rv = regex_version.search(line) 149 + rsv = regex_subversion.search(line) 150 + 151 + if rv is not None and rsv is not None: 152 + # extract version/subversion 153 + self._nmap_version_number = int(line[rv.start() : rv.end()]) 154 + self._nmap_subversion_number = int( 155 + line[rsv.start() + 1 : rsv.end()] 156 + ) 157 + break 158 + 159 + if not is_nmap_found: 160 + raise PortScannerError("nmap program was not found in path") 161 + 162 + return 163 + 164 + def get_nmap_last_output(self): 165 + """ 166 + Returns the last text output of nmap in raw text 167 + this may be used for debugging purpose 168 + 169 + :returns: string containing the last text output of nmap in raw text 170 + """ 171 + return self._nmap_last_output 172 + 173 + def nmap_version(self): 174 + """ 175 + returns nmap version if detected (int version, int subversion) 176 + or (0, 0) if unknown 177 + :returns: (nmap_version_number, nmap_subversion_number) 178 + """ 179 + return (self._nmap_version_number, self._nmap_subversion_number) 180 + 181 + def listscan(self, hosts="127.0.0.1"): 182 + """ 183 + do not scan but interpret target hosts and return a list a hosts 184 + """ 185 + assert ( 186 + type(hosts) is str 187 + ), f"Wrong type for [hosts], should be a string [was {type(hosts)}]" 188 + output = self.scan(hosts, arguments="-sL") 189 + # Test if host was IPV6 190 + if ( 191 + "scaninfo" in output["nmap"] 192 + and "error" in output["nmap"]["scaninfo"] 193 + and len(output["nmap"]["scaninfo"]["error"]) > 0 194 + and "looks like an IPv6 target specification" 195 + in output["nmap"]["scaninfo"]["error"][0] 196 + ): # noqa 197 + self.scan(hosts, arguments="-sL -6") 198 + 199 + return self.all_hosts() 200 + 201 + def scan( # NOQA: CFQ001, C901 202 + self, hosts="127.0.0.1", ports=None, arguments="-sV", sudo=False, timeout=0 203 + ): 204 + """ 205 + Scan given hosts 206 + 207 + May raise PortScannerError exception if nmap output was not xml 208 + 209 + Test existance of the following key to know 210 + if something went wrong : ['nmap']['scaninfo']['error'] 211 + If not present, everything was ok. 212 + 213 + :param hosts: string for hosts as nmap use it 'scanme.nmap.org' or '198.116.0-255.1-127' or '216.163.128.20/20' 214 + :param ports: string for ports as nmap use it '22,53,110,143-4564' 215 + :param arguments: string of arguments for nmap '-sU -sX -sC' 216 + :param sudo: launch nmap with sudo if True 217 + :param timeout: int, if > zero, will terminate scan after seconds, otherwise will wait indefintely 218 + 219 + :returns: scan_result as dictionnary 220 + """ 221 + if sys.version_info[0] == 2: 222 + assert type(hosts) in ( 223 + str, 224 + ), f"Wrong type for [hosts], should be a string [was {type(hosts)}]" 225 + 226 + assert type(ports) in ( 227 + str, 228 + type(None), 229 + ), f"Wrong type for [ports], should be a string [was {type(ports)}]" 230 + assert type(arguments) in ( 231 + str, 232 + ), f"Wrong type for [arguments], should be a string [was {type(arguments)}]" 233 + else: 234 + assert ( 235 + type(hosts) is str 236 + ), f"Wrong type for [hosts], should be a string [was {type(hosts)}]" 237 + assert type(ports) in ( 238 + str, 239 + type(None), 240 + ), f"Wrong type for [ports], should be a string [was {type(ports)}]" 241 + assert ( 242 + type(arguments) is str 243 + ), f"Wrong type for [arguments], should be a string [was {type(arguments)}]" 244 + 245 + for redirecting_output in ["-oX", "-oA"]: 246 + assert ( 247 + redirecting_output not in arguments 248 + ), "Xml output can't be redirected from command line.\nYou can access it after a scan using:\nnmap.nm.get_nmap_last_output()" # noqa 249 + 250 + h_args = shlex.split(hosts) 251 + f_args = shlex.split(arguments) 252 + 253 + # Launch scan 254 + args = ( 255 + [self._nmap_path, "-oX", "-"] 256 + + h_args 257 + + ["-p", ports] * (ports is not None) 258 + + f_args 259 + ) 260 + if sudo: 261 + args = ["sudo"] + args 262 + 263 + p = subprocess.Popen( 264 + args, 265 + bufsize=100000, 266 + stdin=subprocess.PIPE, 267 + stdout=subprocess.PIPE, 268 + stderr=subprocess.PIPE, 269 + ) 270 + 271 + # wait until finished 272 + # get output 273 + # Terminate after user timeout 274 + if timeout == 0: 275 + (self._nmap_last_output, nmap_err) = p.communicate() 276 + else: 277 + try: 278 + (self._nmap_last_output, nmap_err) = p.communicate(timeout=timeout) 279 + except subprocess.TimeoutExpired: 280 + p.kill() 281 + raise PortScannerTimeout("Timeout from nmap process") 282 + 283 + nmap_err = bytes.decode(nmap_err) 284 + 285 + # If there was something on stderr, there was a problem so abort... in 286 + # fact not always. As stated by AlenLPeacock : 287 + # This actually makes python-nmap mostly unusable on most real-life 288 + # networks -- a particular subnet might have dozens of scannable hosts, 289 + # but if a single one is unreachable or unroutable during the scan, 290 + # nmap.scan() returns nothing. This behavior also diverges significantly 291 + # from commandline nmap, which simply stderrs individual problems but 292 + # keeps on trucking. 293 + 294 + nmap_err_keep_trace = [] 295 + nmap_warn_keep_trace = [] 296 + if len(nmap_err) > 0: 297 + regex_warning = re.compile("^Warning: .*", re.IGNORECASE) 298 + for line in nmap_err.split(os.linesep): 299 + if len(line) > 0: 300 + rgw = regex_warning.search(line) 301 + if rgw is not None: 302 + nmap_warn_keep_trace.append(line + os.linesep) 303 + else: 304 + nmap_err_keep_trace.append(nmap_err) 305 + 306 + return self.analyse_nmap_xml_scan( 307 + nmap_xml_output=self._nmap_last_output, 308 + nmap_err=nmap_err, 309 + nmap_err_keep_trace=nmap_err_keep_trace, 310 + nmap_warn_keep_trace=nmap_warn_keep_trace, 311 + ) 312 + 313 + def analyse_nmap_xml_scan( # NOQA: CFQ001, C901 314 + self, 315 + nmap_xml_output=None, 316 + nmap_err="", 317 + nmap_err_keep_trace="", 318 + nmap_warn_keep_trace="", 319 + ): 320 + """ 321 + Analyses NMAP xml scan ouput 322 + 323 + May raise PortScannerError exception if nmap output was not xml 324 + 325 + Test existance of the following key to know if something went wrong : ['nmap']['scaninfo']['error'] 326 + If not present, everything was ok. 327 + 328 + :param nmap_xml_output: xml string to analyse 329 + :returns: scan_result as dictionnary 330 + """ 331 + 332 + # nmap xml output looks like : 333 + # <host starttime="1267974521" endtime="1267974522"> 334 + # <status state="up" reason="user-set"/> 335 + # <address addr="192.168.1.1" addrtype="ipv4" /> 336 + # <hostnames><hostname name="neufbox" type="PTR" /></hostnames> 337 + # <ports> 338 + # <port protocol="tcp" portid="22"> 339 + # <state state="filtered" reason="no-response" reason_ttl="0"/> 340 + # <service name="ssh" method="table" conf="3" /> 341 + # </port> 342 + # <port protocol="tcp" portid="25"> 343 + # <state state="filtered" reason="no-response" reason_ttl="0"/> 344 + # <service name="smtp" method="table" conf="3" /> 345 + # </port> 346 + # </ports> 347 + # <hostscript> 348 + # <script id="nbstat" output="NetBIOS name: GROSTRUC, NetBIOS user: <unknown>, NetBIOS MAC: <unknown>
" /> # NOQA: E501 349 + # <script id="smb-os-discovery" output=" 
 OS: Unix (Samba 3.6.3)
 Name: WORKGROUP\Unknown
 System time: 2013-06-23 15:37:40 UTC+2
" /> # NOQA: E501 350 + # <script id="smbv2-enabled" output="Server doesn't support SMBv2 protocol" /> 351 + # </hostscript> 352 + # <times srtt="-1" rttvar="-1" to="1000000" /> 353 + # </host> 354 + 355 + # <port protocol="tcp" portid="25"> 356 + # <state state="open" reason="syn-ack" reason_ttl="0"/> 357 + # <service name="smtp" product="Exim smtpd" version="4.76" hostname="grostruc" method="probed" conf="10"> 358 + # <cpe>cpe:/a:exim:exim:4.76</cpe> 359 + # </service> 360 + # <script id="smtp-commands" output="grostruc Hello localhost [127.0.0.1], SIZE 52428800, PIPELINING, HELP, 
 Commands supported: AUTH HELO EHLO MAIL RCPT DATA NOOP QUIT RSET HELP "/> # NOQA: E501 361 + # </port> 362 + 363 + if nmap_xml_output is not None: 364 + self._nmap_last_output = nmap_xml_output 365 + 366 + scan_result = {} 367 + 368 + try: 369 + dom = ET.fromstring(self._nmap_last_output) 370 + except Exception: 371 + if len(nmap_err) > 0: 372 + raise PortScannerError(nmap_err) 373 + else: 374 + raise PortScannerError(self._nmap_last_output) 375 + 376 + # nmap command line 377 + scan_result["nmap"] = { 378 + "command_line": dom.get("args"), 379 + "scaninfo": {}, 380 + "scanstats": { 381 + "timestr": dom.find("runstats/finished").get("timestr"), 382 + "elapsed": dom.find("runstats/finished").get("elapsed"), 383 + "uphosts": dom.find("runstats/hosts").get("up"), 384 + "downhosts": dom.find("runstats/hosts").get("down"), 385 + "totalhosts": dom.find("runstats/hosts").get("total"), 386 + }, 387 + } 388 + 389 + # if there was an error 390 + if len(nmap_err_keep_trace) > 0: 391 + scan_result["nmap"]["scaninfo"]["error"] = nmap_err_keep_trace 392 + 393 + # if there was a warning 394 + if len(nmap_warn_keep_trace) > 0: 395 + scan_result["nmap"]["scaninfo"]["warning"] = nmap_warn_keep_trace 396 + 397 + # info about scan 398 + for dsci in dom.findall("scaninfo"): 399 + scan_result["nmap"]["scaninfo"][dsci.get("protocol")] = { 400 + "method": dsci.get("type"), 401 + "services": dsci.get("services"), 402 + } 403 + 404 + scan_result["scan"] = {} 405 + 406 + for dhost in dom.findall("host"): 407 + # host ip, mac and other addresses 408 + host = None 409 + address_block = {} 410 + vendor_block = {} 411 + for address in dhost.findall("address"): 412 + addtype = address.get("addrtype") 413 + address_block[addtype] = address.get("addr") 414 + if addtype == "ipv4": 415 + host = address_block[addtype] 416 + elif addtype == "mac" and address.get("vendor") is not None: 417 + vendor_block[address_block[addtype]] = address.get("vendor") 418 + 419 + if host is None: 420 + host = dhost.find("address").get("addr") 421 + 422 + hostnames = [] 423 + if len(dhost.findall("hostnames/hostname")) > 0: 424 + for dhostname in dhost.findall("hostnames/hostname"): 425 + hostnames.append( 426 + {"name": dhostname.get("name"), "type": dhostname.get("type")} 427 + ) 428 + else: 429 + hostnames.append({"name": "", "type": ""}) 430 + 431 + scan_result["scan"][host] = PortScannerHostDict({"hostnames": hostnames}) 432 + 433 + scan_result["scan"][host]["addresses"] = address_block 434 + scan_result["scan"][host]["vendor"] = vendor_block 435 + 436 + for dstatus in dhost.findall("status"): 437 + # status : up... 438 + scan_result["scan"][host]["status"] = { 439 + "state": dstatus.get("state"), 440 + "reason": dstatus.get("reason"), 441 + } 442 + for dstatus in dhost.findall("uptime"): 443 + # uptime : seconds, lastboot 444 + scan_result["scan"][host]["uptime"] = { 445 + "seconds": dstatus.get("seconds"), 446 + "lastboot": dstatus.get("lastboot"), 447 + } 448 + for dport in dhost.findall("ports/port"): 449 + # protocol 450 + proto = dport.get("protocol") 451 + # port number converted as integer 452 + port = int(dport.get("portid")) 453 + # state of the port 454 + state = dport.find("state").get("state") 455 + # reason 456 + reason = dport.find("state").get("reason") 457 + # name, product, version, extra info and conf if any 458 + name = product = version = extrainfo = conf = cpe = "" 459 + for dname in dport.findall("service"): 460 + name = dname.get("name") 461 + if dname.get("product"): 462 + product = dname.get("product") 463 + if dname.get("version"): 464 + version = dname.get("version") 465 + if dname.get("extrainfo"): 466 + extrainfo = dname.get("extrainfo") 467 + if dname.get("conf"): 468 + conf = dname.get("conf") 469 + 470 + for dcpe in dname.findall("cpe"): 471 + cpe = dcpe.text 472 + # store everything 473 + if proto not in list(scan_result["scan"][host].keys()): 474 + scan_result["scan"][host][proto] = {} 475 + 476 + scan_result["scan"][host][proto][port] = { 477 + "state": state, 478 + "reason": reason, 479 + "name": name, 480 + "product": product, 481 + "version": version, 482 + "extrainfo": extrainfo, 483 + "conf": conf, 484 + "cpe": cpe, 485 + } 486 + script_id = "" 487 + script_out = "" 488 + # get script output if any 489 + for dscript in dport.findall("script"): 490 + script_id = dscript.get("id") 491 + script_out = dscript.get("output") 492 + if "script" not in list( 493 + scan_result["scan"][host][proto][port].keys() 494 + ): 495 + scan_result["scan"][host][proto][port]["script"] = {} 496 + 497 + scan_result["scan"][host][proto][port]["script"][ 498 + script_id 499 + ] = script_out 500 + 501 + # <hostscript> 502 + # <script id="nbstat" output="NetBIOS name: GROSTRUC, NetBIOS user: <unknown>, NetBIOS MAC: <unknown>
" /> # NOQA: E501 503 + # <script id="smb-os-discovery" output=" 
 OS: Unix (Samba 3.6.3)
 Name: WORKGROUP\Unknown
 System time: 2013-06-23 15:37:40 UTC+2
" /> # NOQA: E501 504 + # <script id="smbv2-enabled" output="Server doesn't support SMBv2 protocol" /> 505 + # </hostscript> 506 + for dhostscript in dhost.findall("hostscript"): 507 + for dname in dhostscript.findall("script"): 508 + hsid = dname.get("id") 509 + hsoutput = dname.get("output") 510 + 511 + if "hostscript" not in list(scan_result["scan"][host].keys()): 512 + scan_result["scan"][host]["hostscript"] = [] 513 + 514 + scan_result["scan"][host]["hostscript"].append( 515 + {"id": hsid, "output": hsoutput} 516 + ) 517 + 518 + # <osmatch name="Juniper SA4000 SSL VPN gateway (IVE OS 7.0)" accuracy="98" line="36241"> 519 + # <osclass type="firewall" vendor="Juniper" osfamily="IVE OS" osgen="7.X" 520 + # accuracy="98"><cpe>cpe:/h:juniper:sa4000</cpe><cpe>cpe:/o:juniper:ive_os:7</cpe></osclass> 521 + # </osmatch> 522 + # <osmatch name="Cymphonix EX550 firewall" accuracy="98" line="17929"> 523 + # <osclass type="firewall" vendor="Cymphonix" osfamily="embedded" 524 + # accuracy="98"><cpe>cpe:/h:cymphonix:ex550</cpe></osclass> 525 + # </osmatch> 526 + for dos in dhost.findall("os"): 527 + osmatch = [] 528 + portused = [] 529 + for dportused in dos.findall("portused"): 530 + # <portused state="open" proto="tcp" portid="443"/> 531 + state = dportused.get("state") 532 + proto = dportused.get("proto") 533 + portid = dportused.get("portid") 534 + portused.append({"state": state, "proto": proto, "portid": portid}) 535 + 536 + scan_result["scan"][host]["portused"] = portused 537 + 538 + for dosmatch in dos.findall("osmatch"): 539 + # <osmatch name="Linux 3.7 - 3.15" accuracy="100" line="52790"> 540 + name = dosmatch.get("name") 541 + accuracy = dosmatch.get("accuracy") 542 + line = dosmatch.get("line") 543 + 544 + osclass = [] 545 + for dosclass in dosmatch.findall("osclass"): 546 + # <osclass type="general purpose" vendor="Linux" osfamily="Linux" osgen="2.6.X" accuracy="98"/> 547 + ostype = dosclass.get("type") 548 + vendor = dosclass.get("vendor") 549 + osfamily = dosclass.get("osfamily") 550 + osgen = dosclass.get("osgen") 551 + accuracy = dosclass.get("accuracy") 552 + 553 + cpe = [] 554 + for dcpe in dosclass.findall("cpe"): 555 + cpe.append(dcpe.text) 556 + 557 + osclass.append( 558 + { 559 + "type": ostype, 560 + "vendor": vendor, 561 + "osfamily": osfamily, 562 + "osgen": osgen, 563 + "accuracy": accuracy, 564 + "cpe": cpe, 565 + } 566 + ) 567 + 568 + osmatch.append( 569 + { 570 + "name": name, 571 + "accuracy": accuracy, 572 + "line": line, 573 + "osclass": osclass, 574 + } 575 + ) 576 + else: 577 + scan_result["scan"][host]["osmatch"] = osmatch 578 + 579 + for dport in dhost.findall("osfingerprint"): 580 + # <osfingerprint fingerprint="OS:SCAN(V=5.50%D=11/[...]S)
"/> 581 + fingerprint = dport.get("fingerprint") 582 + 583 + scan_result["scan"][host]["fingerprint"] = fingerprint 584 + 585 + self._scan_result = scan_result # store for later use 586 + return scan_result 587 + 588 + def __getitem__(self, host): 589 + """ 590 + returns a host detail 591 + """ 592 + if sys.version_info[0] == 2: 593 + assert type(host) in ( 594 + str, 595 + ), f"Wrong type for [host], should be a string [was {type(host)}]" 596 + else: 597 + assert ( 598 + type(host) is str 599 + ), f"Wrong type for [host], should be a string [was {type(host)}]" 600 + return self._scan_result["scan"][host] 601 + 602 + def all_hosts(self): 603 + """ 604 + returns a sorted list of all hosts 605 + """ 606 + if "scan" not in list(self._scan_result.keys()): 607 + return [] 608 + listh = list(self._scan_result["scan"].keys()) 609 + listh.sort() 610 + return listh 611 + 612 + def command_line(self): 613 + """ 614 + returns command line used for the scan 615 + 616 + may raise AssertionError exception if called before scanning 617 + """ 618 + assert "nmap" in self._scan_result, "Do a scan before trying to get result !" 619 + assert ( 620 + "command_line" in self._scan_result["nmap"] 621 + ), "Do a scan before trying to get result !" 622 + 623 + return self._scan_result["nmap"]["command_line"] 624 + 625 + def scaninfo(self): 626 + """ 627 + returns scaninfo structure 628 + {'tcp': {'services': '22', 'method': 'connect'}} 629 + 630 + may raise AssertionError exception if called before scanning 631 + """ 632 + assert "nmap" in self._scan_result, "Do a scan before trying to get result !" 633 + assert ( 634 + "scaninfo" in self._scan_result["nmap"] 635 + ), "Do a scan before trying to get result !" 636 + 637 + return self._scan_result["nmap"]["scaninfo"] 638 + 639 + def scanstats(self): 640 + """ 641 + returns scanstats structure 642 + {'uphosts': '3', 'timestr': 'Thu Jun 3 21:45:07 2010', 'downhosts': '253', 'totalhosts': '256', 'elapsed': '5.79'} # NOQA: E501 643 + 644 + may raise AssertionError exception if called before scanning 645 + """ 646 + assert "nmap" in self._scan_result, "Do a scan before trying to get result !" 647 + assert ( 648 + "scanstats" in self._scan_result["nmap"] 649 + ), "Do a scan before trying to get result !" 650 + 651 + return self._scan_result["nmap"]["scanstats"] 652 + 653 + def has_host(self, host): 654 + """ 655 + returns True if host has result, False otherwise 656 + """ 657 + assert ( 658 + type(host) is str 659 + ), f"Wrong type for [host], should be a string [was {type(host)}]" 660 + assert "scan" in self._scan_result, "Do a scan before trying to get result !" 661 + 662 + if host in list(self._scan_result["scan"].keys()): 663 + return True 664 + 665 + return False 666 + 667 + def csv(self): 668 + """ 669 + returns CSV output as text 670 + 671 + Example : 672 + host;hostname;hostname_type;protocol;port;name;state;product;extrainfo;reason;version;conf;cpe 673 + 127.0.0.1;localhost;PTR;tcp;22;ssh;open;OpenSSH;protocol 2.0;syn-ack;5.9p1 Debian 5ubuntu1;10;cpe 674 + 127.0.0.1;localhost;PTR;tcp;23;telnet;closed;;;conn-refused;;3; 675 + 127.0.0.1;localhost;PTR;tcp;24;priv-mail;closed;;;conn-refused;;3; 676 + """ 677 + assert "scan" in self._scan_result, "Do a scan before trying to get result !" 678 + 679 + if sys.version_info < (3, 0): 680 + fd = io.BytesIO() 681 + else: 682 + fd = io.StringIO() 683 + 684 + csv_ouput = csv.writer(fd, delimiter=";") 685 + csv_header = [ 686 + "host", 687 + "hostname", 688 + "hostname_type", 689 + "protocol", 690 + "port", 691 + "name", 692 + "state", 693 + "product", 694 + "extrainfo", 695 + "reason", 696 + "version", 697 + "conf", 698 + "cpe", 699 + ] 700 + 701 + csv_ouput.writerow(csv_header) 702 + 703 + for host in self.all_hosts(): 704 + for proto in self[host].all_protocols(): 705 + if proto not in ["tcp", "udp"]: 706 + continue 707 + lport = list(self[host][proto].keys()) 708 + lport.sort() 709 + for port in lport: 710 + hostname = "" 711 + for h in self[host]["hostnames"]: 712 + hostname = h["name"] 713 + hostname_type = h["type"] 714 + csv_row = [ 715 + host, 716 + hostname, 717 + hostname_type, 718 + proto, 719 + port, 720 + self[host][proto][port]["name"], 721 + self[host][proto][port]["state"], 722 + self[host][proto][port]["product"], 723 + self[host][proto][port]["extrainfo"], 724 + self[host][proto][port]["reason"], 725 + self[host][proto][port]["version"], 726 + self[host][proto][port]["conf"], 727 + self[host][proto][port]["cpe"], 728 + ] 729 + csv_ouput.writerow(csv_row) 730 + 731 + return fd.getvalue() 732 + 733 + 734 + ############################################################################ 735 + 736 + 737 + def __scan_progressive__( # NOQA: CFQ002 738 + self, hosts, ports, arguments, callback, sudo, timeout 739 + ): 740 + """ 741 + Used by PortScannerAsync for callback 742 + """ 743 + for host in self._nm.listscan(hosts): 744 + try: 745 + scan_data = self._nm.scan(host, ports, arguments, sudo, timeout) 746 + except PortScannerError: 747 + scan_data = None 748 + 749 + if callback is not None: 750 + callback(host, scan_data) 751 + return 752 + 753 + 754 + ############################################################################ 755 + 756 + 757 + class PortScannerAsync(object): 758 + """ 759 + PortScannerAsync allows to use nmap from python asynchronously 760 + for each host scanned, callback is called with scan result for the host 761 + 762 + """ 763 + 764 + def __init__(self): 765 + """ 766 + Initialize the module 767 + 768 + * detects nmap on the system and nmap version 769 + * may raise PortScannerError exception if nmap is not found in the path 770 + 771 + """ 772 + self._process = None 773 + self._nm = PortScanner() 774 + return 775 + 776 + def __del__(self): 777 + """ 778 + Cleanup when deleted 779 + 780 + """ 781 + if self._process is not None: 782 + try: 783 + if self._process.is_alive(): 784 + self._process.terminate() 785 + except AssertionError: 786 + # Happens on python3.4 787 + # when using PortScannerAsync twice in a row 788 + pass 789 + 790 + self._process = None 791 + return 792 + 793 + def scan( # NOQA: CFQ002 794 + self, 795 + hosts="127.0.0.1", 796 + ports=None, 797 + arguments="-sV", 798 + callback=None, 799 + sudo=False, 800 + timeout=0, 801 + ): 802 + """ 803 + Scan given hosts in a separate process and return host by host result using callback function 804 + 805 + PortScannerError exception from standard nmap is catched and you won't know about but get None as scan_data 806 + 807 + :param hosts: string for hosts as nmap use it 'scanme.nmap.org' or '198.116.0-255.1-127' or '216.163.128.20/20' 808 + :param ports: string for ports as nmap use it '22,53,110,143-4564' 809 + :param arguments: string of arguments for nmap '-sU -sX -sC' 810 + :param callback: callback function which takes (host, scan_data) as arguments 811 + :param sudo: launch nmap with sudo if true 812 + :param timeout: int, if > zero, will terminate scan after seconds, otherwise will wait indefintely 813 + 814 + """ 815 + 816 + if sys.version_info[0] == 2: 817 + assert type(hosts) in ( 818 + str, 819 + ), f"Wrong type for [hosts], should be a string [was {type(hosts)}]" 820 + assert type(ports) in ( 821 + str, 822 + type(None), 823 + ), f"Wrong type for [ports], should be a string [was {type(ports)}]" 824 + assert type(arguments) in ( 825 + str, 826 + ), f"Wrong type for [arguments], should be a string [was {type(arguments)}]" 827 + else: 828 + assert ( 829 + type(hosts) is str 830 + ), f"Wrong type for [hosts], should be a string [was {type(hosts)}]" 831 + assert type(ports) in ( 832 + str, 833 + type(None), 834 + ), f"Wrong type for [ports], should be a string [was {type(ports)}]" 835 + assert ( 836 + type(arguments) is str 837 + ), f"Wrong type for [arguments], should be a string [was {type(arguments)}]" 838 + 839 + assert ( 840 + callable(callback) or callback is None 841 + ), f"The [callback] {str(callback)} should be callable or None." 842 + 843 + for redirecting_output in ["-oX", "-oA"]: 844 + assert ( 845 + redirecting_output not in arguments 846 + ), "Xml output can't be redirected from command line.\nYou can access it after a scan using:\nnmap.nm.get_nmap_last_output()" # NOQA: E501 847 + 848 + self._process = Process( 849 + target=__scan_progressive__, 850 + args=(self, hosts, ports, arguments, callback, sudo, timeout), 851 + ) 852 + self._process.daemon = True 853 + self._process.start() 854 + return 855 + 856 + def stop(self): 857 + """ 858 + Stop the current scan process 859 + 860 + """ 861 + if self._process is not None: 862 + self._process.terminate() 863 + return 864 + 865 + def wait(self, timeout=None): 866 + """ 867 + Wait for the current scan process to finish, or timeout 868 + 869 + :param timeout: default = None, wait timeout seconds 870 + 871 + """ 872 + assert type(timeout) in ( 873 + int, 874 + type(None), 875 + ), f"Wrong type for [timeout], should be an int or None [was {type(timeout)}]" 876 + 877 + self._process.join(timeout) 878 + return 879 + 880 + def still_scanning(self): 881 + """ 882 + :returns: True if a scan is currently running, False otherwise 883 + 884 + """ 885 + try: 886 + return self._process.is_alive() 887 + except Exception: 888 + return False 889 + 890 + 891 + ############################################################################ 892 + 893 + 894 + class PortScannerYield(PortScannerAsync): 895 + """ 896 + PortScannerYield allows to use nmap from python with a generator 897 + for each host scanned, yield is called with scan result for the host 898 + 899 + """ 900 + 901 + def __init__(self): 902 + """ 903 + Initialize the module 904 + 905 + * detects nmap on the system and nmap version 906 + * may raise PortScannerError exception if nmap is not found in the path 907 + 908 + """ 909 + PortScannerAsync.__init__(self) 910 + return 911 + 912 + def scan( 913 + self, hosts="127.0.0.1", ports=None, arguments="-sV", sudo=False, timeout=0 914 + ): 915 + """ 916 + Scan given hosts in a separate process and return host by host result using callback function 917 + 918 + PortScannerError exception from standard nmap is catched and you won't know about it 919 + 920 + :param hosts: string for hosts as nmap use it 'scanme.nmap.org' or '198.116.0-255.1-127' or '216.163.128.20/20' 921 + :param ports: string for ports as nmap use it '22,53,110,143-4564' 922 + :param arguments: string of arguments for nmap '-sU -sX -sC' 923 + :param callback: callback function which takes (host, scan_data) as arguments 924 + :param sudo: launch nmap with sudo if true 925 + :param timeout: int, if > zero, will terminate scan after seconds, otherwise will wait indefintely 926 + 927 + """ 928 + 929 + assert ( 930 + type(hosts) is str 931 + ), f"Wrong type for [hosts], should be a string [was {type(hosts)}]" 932 + assert type(ports) in ( 933 + str, 934 + type(None), 935 + ), f"Wrong type for [ports], should be a string [was {type(ports)}]" 936 + assert ( 937 + type(arguments) is str 938 + ), f"Wrong type for [arguments], should be a string [was {type(arguments)}]" 939 + 940 + for redirecting_output in ["-oX", "-oA"]: 941 + assert ( 942 + redirecting_output not in arguments 943 + ), "Xml output can't be redirected from command line.\nYou can access it after a scan using:\nnmap.nm.get_nmap_last_output()" # NOQA: E501 944 + 945 + for host in self._nm.listscan(hosts): 946 + try: 947 + scan_data = self._nm.scan(host, ports, arguments, sudo, timeout) 948 + except PortScannerError: 949 + scan_data = None 950 + yield (host, scan_data) 951 + return 952 + 953 + def stop(self): 954 + pass 955 + 956 + def wait(self, timeout=None): 957 + pass 958 + 959 + def still_scanning(self): 960 + pass 961 + 962 + 963 + ############################################################################ 964 + 965 + 966 + class PortScannerHostDict(dict): 967 + """ 968 + Special dictionnary class for storing and accessing host scan result 969 + 970 + """ 971 + 972 + def hostnames(self): 973 + """ 974 + :returns: list of hostnames 975 + 976 + """ 977 + return self["hostnames"] 978 + 979 + def hostname(self): 980 + """ 981 + For compatibility purpose... 982 + :returns: try to return the user record or the first hostname of the list hostnames 983 + 984 + """ 985 + hostname = "" 986 + for h in self["hostnames"]: 987 + if h["type"] == "user": 988 + return h["name"] 989 + else: 990 + if len(self["hostnames"]) > 0 and "name" in self["hostnames"][0]: 991 + return self["hostnames"][0]["name"] 992 + else: 993 + return "" 994 + 995 + return hostname 996 + 997 + def state(self): 998 + """ 999 + :returns: host state 1000 + 1001 + """ 1002 + return self["status"]["state"] 1003 + 1004 + def uptime(self): 1005 + """ 1006 + :returns: host state 1007 + 1008 + """ 1009 + return self["uptime"] 1010 + 1011 + def all_protocols(self): 1012 + """ 1013 + :returns: a list of all scanned protocols 1014 + 1015 + """ 1016 + 1017 + def _proto_filter(x): 1018 + return x in ["ip", "tcp", "udp", "sctp"] 1019 + 1020 + lp = list(filter(_proto_filter, list(self.keys()))) 1021 + lp.sort() 1022 + return lp 1023 + 1024 + def all_tcp(self): 1025 + """ 1026 + :returns: list of tcp ports 1027 + 1028 + """ 1029 + if "tcp" in list(self.keys()): 1030 + ltcp = list(self["tcp"].keys()) 1031 + ltcp.sort() 1032 + return ltcp 1033 + return [] 1034 + 1035 + def has_tcp(self, port): 1036 + """ 1037 + :param port: (int) tcp port 1038 + :returns: True if tcp port has info, False otherwise 1039 + 1040 + """ 1041 + assert ( 1042 + type(port) is int 1043 + ), f"Wrong type for [port], should be an int [was {type(port)}]" 1044 + 1045 + if "tcp" in list(self.keys()) and port in list(self["tcp"].keys()): 1046 + return True 1047 + return False 1048 + 1049 + def tcp(self, port): 1050 + """ 1051 + :param port: (int) tcp port 1052 + :returns: info for tpc port 1053 + 1054 + """ 1055 + assert ( 1056 + type(port) is int 1057 + ), f"Wrong type for [port], should be an int [was {type(port)}]" 1058 + return self["tcp"][port] 1059 + 1060 + def all_udp(self): 1061 + """ 1062 + :returns: list of udp ports 1063 + 1064 + """ 1065 + if "udp" in list(self.keys()): 1066 + ludp = list(self["udp"].keys()) 1067 + ludp.sort() 1068 + return ludp 1069 + return [] 1070 + 1071 + def has_udp(self, port): 1072 + """ 1073 + :param port: (int) udp port 1074 + :returns: True if udp port has info, False otherwise 1075 + 1076 + """ 1077 + assert ( 1078 + type(port) is int 1079 + ), f"Wrong type for [port], should be an int [was {type(port)}]" 1080 + 1081 + if "udp" in list(self.keys()) and "port" in list(self["udp"].keys()): 1082 + return True 1083 + return False 1084 + 1085 + def udp(self, port): 1086 + """ 1087 + :param port: (int) udp port 1088 + :returns: info for udp port 1089 + 1090 + """ 1091 + assert ( 1092 + type(port) is int 1093 + ), f"Wrong type for [port], should be an int [was {type(port)}]" 1094 + 1095 + return self["udp"][port] 1096 + 1097 + def all_ip(self): 1098 + """ 1099 + :returns: list of ip ports 1100 + 1101 + """ 1102 + if "ip" in list(self.keys()): 1103 + lip = list(self["ip"].keys()) 1104 + lip.sort() 1105 + return lip 1106 + return [] 1107 + 1108 + def has_ip(self, port): 1109 + """ 1110 + :param port: (int) ip port 1111 + :returns: True if ip port has info, False otherwise 1112 + 1113 + """ 1114 + assert ( 1115 + type(port) is int 1116 + ), f"Wrong type for [port], should be an int [was {type(port)}]" 1117 + 1118 + if "ip" in list(self.keys()) and port in list(self["ip"].keys()): 1119 + return True 1120 + return False 1121 + 1122 + def ip(self, port): 1123 + """ 1124 + :param port: (int) ip port 1125 + :returns: info for ip port 1126 + 1127 + """ 1128 + assert ( 1129 + type(port) is int 1130 + ), f"Wrong type for [port], should be an int [was {type(port)}]" 1131 + 1132 + return self["ip"][port] 1133 + 1134 + def all_sctp(self): 1135 + """ 1136 + :returns: list of sctp ports 1137 + 1138 + """ 1139 + if "sctp" in list(self.keys()): 1140 + lsctp = list(self["sctp"].keys()) 1141 + lsctp.sort() 1142 + return lsctp 1143 + return [] 1144 + 1145 + def has_sctp(self, port): 1146 + """ 1147 + :returns: True if sctp port has info, False otherwise 1148 + 1149 + """ 1150 + assert ( 1151 + type(port) is int 1152 + ), f"Wrong type for [port], should be an int [was {type(port)}]" 1153 + 1154 + if "sctp" in list(self.keys()) and port in list(self["sctp"].keys()): 1155 + return True 1156 + return False 1157 + 1158 + def sctp(self, port): 1159 + """ 1160 + :returns: info for sctp port 1161 + 1162 + """ 1163 + assert ( 1164 + type(port) is int 1165 + ), f"Wrong type for [port], should be an int [was {type(port)}]" 1166 + 1167 + return self["sctp"][port] 1168 + 1169 + 1170 + ############################################################################ 1171 + 1172 + 1173 + class PortScannerError(Exception): 1174 + """ 1175 + Exception error class for PortScanner class 1176 + 1177 + """ 1178 + 1179 + def __init__(self, value): 1180 + self.value = value 1181 + 1182 + def __str__(self): 1183 + return repr(self.value) 1184 + 1185 + def __repr__(self): 1186 + return f"PortScannerError exception {self.value}" 1187 + 1188 + 1189 + class PortScannerTimeout(PortScannerError): 1190 + pass 1191 + 1192 + 1193 + ############################################################################ 1194 + 1195 + 1196 + def __get_last_online_version(): 1197 + """ 1198 + Gets last python-nmap published version 1199 + 1200 + WARNING : it does an http connection to http://xael.org/pages/python-nmap/python-nmap_CURRENT_VERSION.txt 1201 + 1202 + :returns: a string which indicate last published version (example :'0.4.3') 1203 + 1204 + """ 1205 + import http.client 1206 + 1207 + conn = http.client.HTTPConnection("xael.org") 1208 + conn.request("GET", "/pages/python-nmap/python-nmap_CURRENT_VERSION.txt") 1209 + online_version = bytes.decode(conn.getresponse().read()).strip() 1210 + return online_version 1211 + 1212 + 1213 + ############################################################################ 1214 + 1215 + 1216 + def convert_nmap_output_to_encoding(value, code="ascii"): 1217 + """ 1218 + Change encoding for scan_result object from unicode to whatever 1219 + 1220 + :param value: scan_result as dictionnary 1221 + :param code: default = "ascii", encoding destination 1222 + 1223 + :returns: scan_result as dictionnary with new encoding 1224 + """ 1225 + new_value = {} 1226 + for k in value: 1227 + if type(value[k]) in [dict, PortScannerHostDict]: 1228 + new_value[k] = convert_nmap_output_to_encoding(value[k], code) 1229 + else: 1230 + if type(value[k]) is list: 1231 + new_value[k] = [ 1232 + convert_nmap_output_to_encoding(x, code) for x in value[k] 1233 + ] 1234 + else: 1235 + new_value[k] = value[k].encode(code) 1236 + return new_value 1237 + 1238 + 1239 + # <EOF>###################################################################### 1240 + -
-
-
vuln_analyzer/lib/python3.11/site-packages/yarl/__pycache__/__init__.cpython-311.pycBinary file.
-
vuln_analyzer/lib/python3.11/site-packages/yarl/__pycache__/_quoting.cpython-311.pycBinary file.
-
vuln_analyzer/lib/python3.11/site-packages/yarl/__pycache__/_quoting_py.cpython-311.pycBinary file.
-
vuln_analyzer/lib/python3.11/site-packages/yarl/__pycache__/_url.cpython-311.pycBinary file.
-
-
vuln_analyzer/lib/python3.11/site-packages/yarl/_quoting_c.cpython-311-x86_64-linux-gnu.soBinary file.
-
-
-