Skip to content

Commit

Permalink
#594 make analyzer work without giving SHA-1. Crt.sh seems to have ch…
Browse files Browse the repository at this point in the history
…anged JSON results format
  • Loading branch information
jeromeleonard committed Mar 10, 2020
1 parent 6387549 commit 4ea0301
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions analyzers/Crtsh/crtshquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def search(self, domain, wildcard=True):
if wildcard:
url2 = base_url.format("%25{}.".format(domain))
req2 = requests.get(url2, headers={'User-Agent': ua})
if req2.ok:
if req2.ok and not req2.headers['content-type'].startswith('text/html'):
try:
content2 = req2.content.decode('utf-8')
data2 = json.loads(content2.replace('}{', '},{'))
Expand All @@ -58,17 +58,19 @@ def search(self, domain, wildcard=True):
return None

for c in data:
det_url = 'https://crt.sh/?q={}&output=json'.format(c['min_cert_id'])
try:
det_req = requests.get(det_url, headers={'User-Agent': ua})
if det_req.status_code == requests.codes.ok:
det_con = det_req.content.decode('utf-8')
sha1 = re.findall(rex, det_con)[0]
c['sha1'] = sha1
else:
if c.get('min_cert_id'):
det_url = 'https://crt.sh/?q={}&output=json'.format(c['min_cert_id'])
try:
det_req = requests.get(det_url, headers={'User-Agent': ua})
if det_req.status_code == requests.codes.ok:
det_con = det_req.content.decode('utf-8')
sha1 = re.findall(rex, det_con)[0]
c['sha1'] = sha1
else:
c['sha1'] = ''
except:
c['sha1'] = ''
except:
c['sha1'] = ''

return data

def __init__(self):
Expand Down

0 comments on commit 4ea0301

Please sign in to comment.