From 19d0ac81fbe289cf798c173d07a48b5fb36c09fd Mon Sep 17 00:00:00 2001 From: Robert Wallhead Date: Thu, 5 Oct 2017 21:18:28 +1100 Subject: [PATCH] Fixed safe browsing API after change by Google --- dnstwister/api/checks/safebrowsing.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/dnstwister/api/checks/safebrowsing.py b/dnstwister/api/checks/safebrowsing.py index 2df5df68..f81aa432 100644 --- a/dnstwister/api/checks/safebrowsing.py +++ b/dnstwister/api/checks/safebrowsing.py @@ -4,7 +4,7 @@ import requests -API_URL = 'https://www.google.com/safebrowsing/diagnostic' +API_URL = 'https://www.google.com/transparencyreport/api/v3/safebrowsing/status' def get_report(domain): @@ -15,17 +15,22 @@ def get_report(domain): Returns a count of matches. """ data = { - 'output': 'jsonp', 'site': domain } result = requests.get(API_URL, params=data) - json_result = json.loads(re.search(r'({.*})', result.text).groups()[0]) + result_array = re.search( + r'(\["sb.ssr".*\])', + result.text, + flags=re.MULTILINE).groups()[0] - status = json_result['website']['malwareListStatus'] + payload = r'{{"result": {}}}'.format( + result_array + ) - if status == 'unlisted': + # TODO: Work out detailed meaning of these values. + if json.loads(payload)['result'][2:-1] == [0, 0, 0, 0, 0, 0]: return 0 return 1