mirror of
https://github.com/laramies/theHarvester.git
synced 2025-02-25 23:13:24 +08:00
Make each reverse query concurrent
This commit is contained in:
parent
d14c28e2fa
commit
c911ea8e18
2 changed files with 25 additions and 20 deletions
|
@ -474,6 +474,9 @@ async def handler(lst):
|
|||
if dnslookup is True:
|
||||
print('\n[*] Starting active queries.')
|
||||
# load the reverse dns tools
|
||||
import functools
|
||||
import operator
|
||||
import random
|
||||
from theHarvester.discovery.dnssearch import (
|
||||
reverse_all_ips_in_range,
|
||||
serialize_ip_range)
|
||||
|
@ -487,12 +490,15 @@ async def handler(lst):
|
|||
print('\n[*] Performing reverse lookup on ' + ip_range)
|
||||
reversed_ipranges[ip_range] = reverse_all_ips_in_range(iprange=ip_range,verbose=True)
|
||||
|
||||
__truc = functools.reduce(operator.add, reversed_ipranges.values())
|
||||
await asyncio.gather(*random.sample(__truc, k=len(__truc)))
|
||||
|
||||
# keep only the host that contain the target domain
|
||||
async for cname in merge_async_generators(*reversed_ipranges.values()):
|
||||
if word in cname:
|
||||
dnsrev.append(cname)
|
||||
if cname not in full:
|
||||
full.append(cname)
|
||||
# async for cname in merge_async_generators(*reversed_ipranges.values()):
|
||||
# if word in cname:
|
||||
# dnsrev.append(cname)
|
||||
# if cname not in full:
|
||||
# full.append(cname)
|
||||
|
||||
# Display the newly found hosts
|
||||
print('[*] Hosts found after reverse lookup (in target domain):')
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
import asyncio
|
||||
import functools
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
@ -142,13 +143,19 @@ async def reverse_single_ip(
|
|||
out: str.
|
||||
The corresponding CNAME or None.
|
||||
"""
|
||||
# Display the current query
|
||||
sys.stdout.write(chr(27) + '[2K' + chr(27) + '[G')
|
||||
sys.stdout.write('\r' + ip + ' - ')
|
||||
sys.stdout.flush()
|
||||
try:
|
||||
__host = await resolver.gethostbyaddr(ip)
|
||||
if __host and __host.name:
|
||||
print(__host.name)
|
||||
return __host.name if __host else ''
|
||||
except Exception:
|
||||
return ''
|
||||
|
||||
async def reverse_all_ips_in_range(
|
||||
def reverse_all_ips_in_range(
|
||||
iprange: str,
|
||||
verbose: bool = False) -> AsyncGenerator[str, None]:
|
||||
"""
|
||||
|
@ -169,17 +176,9 @@ async def reverse_all_ips_in_range(
|
|||
The list of all the found CNAME records.
|
||||
"""
|
||||
__resolver = DNSResolver(timeout=4)
|
||||
for ip in list_ips_in_network_range(iprange):
|
||||
# Display the current query
|
||||
if verbose:
|
||||
sys.stdout.write(chr(27) + '[2K' + chr(27) + '[G')
|
||||
sys.stdout.write('\r' + ip + ' - ')
|
||||
sys.stdout.flush()
|
||||
|
||||
# Reverse the ip
|
||||
__host = await reverse_single_ip(ip=ip, resolver=__resolver)
|
||||
|
||||
# Output the results
|
||||
if __host is not None and __host:
|
||||
print(__host)
|
||||
yield __host
|
||||
__reversing_tasks = []
|
||||
for __ip in list_ips_in_network_range(iprange):
|
||||
__task = asyncio.create_task(reverse_single_ip(ip=__ip, resolver=__resolver))
|
||||
__task.add_done_callback(lambda x: print(x.result()))
|
||||
__reversing_tasks.append(__task)
|
||||
return __reversing_tasks
|
||||
|
|
Loading…
Reference in a new issue