コード例 #1
0
 def run(self, conf, args, plugins):
     sb = SafeBrowsing(conf['SafeBrowsing']['key'])
     if 'subcommand' in args:
         if args.subcommand == 'url':
             try:
                 if args.URL.startswith("http"):
                     res = sb.lookup_url(args.URL)
                 else:
                     res = sb.lookup_url("http://" + args.URL + "/")
             except SafeBrowsingInvalidApiKey:
                 print("Invalid API key!")
                 sys.exit(1)
             except SafeBrowsingWeirdError:
                 print("Weird Error!")
                 sys.exit(1)
             else:
                 if args.json:
                     print(json.dumps(res, sort_keys=True, indent=4))
                 else:
                     if res["malicious"]:
                         print("Malicious: Yes")
                         print("Platforms: %s" %
                               ", ".join(res["platforms"]))
                         print("Threats: %s" % ", ".join(res["threats"]))
                     else:
                         print("Malicious: No")
         elif args.subcommand == 'file':
             with open(args.FILE, 'r') as f:
                 data = f.read()
             domains = [d.strip() for d in data.split()]
             res = sb.lookup_urls([
                 "http://" + d + "/" if not d.startswith("http") else d
                 for d in domains
             ])
             if args.format == "txt":
                 for domain in res:
                     if res[domain]["malicious"]:
                         print("%s\tMalicious" % domain)
                     else:
                         print("%s\tOk" % domain)
             elif args.format == "json":
                 print(json.dumps(res, sort_keys=True, indent=4))
             else:
                 print("Url|Malicious|Threat|Platform")
                 for domain in res:
                     if res[domain]["malicious"]:
                         print("%s|%s|%s|%s" % (domain, "Yes", ",".join(
                             res[domain]["threats"]), ",".join(
                                 res[domain]["platforms"])))
                     else:
                         print("%s|No||" % domain)
         else:
             self.parser.print_help()
     else:
         self.parser.print_help()
コード例 #2
0
ファイル: classifications.py プロジェクト: killvxk/uzen
def google_safe_brwosing_lookup(url: str) -> Optional[dict]:
    """Lookup a url on GSB

    Arguments:
        url {str} -- A URL to lookup

    Returns:
        Optional[dict] -- A lookup result
    """
    key = str(settings.GOOGLE_SAFE_BROWSING_API_KEY)
    if key == "":
        return None

    try:
        s = SafeBrowsing(key)
        return s.lookup_url(url)
    except (SafeBrowsingInvalidApiKey, SafeBrowsingWeirdError):
        pass

    return None
コード例 #3
0
def main():
    key = 'AIzaSyBZUltwuT2ApyBvBi4Yr9BF5gQTNP7nwgI'
    s = SafeBrowsing(key)
    url_list = [
        "malware.testing.google.test/testing/malware/",
        "cpcontacts.loveshackdiy.com", "beta.servicehub.com",
        "webmail.accantobeleza.com.br", "www.1plus1.sk", "www.raypal.com/",
        "lefcm.org", "forfriendsstore.com", "api.atux.com.ar",
        "www.mercercopywriting.co.uk",
        "verkehrspsychologische-untersuchung-schweiz.online",
        "bst-8b6d93ad-79da-40b9-8670-d837428ca3b1.bastion.azure.com",
        "enterprisevineyards.com", "wx.n3uc.com", "vitalbites.us",
        "labradortoscana.it", "entizolab.com", "www.hokkaido-select.com",
        "www.jacklete.ca", "46640.1602746166.cr-gke-boskos-40.cr-e2e.com",
        "web-ssoreporting-test.apps.beta.azure.cp-skoda-auto.com",
        "autodiscover.womanmoneyblog.com"
    ]

    for r in url_list:
        h = s.lookup_url('http://' + r)
        print(h)
コード例 #4
0
def safb(Tester):
    KEY = '<Google Safe Browsing API here>'
    from pysafebrowsing import SafeBrowsing
    s = SafeBrowsing(KEY)
    r = s.lookup_url(Tester)
    print("\nGoogle safe browsing " + str(r))