Beispiel #1
0
 def getIpsFitting(self):
     """Returns a list of ip mongo dict fitting this scope
     Returns:
         A list ip IP dictionnary from mongo db
     """
     mongoInstance = MongoCalendar.getInstance()
     ips = mongoInstance.find("ips", )
     ips_fitting = []
     isdomain = self.isDomain()
     for ip in ips:
         if isdomain:
             my_ip = Utils.performLookUp(self.scope)
             my_domain = self.scope
             ip_isdomain = not Utils.isIp(ip["ip"])
             if ip_isdomain:
                 if my_domain == ip["ip"]:
                     ips_fitting.append(ip)
                 if Scope.isSubDomain(my_domain, ip["ip"]):
                     ips_fitting.append(ip)
             else:
                 if my_ip == ip["ip"]:
                     ips_fitting.append(ip)
         else:
             if Ip.checkIpScope(self.scope, ip["ip"]):
                 ips_fitting.append(ip)
     return ips_fitting
Beispiel #2
0
    def checkDomainFit(cls, waveName, domain):
        """
        Check if a found domain belongs to one of the scope of the given wave.

        Args:
            waveName: The wave id (name) you want to search for a validating scope
            domain: The found domain.

        Returns:
            boolean
        """
        # Checking settings for domain check.
        settings = Settings()
        # get the domain ip so we can search for it in ipv4 range scopes.
        domainIp = Utils.performLookUp(domain)
        mongoInstance = MongoCalendar.getInstance()
        scopesOfWave = mongoInstance.find("scopes", {"wave": waveName})
        for scopeOfWave in scopesOfWave:
            scopeIsANetworkIp = Utils.isNetworkIp(scopeOfWave["scope"])
            if scopeIsANetworkIp:
                if settings.db_settings.get("include_domains_with_ip_in_scope",
                                            False):
                    if Ip.checkIpScope(scopeOfWave["scope"], domainIp):
                        return True
            else:  # If scope is domain
                # check if we include subdomains
                if settings.db_settings.get("include_all_domains", False):
                    return True
                else:
                    splitted_domain = domain.split(".")
                    # Assuring to check only if there is a domain before the tld (.com, .fr ... )
                    topDomainExists = len(splitted_domain) > 2
                    if topDomainExists:
                        if settings.db_settings.get(
                                "include_domains_with_topdomain_in_scope",
                                False):
                            if splitted_domain[1:] == scopeOfWave[
                                    "scope"].split("."):
                                return True
                    if settings.db_settings.get(
                            "include_domains_with_ip_in_scope", False):
                        inRangeDomainIp = Utils.performLookUp(
                            scopeOfWave["scope"])
                        if str(inRangeDomainIp) == str(domainIp):
                            return True
        return False