Example #1
0
    def get_urls(self):
        """Extract all URLs embedded in this file through a simple regex."""
        if not os.path.getsize(self.file_path):
            return []

        # http://stackoverflow.com/a/454589
        urls, f = set(), open(self.file_path, "rb")
        for url in re.findall(URL_REGEX, self.mmap(f.fileno())):
            if not is_whitelisted_domain(url[1]):
                urls.add("".join(url))
        return list(urls)
Example #2
0
    def get_urls(self):
        """Extract all URLs embedded in this file through a simple regex."""
        if not os.path.getsize(self.file_path):
            return []

        # http://stackoverflow.com/a/454589
        urls, f = set(), open(self.file_path, "rb")
        for url in re.findall(URL_REGEX, self.mmap(f.fileno())):
            if not is_whitelisted_domain(url[1]):
                urls.add("".join(url))
        return list(urls)
Example #3
0
    def _is_whitelisted(self, conn, hostname):
        """Checks if whitelisting conditions are met"""
        # Is whitelistng enabled?
        if not self.whitelist_enabled:
            return False

        # Is DNS recording coming from allowed NS server.
        if not self.known_dns:
            pass
        elif (conn.get("src") in self.known_dns or
              conn.get("dst") in self.known_dns):
            pass
        else:
            return False

        # Is hostname whitelisted.
        if not is_whitelisted_domain(hostname):
            return False

        return True
Example #4
0
    def _is_whitelisted(self, conn, hostname):
        """Checks if whitelisting conditions are met"""
        # Is whitelistng enabled?
        if not self.whitelist_enabled:
            return False

        # Is DNS recording coming from allowed NS server.
        if not self.known_dns:
            pass
        elif (conn.get("src") in self.known_dns
              or conn.get("dst") in self.known_dns):
            pass
        else:
            return False

        # Is hostname whitelisted.
        if not is_whitelisted_domain(hostname):
            return False

        return True
Example #5
0
def test_is_whitelisted_domain():
    assert is_whitelisted_domain("java.com") is True
    assert is_whitelisted_domain("java2.com") is False
    assert is_whitelisted_domain("crl.microsoft.com") is True
Example #6
0
def test_is_whitelisted_domain():
    assert is_whitelisted_domain("java.com") is True
    assert is_whitelisted_domain("java2.com") is False
    assert is_whitelisted_domain("crl.microsoft.com") is True