From b2376857b889a9f6dbf2a3822b1bea0bcea94118 Mon Sep 17 00:00:00 2001 From: L1ghtn1ng Date: Mon, 24 May 2021 22:00:48 +0100 Subject: [PATCH] Update censys module to support version 2 of the sdk, fix by @thehappydinoa and to get emails. --- theHarvester/__main__.py | 6 ++--- .../discovery/{censys.py => censysearch.py} | 25 ++++++++++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) rename theHarvester/discovery/{censys.py => censysearch.py} (51%) diff --git a/theHarvester/__main__.py b/theHarvester/__main__.py index f6849aa3..6e3bb1eb 100644 --- a/theHarvester/__main__.py +++ b/theHarvester/__main__.py @@ -192,10 +192,10 @@ async def store(search_engine: Any, source: str, process_param: Any = None, stor print(e) elif engineitem == 'censys': - from theHarvester.discovery import censys + from theHarvester.discovery import censysearch try: - censys_search = censys.SearchCensys(word) - stor_lst.append(store(censys_search, engineitem, store_host=True)) + censys_search = censysearch.SearchCensys(word) + stor_lst.append(store(censys_search, engineitem, store_host=True, store_emails=True)) except Exception as e: if isinstance(e, MissingKey): print(e) diff --git a/theHarvester/discovery/censys.py b/theHarvester/discovery/censysearch.py similarity index 51% rename from theHarvester/discovery/censys.py rename to theHarvester/discovery/censysearch.py index 4eb23f27..df70d438 100644 --- a/theHarvester/discovery/censys.py +++ b/theHarvester/discovery/censysearch.py @@ -1,7 +1,8 @@ from theHarvester.discovery.constants import MissingKey from theHarvester.lib.core import Core -from censys.certificates import CensysCertificates -from censys.exceptions import ( +from censys.search import CensysCertificates +from censys.common import __version__ +from censys.common.exceptions import ( CensysRateLimitExceededException, CensysUnauthorizedException, ) @@ -14,25 +15,37 @@ def __init__(self, domain): if self.key[0] is None or self.key[1] is None: raise MissingKey("Censys ID and/or Secret") self.totalhosts = set() + self.emails = set() self.proxy = False async def do_search(self): try: - censys = CensysCertificates(api_id=self.key[0], api_secret=self.key[1]) + cert_search = CensysCertificates( + api_id=self.key[0], + api_secret=self.key[1], + user_agent=f"censys/{__version__} (theHarvester/{Core.version()}; +https://github.com/laramies/theHarvester)", + ) except CensysUnauthorizedException: - raise MissingKey("Censys ID and/or Secret") + raise MissingKey('Censys ID and/or Secret') query = f"parsed.names: {self.word}" try: - response = censys.search(query=query, fields=["parsed.names", "metadata"]) + response = cert_search.search( + query=query, + fields=["parsed.names", "metadata", "parsed.subject.email_address"], + ) for cert in response: - self.totalhosts.update(cert["parsed.names"]) + self.totalhosts.update(cert.get("parsed.names", [])) + self.emails.update(cert.get("parsed.subject.email_address", [])) except CensysRateLimitExceededException: print("Censys rate limit exceeded") async def get_hostnames(self) -> set: return self.totalhosts + async def get_emails(self) -> set: + return self.emails + async def process(self, proxy=False): self.proxy = proxy await self.do_search()