-
Notifications
You must be signed in to change notification settings - Fork 28
/
safebrowsing.py
77 lines (53 loc) · 1.9 KB
/
safebrowsing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
#
# Copyright (c) 2016 Jun C. Valdez
# Code is distrubuted under the terms of an MIT style license
# http://www.opensource.org/licenses/mit-license
#
import requests
import json
SB_CLIENT_ID = "Python SafeBrowsing Client"
SB_CLIENT_VER = "0.0.1"
class LookupAPI(object):
def __init__(self, apikey):
self.apiurl = 'https://safebrowsing.googleapis.com/v4/threatMatches:find?key=%s' % (apikey)
self.platform_types = ['ANY_PLATFORM']
self.threat_types = ['THREAT_TYPE_UNSPECIFIED',
'MALWARE',
'SOCIAL_ENGINEERING',
'UNWANTED_SOFTWARE',
'POTENTIALLY_HARMFUL_APPLICATION']
self.threat_entry_types = ['URL']
def set_threat_types(self, threats):
self.threat_types = threats
def set_platform_types(self, platforms):
self.platform_types = platforms
def threat_matches_find(self, *urls):
threat_entries = []
results = {}
for url_ in urls:
url = {'url': url_}
threat_entries.append(url)
reqbody = {
'client': {
'clientId': SB_CLIENT_ID,
'clientVersion': SB_CLIENT_VER
},
'threatInfo': {
'threatTypes': self.threat_types,
'platformTypes': self.platform_types,
'threatEntryTypes': self.threat_entry_types,
'threatEntries': threat_entries
}
}
headers = {'Content-Type': 'application/json'}
r = requests.post(self.apiurl,
data=json.dumps(reqbody),
headers=headers)
#
# need to include exceptions here
#
return r.json()
class UpdateAPI(object):
def __init__(self, apikey):
pass