Example #1
0
    def load_instance_config(self, config):
        """
        Attempt to load the results from the cache. If no cache exists, run a new scan and cache those results
        :param data: configuration data from the settings.py file
        :return: None
        """
        global results

        # remove "/" from network name so we can use it for our cache
        cache_network_name = self.get_config_value("network").replace("/", "-")
        cache_key_name = "NmapDiscovery_%s" % cache_network_name

        # query the cache
        results = cache.get(cache_key_name)

        if results is None:
            print "No results found - performing new scan"
            ps = PortScanner()
            results = ps.scan(hosts=self.get_config_value("network"),
                              arguments="-sP")
            cache.set(cache_key_name, results,
                      int(self.get_config_value("cache_timeout")))

        self.iterator = iter(results["scan"].iteritems())
        return
Example #2
0
def arp_scan(subnet):
    nm = PS()
    retadd = []
    nm.scan(hosts=subnet, arguments="-sn")
    results = nm._scan_result['scan']
    for i in results:
        if results[i]['status']['state'] == "up":
            retadd.append(i)
    return tuple(retadd)
Example #3
0
 def get_endpoint_by_id(self, endpoint_ip):
     """
     for NmapDiscovery, id is always == endpoint_ip
     run a new scan only on that ip. Ignores cache
     :param endpoint_ip:
     :return: endpoint pyobject
     """
     ps = PortScanner()
     r = ps.scan(hosts=endpoint_ip, arguments="-sP")
     print r
     return self.create_endpoint((endpoint_ip, r["scan"][endpoint_ip]))
Example #4
0
def quick_scan(ip):
    nm = PS()
    ports = {}
    nm.scan(hosts=ip, arguments="--open")
    results = nm._scan_result['scan']
    if 'tcp' in results[ip].keys():
        ports['tcp'] = results[ip]['tcp']
        pprint(ports['tcp'])
    if 'udp' in results[ip].keys():
        ports['udp'] = results[ip]['udp']
        pprint(ports['udp'])
    return ports
Example #5
0
class Config():
    """Configuration values. Static object."""
    client = DockerClient('unix://var/run/docker.sock', version='1.37')
    default_nginx_webroot = join(root, 'usr', 'share', 'quick_deployments',
                                 'nginx_default', 'webroot')
    default_nginx_config = join(root, 'usr', 'share', 'quick_deployments',
                                'nginx_default', 'configuration')
    port_scanner = PortScanner()

    @staticmethod
    @strict
    def all_image_tags() -> List[str]:
        """Return a list of all available image tags."""
        tags = []
        for image in Config.client.images.list():
            for tag in image.tags:
                tags.append(tag)
        return tags