예제 #1
0
    async def _get_nodes(self, url: str) -> set:
        """
        Get nodes from Topdis

        Returns:
            set of unique nodes (Node object)

        """
        url = '{0}/{1}'.format(self.api, url)
        resource = await HTTPClient.instance().get(url)

        nodes_cfg = ujson.loads(resource.body)

        timestamp = parse_time_to_timestamp(nodes_cfg['meta']['requestTime'])
        ip_node = {}

        for node_struct in nodes_cfg['nodes']:
            for node_ip in node_struct['ips']:
                node = Node(ip=ipaddress.ip_address(node_ip),
                            node_id=node_struct['id'])
                node.name = node_struct['displayName']
                node.scan = Scan(start=timestamp)

                software = node_struct.get('software', {})
                os = software.get('os', {})

                if os.get('discoveryType') in (
                        TopisOSDiscoveryType.DIRECT.value, ):
                    node.os.name, node.os.version = os.get('name'), os.get(
                        'version')

                    try:
                        node.os.cpe = Service.build_cpe(
                            product=node.os.name,
                            version=node.os.version,
                            part=CPEType.OS)
                    except:
                        node.os.cpe = None
                ip_node[node.ip] = node

        nodes = set(ip_node.values())

        log.debug('Got %i nodes from topdis', len(nodes))
        return nodes
예제 #2
0
 def setUp(self):
     super(PortScanTest, self).setUp()
     cfg = {
         'portdetection': {
             'tcp': {
                 'ports': {
                     'include': ['55'],
                     'exclude': [],
                 },
                 'scan_rate': 1030,
                 'host_timeout': '600'
             },
             'udp': {
                 'ports': {
                     'include': [],
                     'exclude': []
                 },
                 'scan_rate': 30,
                 'defeat_icmp_ratelimit': False,
                 'max_retries': 77
             },
             '_internal': {
                 'udp_retries': 2
             }
         },
         'tools': {
             'nmap': {
                 'cmd': 'nmap',
                 'scripts_dir': '',
             }
         }
     }
     self.cfg = cfg
     self.kudu_queue = MagicMock()
     self.scanner = PortsScan(ipv6=True, tcp=True, udp=False)
     node = Node(ip=ipaddress.ip_address('192.168.1.5'), node_id=None)
     node.scan = Scan()
     self.nodes = [node]