From 68f5330703db24785d7142d3fa0766bf45dc5cba Mon Sep 17 00:00:00 2001 From: NotoriousRebel Date: Sat, 28 Dec 2019 14:58:31 -0500 Subject: [PATCH] Ported yahoo & virustotal to use aiohttp. --- theHarvester/discovery/virustotal.py | 16 +++++++--------- theHarvester/discovery/yahoosearch.py | 17 ++++++++--------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/theHarvester/discovery/virustotal.py b/theHarvester/discovery/virustotal.py index dcc02df2..c4a7c009 100644 --- a/theHarvester/discovery/virustotal.py +++ b/theHarvester/discovery/virustotal.py @@ -1,6 +1,5 @@ -from theHarvester.lib.core import Core +from theHarvester.lib.core import * from theHarvester.parsers import myparser -import requests class SearchVirustotal: @@ -12,18 +11,17 @@ def __init__(self, word): self.quantity = '100' self.counter = 0 - def do_search(self): + async def do_search(self): base_url = f'https://www.virustotal.com/ui/domains/{self.word}/subdomains?relationships=resolutions&cursor=STMwCi4%3D&limit=40' headers = {'User-Agent': Core.get_user_agent()} - res = requests.get(base_url, headers=headers) - self.results = res.content.decode('UTF-8') + responses = await async_fetcher.fetch_all([base_url], headers=headers) + self.results = responses[0] self.totalresults += self.results - def get_hostnames(self): + async def get_hostnames(self): rawres = myparser.Parser(self.results, self.word) return rawres.hostnames() - def process(self): + async def process(self): print('\tSearching results.') - self.do_search() - self.get_hostnames() + await self.do_search() diff --git a/theHarvester/discovery/yahoosearch.py b/theHarvester/discovery/yahoosearch.py index 4fc324a4..c3387332 100644 --- a/theHarvester/discovery/yahoosearch.py +++ b/theHarvester/discovery/yahoosearch.py @@ -11,22 +11,21 @@ def __init__(self, word, limit): self.server = 'search.yahoo.com' self.limit = limit - def do_search(self): + async def do_search(self): base_url = f'https://{self.server}/search?p=%40{self.word}&b=xx&pz=10' headers = { 'Host': self.server, 'User-agent': Core.get_user_agent() } urls = [base_url.replace("xx", str(num)) for num in range(0, self.limit, 10) if num <= self.limit] - request = (grequests.get(url, headers=headers) for url in urls) - response = grequests.imap(request, size=5) - for entry in response: - self.total_results += entry.content.decode('UTF-8') + responses = await async_fetcher.fetch_all(urls, headers=headers) + for response in responses: + self.total_results += response - def process(self): - self.do_search() + async def process(self): + await self.do_search() - def get_emails(self): + async def get_emails(self): rawres = myparser.Parser(self.total_results, self.word) toparse_emails = rawres.emails() emails = set() @@ -39,6 +38,6 @@ def get_emails(self): emails.add(email) return list(emails) - def get_hostnames(self): + async def get_hostnames(self): rawres = myparser.Parser(self.total_results, self.word) return rawres.hostnames()