Skip to content

Commit

Permalink
Merge pull request #1083 from Gandalf098/patch-1
Browse files Browse the repository at this point in the history
Updated Censys Analyzer for latest API
  • Loading branch information
nusantara-self authored Sep 19, 2024
2 parents 539b696 + ed71804 commit 4d1f391
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions analyzers/Censys/censys_analyzer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env python3
from cortexutils.analyzer import Analyzer
from censys.certificates import CensysCertificates
from censys.ipv4 import CensysIPv4
from censys.websites import CensysWebsites
from censys.exceptions import (
from censys.search import CensysHosts
from censys.common.exceptions import (
CensysNotFoundException,
CensysRateLimitExceededException,
CensysUnauthorizedException,
Expand Down Expand Up @@ -45,8 +43,8 @@ def search_hosts(self, ip):
:type ip: str
:return: dict
"""
c = CensysIPv4(api_id=self.__uid, api_secret=self.__api_key)
return c.view(ip)
c = CensysHosts(api_id=self.__uid, api_secret=self.__api_key)
return c.search("ip: " + ip, per_page=1, pages=1)()[0]

def search_certificate(self, hash):
"""
Expand All @@ -56,8 +54,8 @@ def search_certificate(self, hash):
:type hash: str
:return: dict
"""
c = CensysCertificates(api_id=self.__uid, api_secret=self.__api_key)
return c.view(hash)
c = CensysHosts(api_id=self.__uid, api_secret=self.__api_key)
return c.search("certificate: " + hash, per_page=1, pages=1)()[0]

def search_website(self, dom):
"""
Expand All @@ -66,8 +64,8 @@ def search_website(self, dom):
:type dom: str
:return: dict
"""
c = CensysWebsites(api_id=self.__uid, api_secret=self.__api_key)
return c.view(dom)
c = CensyshOSTs(api_id=self.__uid, api_secret=self.__api_key)
return c.search("dns.name: " + dom, per_page=1, pages=1)()[0]

def search_ipv4(self, search):
"""
Expand All @@ -76,8 +74,8 @@ def search_ipv4(self, search):
:type search: str
:return: dict
"""
c = CensysIPv4(api_id=self.__uid, api_secret=self.__api_key)
return [x for x in c.search(search, fields=self.__fields, max_records=self.__max_records, flatten=self.__flatten)]
c = CensysHosts(api_id=self.__uid, api_secret=self.__api_key)
return [x for x in c.search("ip: " + search, per_page=1, pages=1)()[0]]

def run(self):
try:
Expand Down Expand Up @@ -114,7 +112,8 @@ def summary(self, raw):
taxonomies = []
if 'ip' in raw:
raw = raw['ip']
service_count = len(raw.get('protocols', []))
service_count = len(raw.get('services', []))
print(service_count)
heartbleed = raw.get('443', {}).get('https', {}).get('heartbleed', {}).get('heartbleed_vulnerable', False)
taxonomies.append(self.build_taxonomy('info', 'Censys', 'OpenServices', service_count))
if heartbleed:
Expand Down

0 comments on commit 4d1f391

Please sign in to comment.