Skip to content

Commit

Permalink
Merge pull request #337 from lalalashenle/master
Browse files Browse the repository at this point in the history
修改censys api地址以及对应的调用逻辑
  • Loading branch information
shmilylty authored Aug 29, 2024
2 parents 9ecfda2 b5de606 commit 4febfae
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions modules/certificates/censys_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 9,7 @@ def __init__(self, domain):
self.domain = domain
self.module = 'Certificate'
self.source = "CensysAPIQuery"
self.addr = 'https://search.censys.io/api/v1/search/certificates'
self.addr = 'https://search.censys.io/api/v2/certificates/search'
self.id = settings.censys_api_id
self.secret = settings.censys_api_secret
self.delay = 3.0 # Censys 接口查询速率限制 最快2.5秒查1次
Expand All @@ -20,26 20,30 @@ def query(self):
"""
self.header = self.get_header()
self.proxy = self.get_proxy(self.source)
data = {
'query': f'parsed.names: {self.domain}',
'page': 1,
'fields': ['parsed.subject_dn', 'parsed.names'],
'flatten': True}
resp = self.post(self.addr, json=data, auth=(self.id, self.secret))
params = {
'q': f'names: {self.domain}',
'per_page': 100,
}
resp = self.get(self.addr, params=params, auth=(self.id, self.secret))
if not resp:
return
json = resp.json()
status = json.get('status')
if status != 'ok':
if status != 'OK':
logger.log('ALERT', f'{self.source} module {status}')
return
subdomains = self.match_subdomains(resp.text)
self.subdomains.update(subdomains)
pages = json.get('metadata').get('pages')
for page in range(2, pages 1):
data['page'] = page
resp = self.post(self.addr, json=data, auth=(self.id, self.secret))
self.subdomains = self.collect_subdomains(resp)
next_cursor = json.get("result").get("links").get("next")
while next_cursor:
tmp_params = {
'q': f'names: {self.domain}',
'per_page': 100,
"cursor": next_cursor
}
tmp_resp = self.get(self.addr, params=tmp_params, auth=(self.id, self.secret))
self.subdomains = self.collect_subdomains(tmp_resp)
next_cursor = tmp_resp.json().get("result").get("links").get("next")

def run(self):
"""
Expand Down

0 comments on commit 4febfae

Please sign in to comment.