From 14e76dbad2259a6bf800bd93aff8f0004fc5140e Mon Sep 17 00:00:00 2001 From: L1ghtn1ng Date: Tue, 6 Oct 2020 16:03:00 +0100 Subject: [PATCH] Add the main censys module that is WIP --- theHarvester/discovery/censys.py | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 theHarvester/discovery/censys.py diff --git a/theHarvester/discovery/censys.py b/theHarvester/discovery/censys.py new file mode 100644 index 00000000..928bcfa8 --- /dev/null +++ b/theHarvester/discovery/censys.py @@ -0,0 +1,33 @@ +from theHarvester.discovery.constants import * +from theHarvester.lib.core import * +import censys.certificates +import censys.base + + +class SearchCensys: + + def __init__(self, word): + self.word = word + self.key = Core.censys_key() + if self.key[0] is None or self.key[1] is None: + raise MissingKey(True, 'Censys ID or Secret') + self.totalhosts = set() + self.proxy = False + + async def do_search(self): + cert = censys.certificates.CensysCertificates(api_id=self.key[0], api_secret=self.key[1]) + query = f'parsed.names: {self.word}' + try: + response = cert.search(query=query, fields=['parsed.names']) + except censys.base.CensysRateLimitExceededException: + print('Censys rate limit exceeded') + for hosts in response: + #print(set(hosts['parsed.names'])) + self.totalhosts.update(hosts['parsed.names']) + + async def get_hostnames(self) -> set: + return self.totalhosts + + async def process(self, proxy=False): + self.proxy = proxy + await self.do_search()