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