2019-01-06 13:14:46 +08:00
#!/usr/bin/env python3
2011-05-04 23:07:06 +08:00
2019-01-01 07:14:12 +08:00
from discovery import *
from discovery . constants import *
from lib import hostchecker
from lib import htmlExport
2018-12-30 10:29:25 +08:00
from lib import reportgraph
from lib import statichtmlgenerator
2019-01-20 09:59:59 +08:00
from lib import stash
2019-01-22 04:46:10 +08:00
from lib . core import *
from platform import python_version
import argparse
2019-01-11 10:09:47 +08:00
import datetime
2019-01-13 05:49:05 +08:00
import ipaddress
2019-01-11 10:09:47 +08:00
import re
import time
2019-01-24 01:22:29 +08:00
import sys
2015-07-06 00:03:13 +08:00
try :
2018-12-27 15:43:32 +08:00
import bs4
2018-12-30 10:29:25 +08:00
except ImportError :
2019-01-11 13:14:44 +08:00
print ( ' \n \033 [93m[!] BeautifulSoup library not found, please install before proceeding. \n \n \033 [0m ' )
2018-12-27 15:53:12 +08:00
sys . exit ( 1 )
2018-12-16 11:07:37 +08:00
2018-11-30 05:28:37 +08:00
try :
2018-12-27 15:43:32 +08:00
import requests
2018-12-30 10:29:25 +08:00
except ImportError :
2019-01-11 13:14:44 +08:00
print ( ' \n \033 [93m[!] Requests library not found, please install before proceeding. \n \n \033 [0m ' )
2018-12-27 15:53:12 +08:00
sys . exit ( 1 )
2015-07-06 00:03:13 +08:00
2019-01-01 07:14:12 +08:00
Core . banner ( )
2011-05-04 23:07:06 +08:00
2018-12-30 10:29:25 +08:00
2019-01-14 10:11:23 +08:00
def start ( ) :
2019-01-27 12:42:56 +08:00
parser = argparse . ArgumentParser ( description = ' theHarvester is used to gather open source intelligence on a company or domain. ' )
parser . add_argument ( ' -d ' , ' --domain ' , help = ' Company or domain to search ' , required = True )
parser . add_argument ( ' -l ' , ' --limit ' , help = ' Limit the number of search results, default=500 ' , default = 500 , type = int )
parser . add_argument ( ' -S ' , ' --start ' , help = ' Start with result number X, default=0 ' , default = 0 , type = int )
parser . add_argument ( ' -g ' , ' --google-dork ' , help = ' Use Google Dorks for Google search ' , default = False , action = ' store_true ' )
parser . add_argument ( ' -p ' , ' --port-scan ' , help = ' Scan discovered hosts and check for Takeovers (21,22,80,443,8080) default=False, params=True ' , default = False )
parser . add_argument ( ' -s ' , ' --shodan ' , help = ' Use Shodan to query discovered hosts ' , default = False , action = ' store_true ' )
parser . add_argument ( ' -v ' , ' --virtual-host ' , help = ' Verify host name via DNS resolution and search for virtual hosts params=basic, default=False ' , default = False )
parser . add_argument ( ' -e ' , ' --dns-server ' , help = ' Specify a DNS server to use for lookup ' )
parser . add_argument ( ' -c ' , ' --dns-brute ' , help = ' Perform a DNS brute force on a domain ' , default = False , action = ' store_true ' )
parser . add_argument ( ' -n ' , ' --dns-lookup ' , help = ' Enable a DNS server lookup, default=False, params=True ' , default = False )
parser . add_argument ( ' -t ' , ' --dns-tld ' , help = ' Perform a DNS TLD expansion discovery, default False ' , default = False )
parser . add_argument ( ' -f ' , ' --filename ' , help = ' Save the results to an HTML and/or XML file ' , default = ' ' , type = str )
parser . add_argument ( ' -b ' , ' --source ' , help = ''' Source: baidu, bing, bingapi, censys, crtsh, cymon,
2019-01-27 09:01:30 +08:00
dogpile , duckduckgo , google , googleCSE ,
2019-01-28 09:33:18 +08:00
google - certificates , hunter , linkedin ,
netcraft , pgp , securityTrails , threatcrowd ,
2019-01-27 09:01:30 +08:00
trello , twitter , vhost , virustotal , yahoo , all ''' )
2019-01-14 10:11:23 +08:00
args = parser . parse_args ( )
2018-03-23 06:32:50 +08:00
try :
2018-12-16 11:07:37 +08:00
db = stash . stash_manager ( )
2018-03-23 06:32:50 +08:00
db . do_init ( )
2019-01-14 10:11:23 +08:00
except Exception :
2018-03-23 06:32:50 +08:00
pass
2019-01-13 14:17:06 +08:00
2018-12-18 07:14:42 +08:00
all_emails = [ ]
2019-01-13 14:17:06 +08:00
all_hosts = [ ]
all_ip = [ ]
2019-01-20 09:59:59 +08:00
dnsbrute = args . dns_brute
dnslookup = args . dns_lookup
dnsserver = args . dns_server
2019-01-22 04:46:10 +08:00
dnstld = args . dns_tld
2019-01-17 07:47:43 +08:00
filename = args . filename
2019-01-13 14:17:06 +08:00
full = [ ]
2019-01-22 04:46:10 +08:00
google_dorking = args . google_dork
2019-01-13 14:17:06 +08:00
host_ip = [ ]
2019-01-14 10:11:23 +08:00
limit = args . limit
2019-01-22 04:46:10 +08:00
ports_scanning = args . port_scan
2019-01-17 07:47:43 +08:00
shodan = args . shodan
2019-01-18 06:05:10 +08:00
start = args . start
2019-01-13 14:17:06 +08:00
takeover_check = False
2018-12-23 04:48:46 +08:00
trello_info = ( [ ] , False )
2019-01-13 14:17:06 +08:00
vhost = [ ]
2019-01-20 09:59:59 +08:00
virtual = args . virtual_host
2019-01-14 10:11:23 +08:00
word = args . domain
2019-01-24 02:47:48 +08:00
if args . source is not None :
engines = set ( args . source . split ( ' , ' ) )
if set ( engines ) . issubset ( Core . get_supportedengines ( ) ) :
2019-01-27 09:37:16 +08:00
print ( f ' \033 [94m[*] Target: { word } \n \033 [0m ' )
2019-01-24 02:47:48 +08:00
for engineitem in engines :
if engineitem == ' baidu ' :
print ( ' \033 [94m[*] Searching Baidu. \033 [0m ' )
try :
search = baidusearch . SearchBaidu ( word , limit )
search . process ( )
all_emails = filter ( search . get_emails ( ) )
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' host ' , ' baidu ' )
db . store_all ( word , all_emails , ' email ' , ' baidu ' )
except Exception :
pass
2018-10-27 03:42:47 +08:00
2019-01-24 02:47:48 +08:00
elif engineitem == ' bing ' or engineitem == ' bingapi ' :
print ( ' \033 [94m[*] Searching Bing. \033 [0m ' )
try :
search = bingsearch . SearchBing ( word , limit , start )
bingapi = ' '
if engineitem == ' bingapi ' :
bingapi + = ' yes '
else :
bingapi + = ' no '
search . process ( bingapi )
all_emails = filter ( search . get_emails ( ) )
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' email ' , ' bing ' )
db . store_all ( word , all_hosts , ' host ' , ' bing ' )
except Exception as e :
2019-01-14 10:11:23 +08:00
if isinstance ( e , MissingKey ) :
print ( e )
2019-01-11 15:21:45 +08:00
else :
2019-01-14 10:11:23 +08:00
pass
2018-10-27 03:42:47 +08:00
2019-01-24 02:47:48 +08:00
elif engineitem == ' censys ' :
2019-01-14 10:11:23 +08:00
print ( ' \033 [94m[*] Searching Censys. \033 [0m ' )
from discovery import censys
# Import locally or won't work
search = censys . SearchCensys ( word , limit )
search . process ( )
all_ip = search . get_ipaddresses ( )
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' host ' , ' censys ' )
db . store_all ( word , all_ip , ' ip ' , ' censys ' )
2019-01-24 02:47:48 +08:00
elif engineitem == ' crtsh ' :
2019-01-14 10:11:23 +08:00
print ( ' \033 [94m[*] Searching CRT.sh. \033 [0m ' )
search = crtsh . search_crtsh ( word )
search . process ( )
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' host ' , ' CRTsh ' )
2019-01-24 02:47:48 +08:00
elif engineitem == ' cymon ' :
2019-01-14 10:11:23 +08:00
print ( ' \033 [94m[*] Searching Cymon. \033 [0m ' )
from discovery import cymon
# Import locally or won't work.
search = cymon . search_cymon ( word )
search . process ( )
all_ip = search . get_ipaddresses ( )
db = stash . stash_manager ( )
db . store_all ( word , all_ip , ' ip ' , ' cymon ' )
2019-01-24 02:47:48 +08:00
elif engineitem == ' dogpile ' :
try :
print ( ' \033 [94m[*] Searching Dogpile. \033 [0m ' )
search = dogpilesearch . SearchDogpile ( word , limit )
search . process ( )
emails = filter ( search . get_emails ( ) )
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
all_emails . extend ( emails )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' email ' , ' dogpile ' )
db . store_all ( word , all_hosts , ' host ' , ' dogpile ' )
except Exception as e :
2019-01-27 09:37:16 +08:00
print ( f ' \033 [93m[!] A error occurred in Dogpile: { e } \033 [0m ' )
2019-01-14 10:11:23 +08:00
2019-01-24 02:47:48 +08:00
elif engineitem == ' duckduckgo ' :
2019-01-14 10:11:23 +08:00
print ( ' \033 [94m[*] Searching DuckDuckGo. \033 [0m ' )
from discovery import duckduckgosearch
search = duckduckgosearch . SearchDuckDuckGo ( word , limit )
search . process ( )
emails = filter ( search . get_emails ( ) )
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
all_emails . extend ( emails )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' email ' , ' duckduckgo ' )
db . store_all ( word , all_hosts , ' host ' , ' duckduckgo ' )
2019-01-24 02:47:48 +08:00
elif engineitem == ' google ' :
2019-01-14 10:11:23 +08:00
print ( ' \033 [94m[*] Searching Google. \033 [0m ' )
search = googlesearch . search_google ( word , limit , start )
search . process ( google_dorking )
emails = filter ( search . get_emails ( ) )
all_emails . extend ( emails )
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' host ' , ' google ' )
db . store_all ( word , all_emails , ' email ' , ' google ' )
2019-01-24 02:47:48 +08:00
elif engineitem == ' googleCSE ' :
2019-01-18 06:05:10 +08:00
print ( ' \033 [94m[*] Searching Google Custom Search. \033 [0m ' )
try :
search = googleCSE . SearchGoogleCSE ( word , limit , start )
2018-10-27 03:42:47 +08:00
search . process ( )
2019-01-18 06:05:10 +08:00
search . store_results ( )
all_emails = filter ( search . get_emails ( ) )
2018-12-31 01:52:02 +08:00
db = stash . stash_manager ( )
2019-01-02 10:18:09 +08:00
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
2019-01-18 06:05:10 +08:00
db . store_all ( word , all_hosts , ' email ' , ' googleCSE ' )
2019-01-02 10:18:09 +08:00
db = stash . stash_manager ( )
2019-01-18 06:05:10 +08:00
db . store_all ( word , all_hosts , ' host ' , ' googleCSE ' )
except Exception as e :
if isinstance ( e , MissingKey ) :
print ( e )
2019-01-11 15:21:45 +08:00
else :
2019-01-18 06:05:10 +08:00
pass
2019-01-14 10:11:23 +08:00
2019-01-24 02:47:48 +08:00
elif engineitem == ' google-certificates ' :
2019-01-14 10:11:23 +08:00
print ( ' \033 [94m[*] Searching Google Certificate transparency report. \033 [0m ' )
search = googlecertificates . SearchGoogleCertificates ( word , limit , start )
search . process ( )
hosts = filter ( search . get_domains ( ) )
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' host ' , ' google-certificates ' )
2019-01-24 02:47:48 +08:00
elif engineitem == ' hunter ' :
print ( ' \033 [94m[*] Searching Hunter. \033 [0m ' )
from discovery import huntersearch
# Import locally or won't work.
try :
search = huntersearch . SearchHunter ( word , limit , start )
2018-12-01 17:39:01 +08:00
search . process ( )
2018-12-24 08:54:56 +08:00
emails = filter ( search . get_emails ( ) )
2018-12-23 04:48:46 +08:00
all_emails . extend ( emails )
2019-01-24 02:47:48 +08:00
hosts = filter ( search . get_hostnames ( ) )
2018-12-23 04:48:46 +08:00
all_hosts . extend ( hosts )
2018-12-20 03:39:33 +08:00
db = stash . stash_manager ( )
2019-01-24 02:47:48 +08:00
db . store_all ( word , all_hosts , ' host ' , ' hunter ' )
db . store_all ( word , all_emails , ' email ' , ' hunter ' )
except Exception as e :
if isinstance ( e , MissingKey ) :
print ( e )
else :
pass
2018-12-16 11:07:37 +08:00
2019-01-24 02:47:48 +08:00
elif engineitem == ' linkedin ' :
print ( ' \033 [94m[*] Searching Linkedin. \033 [0m ' )
search = linkedinsearch . SearchLinkedin ( word , limit )
search . process ( )
people = search . get_people ( )
db = stash . stash_manager ( )
db . store_all ( word , people , ' name ' , ' linkedin ' )
2019-01-12 04:40:35 +08:00
2019-01-24 02:47:48 +08:00
if len ( people ) == 0 :
print ( ' \n [*] No users found Linkedin. \n \n ' )
else :
print ( f ' \n [*] Users found: { len ( people ) } ' )
print ( ' --------------------- ' )
for user in sorted ( list ( set ( people ) ) ) :
print ( user )
sys . exit ( 0 )
2018-12-16 11:07:37 +08:00
2019-01-24 02:47:48 +08:00
elif engineitem == ' netcraft ' :
print ( ' \033 [94m[*] Searching Netcraft. \033 [0m ' )
search = netcraft . SearchNetcraft ( word )
search . process ( )
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' host ' , ' netcraft ' )
2018-12-16 11:07:37 +08:00
2019-01-24 02:47:48 +08:00
elif engineitem == ' pgp ' :
print ( ' \033 [94m[*] Searching PGP key server. \033 [0m ' )
try :
search = pgpsearch . SearchPgp ( word )
2018-12-22 04:17:51 +08:00
search . process ( )
2019-01-24 02:47:48 +08:00
all_emails = filter ( search . get_emails ( ) )
2018-12-24 08:54:56 +08:00
hosts = filter ( search . get_hostnames ( ) )
2018-12-22 04:17:51 +08:00
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
2019-01-24 02:47:48 +08:00
db . store_all ( word , all_hosts , ' host ' , ' pgp ' )
db . store_all ( word , all_emails , ' email ' , ' pgp ' )
except Exception :
pass
elif engineitem == ' securityTrails ' :
print ( ' \033 [94m[*] Searching SecurityTrails. \033 [0m ' )
from discovery import securitytrailssearch
try :
search = securitytrailssearch . search_securitytrail ( word )
2018-10-27 03:42:47 +08:00
search . process ( )
2018-12-24 08:54:56 +08:00
hosts = filter ( search . get_hostnames ( ) )
2018-10-27 03:42:47 +08:00
all_hosts . extend ( hosts )
2018-12-16 11:07:37 +08:00
db = stash . stash_manager ( )
2019-01-24 02:47:48 +08:00
db . store_all ( word , hosts , ' host ' , ' securityTrails ' )
ips = search . get_ips ( )
all_ip . extend ( ips )
2018-12-16 11:07:37 +08:00
db = stash . stash_manager ( )
2019-01-24 02:47:48 +08:00
db . store_all ( word , ips , ' ip ' , ' securityTrails ' )
except Exception as e :
if isinstance ( e , MissingKey ) :
print ( e )
else :
pass
2018-10-27 03:42:47 +08:00
2019-01-24 02:47:48 +08:00
elif engineitem == ' threatcrowd ' :
print ( ' \033 [94m[*] Searching Threatcrowd. \033 [0m ' )
try :
search = threatcrowd . search_threatcrowd ( word )
2018-10-27 03:42:47 +08:00
search . process ( )
2018-12-24 08:54:56 +08:00
hosts = filter ( search . get_hostnames ( ) )
2018-10-27 03:42:47 +08:00
all_hosts . extend ( hosts )
2018-12-16 11:07:37 +08:00
db = stash . stash_manager ( )
2019-01-24 02:47:48 +08:00
db . store_all ( word , all_hosts , ' host ' , ' threatcrowd ' )
except Exception :
pass
2018-10-27 03:42:47 +08:00
2019-01-24 02:47:48 +08:00
elif engineitem == ' trello ' :
print ( ' \033 [94m[*] Searching Trello. \033 [0m ' )
from discovery import trello
# Import locally or won't work.
search = trello . search_trello ( word , limit )
search . process ( )
emails = filter ( search . get_emails ( ) )
all_emails . extend ( emails )
info = search . get_urls ( )
hosts = filter ( info [ 0 ] )
trello_info = ( info [ 1 ] , True )
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
db . store_all ( word , hosts , ' host ' , ' trello ' )
db . store_all ( word , emails , ' email ' , ' trello ' )
2018-11-11 22:24:58 +08:00
2019-01-24 02:47:48 +08:00
elif engineitem == ' twitter ' :
print ( ' \033 [94m[*] Searching Twitter. \033 [0m ' )
search = twittersearch . search_twitter ( word , limit )
search . process ( )
people = search . get_people ( )
db = stash . stash_manager ( )
db . store_all ( word , people , ' name ' , ' twitter ' )
if len ( people ) == 0 :
print ( ' \n [*] No users found. \n \n ' )
else :
print ( ' \n [*] Users found: ' + str ( len ( people ) ) )
print ( ' --------------------- ' )
for user in sorted ( list ( set ( people ) ) ) :
print ( user )
2018-12-23 04:29:11 +08:00
2019-01-24 02:47:48 +08:00
elif engineitem == ' virustotal ' :
print ( ' \033 [94m[*] Searching VirusTotal. \033 [0m ' )
search = virustotal . search_virustotal ( word )
search . process ( )
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' host ' , ' virustotal ' )
elif engineitem == ' yahoo ' :
print ( ' \033 [94m[*] Searching Yahoo. \033 [0m ' )
search = yahoosearch . search_yahoo ( word , limit )
search . process ( )
hosts = search . get_hostnames ( )
emails = search . get_emails ( )
all_hosts . extend ( filter ( hosts ) )
all_emails . extend ( filter ( emails ) )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' host ' , ' yahoo ' )
db . store_all ( word , all_emails , ' email ' , ' yahoo ' )
elif engineitem == ' all ' :
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m[*] Running a full harvest. \033 [0m ' )
2019-01-24 02:47:48 +08:00
all_emails = [ ]
all_hosts = [ ]
try :
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching Baidu. \033 [0m ' )
2019-01-24 02:47:48 +08:00
search = baidusearch . SearchBaidu ( word , limit )
2019-01-06 17:50:07 +08:00
search . process ( )
2019-01-24 02:47:48 +08:00
all_emails = filter ( search . get_emails ( ) )
2019-01-06 17:50:07 +08:00
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
2019-01-24 02:47:48 +08:00
db . store_all ( word , all_hosts , ' host ' , ' baidu ' )
db . store_all ( word , all_emails , ' email ' , ' baidu ' )
except Exception :
pass
2019-01-06 17:50:07 +08:00
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching Bing. \033 [0m ' )
2019-01-24 02:47:48 +08:00
bingapi = ' no '
search = bingsearch . SearchBing ( word , limit , start )
search . process ( bingapi )
emails = filter ( search . get_emails ( ) )
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' host ' , ' bing ' )
all_emails . extend ( emails )
all_emails = sorted ( set ( all_emails ) )
db . store_all ( word , all_emails , ' email ' , ' bing ' )
2018-12-23 04:29:11 +08:00
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching Censys. \033 [0m ' )
2019-01-24 02:47:48 +08:00
from discovery import censys
search = censys . SearchCensys ( word , limit )
search . process ( )
ips = search . get_ipaddresses ( )
setips = set ( ips )
uniqueips = list ( setips ) # Remove duplicates.
all_ip . extend ( uniqueips )
hosts = filter ( search . get_hostnames ( ) )
sethosts = set ( hosts )
uniquehosts = list ( sethosts ) # Remove duplicates.
all_hosts . extend ( uniquehosts )
db = stash . stash_manager ( )
db . store_all ( word , uniquehosts , ' host ' , ' censys ' )
db . store_all ( word , uniqueips , ' ip ' , ' censys ' )
2018-11-03 07:04:20 +08:00
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching CRT.sh. \033 [0m ' )
2019-01-24 02:47:48 +08:00
search = crtsh . search_crtsh ( word )
search . process ( )
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' host ' , ' CRTsh ' )
2019-01-17 08:06:41 +08:00
2019-01-24 02:47:48 +08:00
# cymon
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching Cymon. \033 [0m ' )
2019-01-24 02:47:48 +08:00
from discovery import cymon
# Import locally or won't work.
search = cymon . search_cymon ( word )
search . process ( )
all_ip = search . get_ipaddresses ( )
db = stash . stash_manager ( )
db . store_all ( word , all_ip , ' ip ' , ' cymon ' )
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching Dogpile. \033 [0m ' )
2019-01-24 02:47:48 +08:00
search = dogpilesearch . SearchDogpile ( word , limit )
search . process ( )
emails = filter ( search . get_emails ( ) )
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
all_emails . extend ( emails )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' email ' , ' dogpile ' )
db . store_all ( word , all_hosts , ' host ' , ' dogpile ' )
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching DuckDuckGo. \033 [0m ' )
2019-01-24 02:47:48 +08:00
from discovery import duckduckgosearch
search = duckduckgosearch . SearchDuckDuckGo ( word , limit )
search . process ( )
emails = filter ( search . get_emails ( ) )
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
all_emails . extend ( emails )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' email ' , ' duckduckgo ' )
db . store_all ( word , all_hosts , ' host ' , ' duckduckgo ' )
2018-12-23 04:29:11 +08:00
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching Google. \033 [0m ' )
2019-01-24 02:47:48 +08:00
search = googlesearch . search_google ( word , limit , start )
search . process ( google_dorking )
emails = filter ( search . get_emails ( ) )
hosts = filter ( search . get_hostnames ( ) )
all_emails . extend ( emails )
db = stash . stash_manager ( )
db . store_all ( word , all_emails , ' email ' , ' google ' )
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' host ' , ' google ' )
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching Google Certificate transparency report. \033 [0m ' )
2019-01-24 02:47:48 +08:00
search = googlecertificates . SearchGoogleCertificates ( word , limit , start )
search . process ( )
domains = filter ( search . get_domains ( ) )
all_hosts . extend ( domains )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' host ' , ' google-certificates ' )
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching Hunter. \033 [0m ' )
2019-01-24 02:47:48 +08:00
from discovery import huntersearch
# Import locally.
try :
search = huntersearch . SearchHunter ( word , limit , start )
2018-12-22 06:47:15 +08:00
search . process ( )
2019-01-24 02:47:48 +08:00
emails = filter ( search . get_emails ( ) )
2018-12-24 08:54:56 +08:00
hosts = filter ( search . get_hostnames ( ) )
2018-12-22 06:47:15 +08:00
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
2019-01-24 02:47:48 +08:00
db . store_all ( word , hosts , ' host ' , ' hunter ' )
all_emails . extend ( emails )
all_emails = sorted ( set ( all_emails ) )
db . store_all ( word , all_emails , ' email ' , ' hunter ' )
except Exception as e :
if isinstance ( e , MissingKey ) :
print ( e )
else :
2018-12-24 06:27:30 +08:00
pass
2018-11-23 05:20:06 +08:00
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching Linkedin. \033 [0m ' )
2019-01-24 02:47:48 +08:00
search = linkedinsearch . SearchLinkedin ( word , limit )
search . process ( )
people = search . get_people ( )
db = stash . stash_manager ( )
db . store_all ( word , people , ' name ' , ' linkedin ' )
if len ( people ) == 0 :
print ( ' \n [*] No users found. \n \n ' )
else :
print ( ' \n [*] Users found: ' + str ( len ( people ) ) )
print ( ' --------------------- ' )
for user in sorted ( list ( set ( people ) ) ) :
print ( user )
2018-12-23 04:29:11 +08:00
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching Netcraft. \033 [0m ' )
2019-01-24 02:47:48 +08:00
search = netcraft . SearchNetcraft ( word )
search . process ( )
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' host ' , ' netcraft ' )
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching PGP key server. \033 [0m ' )
2019-01-24 02:47:48 +08:00
try :
search = pgpsearch . SearchPgp ( word )
2018-12-23 04:48:46 +08:00
search . process ( )
2018-12-24 08:54:56 +08:00
emails = filter ( search . get_emails ( ) )
2019-01-24 02:47:48 +08:00
hosts = filter ( search . get_hostnames ( ) )
sethosts = set ( hosts )
uniquehosts = list ( sethosts ) # Remove duplicates.
all_hosts . extend ( uniquehosts )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' host ' , ' PGP ' )
2018-12-23 04:48:46 +08:00
all_emails . extend ( emails )
db = stash . stash_manager ( )
2019-01-24 02:47:48 +08:00
db . store_all ( word , all_emails , ' email ' , ' PGP ' )
except Exception :
pass
2018-12-23 04:29:11 +08:00
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching Threatcrowd. \033 [0m ' )
2019-01-24 02:47:48 +08:00
try :
search = threatcrowd . search_threatcrowd ( word )
2018-12-23 02:46:27 +08:00
search . process ( )
2018-12-27 15:43:32 +08:00
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
2018-12-23 02:46:27 +08:00
db = stash . stash_manager ( )
2019-01-24 02:47:48 +08:00
db . store_all ( word , all_hosts , ' host ' , ' threatcrowd ' )
except Exception :
pass
2018-12-23 04:29:11 +08:00
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching Trello. \033 [0m ' )
2019-01-24 02:47:48 +08:00
from discovery import trello
# Import locally or won't work.
search = trello . search_trello ( word , limit )
search . process ( )
emails = filter ( search . get_emails ( ) )
all_emails . extend ( emails )
info = search . get_urls ( )
hosts = filter ( info [ 0 ] )
trello_info = ( info [ 1 ] , True )
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
db . store_all ( word , hosts , ' host ' , ' trello ' )
db . store_all ( word , emails , ' email ' , ' trello ' )
try :
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching Twitter. \033 [0m ' )
2019-01-24 02:47:48 +08:00
search = twittersearch . search_twitter ( word , limit )
2019-01-06 17:50:07 +08:00
search . process ( )
2019-01-24 02:47:48 +08:00
people = search . get_people ( )
2019-01-06 17:50:07 +08:00
db = stash . stash_manager ( )
2019-01-24 02:47:48 +08:00
db . store_all ( word , people , ' name ' , ' twitter ' )
print ( ' \n Users from Twitter: ' )
print ( ' ------------------- ' )
for user in people :
print ( user )
except Exception :
pass
print ( ' \n [*] Virtual hosts: ' )
print ( ' ------------------ ' )
for l in host_ip :
search = bingsearch . SearchBing ( l , limit , start )
search . process_vhost ( )
res = search . get_allhostnames ( )
for x in res :
x = re . sub ( r ' [[ \ < \ /?]*[ \ w]*>]* ' , ' ' , x )
x = re . sub ( ' < ' , ' ' , x )
x = re . sub ( ' > ' , ' ' , x )
print ( ( l + ' \t ' + x ) )
vhost . append ( l + ' : ' + x )
full . append ( l + ' : ' + x )
vhost = sorted ( set ( vhost ) )
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching VirusTotal. \033 [0m ' )
2019-01-24 02:47:48 +08:00
search = virustotal . search_virustotal ( word )
search . process ( )
hosts = filter ( search . get_hostnames ( ) )
all_hosts . extend ( hosts )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' host ' , ' virustotal ' )
2019-01-28 09:33:18 +08:00
print ( ' \033 [94m \n [*] Searching Yahoo. \033 [0m ' )
2019-01-24 02:47:48 +08:00
search = yahoosearch . search_yahoo ( word , limit )
search . process ( )
hosts = search . get_hostnames ( )
emails = search . get_emails ( )
all_hosts . extend ( filter ( hosts ) )
all_emails . extend ( filter ( emails ) )
db = stash . stash_manager ( )
db . store_all ( word , all_hosts , ' host ' , ' yahoo ' )
db . store_all ( word , all_emails , ' email ' , ' yahoo ' )
else :
print ( ' \033 [93m[!] Invalid source. \n \n \033 [0m ' )
sys . exit ( 1 )
2018-11-11 22:24:58 +08:00
2018-12-27 15:43:32 +08:00
# Sanity check to see if all_emails and all_hosts are defined.
2018-11-23 05:20:06 +08:00
try :
all_emails
except NameError :
2019-01-11 13:14:44 +08:00
print ( ' \n \n \033 [93m[!] No emails found because all_emails is not defined. \n \n \033 [0m ' )
2018-12-27 15:43:32 +08:00
sys . exit ( 1 )
2018-11-23 05:20:06 +08:00
try :
all_hosts
except NameError :
2019-01-11 13:14:44 +08:00
print ( ' \n \n \033 [93m[!] No hosts found because all_hosts is not defined. \n \n \033 [0m ' )
2018-12-27 15:43:32 +08:00
sys . exit ( 1 )
2018-11-23 05:20:06 +08:00
2019-01-11 13:14:44 +08:00
# Results
if len ( all_ip ) == 0 :
2019-01-11 15:21:45 +08:00
print ( ' \n [*] No IPs found. ' )
2019-01-11 13:14:44 +08:00
else :
2019-01-11 15:21:45 +08:00
print ( ' \n [*] IPs found: ' + str ( len ( all_ip ) ) )
print ( ' ------------------- ' )
2019-01-24 01:27:16 +08:00
ips = sorted ( ipaddress . ip_address ( line . strip ( ) ) for line in set ( all_ip ) )
2019-01-13 05:49:05 +08:00
print ( ' \n ' . join ( map ( str , ips ) ) )
2019-01-11 13:14:44 +08:00
2019-01-11 15:21:45 +08:00
if len ( all_emails ) == 0 :
2019-01-11 13:14:44 +08:00
print ( ' \n [*] No emails found. ' )
2014-12-17 07:25:12 +08:00
else :
2019-01-11 15:21:45 +08:00
print ( ' \n [*] Emails found: ' + str ( len ( all_emails ) ) )
print ( ' ---------------------- ' )
2019-01-13 14:17:06 +08:00
print ( ( ' \n ' . join ( sorted ( list ( set ( all_emails ) ) ) ) ) )
2014-12-17 07:25:12 +08:00
2019-01-11 15:21:45 +08:00
if len ( all_hosts ) == 0 :
print ( ' \n [*] No hosts found. \n \n ' )
2014-12-17 07:25:12 +08:00
else :
2019-01-23 23:59:11 +08:00
print ( ' \n [*] Hosts found: ' + str ( len ( all_hosts ) ) )
print ( ' --------------------- ' )
2018-12-24 10:50:25 +08:00
all_hosts = sorted ( list ( set ( all_hosts ) ) )
2014-12-17 07:25:12 +08:00
full_host = hostchecker . Checker ( all_hosts )
full = full_host . check ( )
for host in full :
2018-04-16 19:55:52 +08:00
ip = host . split ( ' : ' ) [ 1 ]
2018-11-23 05:20:06 +08:00
print ( host )
2019-01-13 14:17:06 +08:00
if ip != ' empty ' :
2018-08-09 03:34:10 +08:00
if host_ip . count ( ip . lower ( ) ) :
pass
else :
host_ip . append ( ip . lower ( ) )
2018-12-16 11:07:37 +08:00
2018-12-20 03:39:33 +08:00
db = stash . stash_manager ( )
db . store_all ( word , host_ip , ' ip ' , ' DNS-resolver ' )
2019-01-11 10:09:47 +08:00
if trello_info [ 1 ] is True :
2018-12-23 04:48:46 +08:00
trello_urls = trello_info [ 0 ]
if trello_urls == [ ] :
2019-01-11 15:21:45 +08:00
print ( ' \n [*] No URLs found. ' )
2018-12-23 04:48:46 +08:00
else :
total = len ( trello_urls )
2019-01-11 15:21:45 +08:00
print ( ' \n [*] URLs found: ' + str ( total ) )
print ( ' -------------------- ' )
2018-12-23 04:48:46 +08:00
for url in sorted ( list ( set ( trello_urls ) ) ) :
print ( url )
2018-12-24 04:23:01 +08:00
2019-01-11 10:09:47 +08:00
# DNS brute force
2018-08-09 03:34:10 +08:00
dnsres = [ ]
2019-01-01 07:14:12 +08:00
if dnsbrute is True :
2019-01-11 13:14:44 +08:00
print ( ' \n [*] Starting DNS brute force. ' )
2018-08-09 03:34:10 +08:00
a = dnssearch . dns_force ( word , dnsserver , verbose = True )
res = a . process ( )
2019-01-11 13:14:44 +08:00
print ( ' \n [*] Hosts found after DNS brute force: ' )
print ( ' ------------------------------------- ' )
2018-08-09 03:34:10 +08:00
for y in res :
2018-11-23 05:20:06 +08:00
print ( y )
2018-08-09 03:34:10 +08:00
dnsres . append ( y . split ( ' : ' ) [ 0 ] )
if y not in full :
full . append ( y )
2018-12-16 11:07:37 +08:00
db = stash . stash_manager ( )
db . store_all ( word , dnsres , ' host ' , ' dns_bruteforce ' )
2018-08-09 03:34:10 +08:00
2019-01-11 10:09:47 +08:00
# Port scanning
2019-01-01 07:14:12 +08:00
if ports_scanning is True :
2019-01-11 13:14:44 +08:00
print ( ' \n \n [*] Scanning ports (active). \n ' )
2018-12-16 11:07:37 +08:00
for x in full :
host = x . split ( ' : ' ) [ 1 ]
domain = x . split ( ' : ' ) [ 0 ]
2019-01-13 14:17:06 +08:00
if host != ' empty ' :
2019-01-11 13:14:44 +08:00
print ( ( ' [*] Scanning ' + host ) )
2018-12-27 15:43:32 +08:00
ports = [ 21 , 22 , 80 , 443 , 8080 ]
2018-12-16 11:07:37 +08:00
try :
2019-01-01 10:38:32 +08:00
scan = port_scanner . PortScan ( host , ports )
2018-12-16 11:07:37 +08:00
openports = scan . process ( )
if len ( openports ) > 1 :
2019-01-11 13:14:44 +08:00
print ( ( ' \t [*] Detected open ports: ' + ' , ' . join ( str ( e ) for e in openports ) ) )
2018-12-16 11:07:37 +08:00
takeover_check = ' True '
if takeover_check == ' True ' :
if len ( openports ) > 0 :
search_take = takeover . take_over ( domain )
search_take . process ( )
except Exception as e :
print ( e )
2019-01-01 07:14:12 +08:00
# DNS reverse lookup
2014-12-17 07:25:12 +08:00
dnsrev = [ ]
2019-01-01 07:14:12 +08:00
if dnslookup is True :
2019-01-11 13:14:44 +08:00
print ( ' \n [*] Starting active queries. ' )
2014-12-17 07:25:12 +08:00
analyzed_ranges = [ ]
2018-04-16 19:55:52 +08:00
for x in host_ip :
2018-11-23 05:20:06 +08:00
print ( x )
2019-01-13 14:17:06 +08:00
ip = x . split ( ' : ' ) [ 0 ]
range = ip . split ( ' . ' )
range [ 3 ] = ' 0/24 '
2018-11-23 05:20:06 +08:00
s = ' . '
range = s . join ( range )
2014-12-17 07:25:12 +08:00
if not analyzed_ranges . count ( range ) :
2019-01-23 23:59:11 +08:00
print ( ' [*] Performing reverse lookup in ' + range )
2014-12-17 07:25:12 +08:00
a = dnssearch . dns_reverse ( range , True )
a . list ( )
res = a . process ( )
analyzed_ranges . append ( range )
else :
continue
for x in res :
if x . count ( word ) :
dnsrev . append ( x )
if x not in full :
full . append ( x )
2019-01-27 09:37:16 +08:00
print ( ' [*] Hosts found after reverse lookup (in target domain): ' )
print ( ' -------------------------------------------------------- ' )
2014-12-17 07:25:12 +08:00
for xh in dnsrev :
2018-11-23 05:20:06 +08:00
print ( xh )
2018-12-16 11:07:37 +08:00
2019-01-01 07:14:12 +08:00
# DNS TLD expansion
2014-12-17 07:25:12 +08:00
dnstldres = [ ]
2019-01-06 17:50:07 +08:00
if dnstld is True :
2019-01-11 13:14:44 +08:00
print ( ' [*] Starting DNS TLD expansion. ' )
2014-12-17 07:25:12 +08:00
a = dnssearch . dns_tld ( word , dnsserver , verbose = True )
res = a . process ( )
2019-01-11 13:14:44 +08:00
print ( ' \n [*] Hosts found after DNS TLD expansion: ' )
print ( ' ---------------------------------------- ' )
2014-12-17 07:25:12 +08:00
for y in res :
2018-11-23 05:20:06 +08:00
print ( y )
2014-12-17 07:25:12 +08:00
dnstldres . append ( y )
if y not in full :
full . append ( y )
2019-01-01 07:14:12 +08:00
# Virtual hosts search
2019-01-13 14:17:06 +08:00
if virtual == ' basic ' :
2019-01-11 13:14:44 +08:00
print ( ' \n [*] Virtual hosts: ' )
print ( ' ------------------ ' )
2014-12-17 07:25:12 +08:00
for l in host_ip :
2019-01-06 17:50:07 +08:00
search = bingsearch . SearchBing ( l , limit , start )
2014-12-17 07:25:12 +08:00
search . process_vhost ( )
res = search . get_allhostnames ( )
for x in res :
2018-12-16 11:07:37 +08:00
x = re . sub ( r ' [[ \ < \ /?]*[ \ w]*>]* ' , ' ' , x )
x = re . sub ( ' < ' , ' ' , x )
x = re . sub ( ' > ' , ' ' , x )
2019-01-13 14:17:06 +08:00
print ( ( l + ' \t ' + x ) )
vhost . append ( l + ' : ' + x )
full . append ( l + ' : ' + x )
2018-12-16 11:07:37 +08:00
vhost = sorted ( set ( vhost ) )
2014-12-17 07:25:12 +08:00
else :
pass
2018-12-27 15:43:32 +08:00
2019-01-11 10:09:47 +08:00
# Shodan
2014-12-17 07:25:12 +08:00
shodanres = [ ]
2019-01-01 07:37:47 +08:00
if shodan is True :
2019-01-21 05:13:18 +08:00
import texttable
tab = texttable . Texttable ( )
header = [ ' IP address ' , ' Hostname ' , ' Org ' , ' Services:Ports ' , ' Technologies ' ]
tab . header ( header )
tab . set_cols_align ( [ ' c ' , ' c ' , ' c ' , ' c ' , ' c ' ] )
tab . set_cols_valign ( [ ' m ' , ' m ' , ' m ' , ' m ' , ' m ' ] )
tab . set_chars ( [ ' - ' , ' | ' , ' + ' , ' # ' ] )
tab . set_cols_width ( [ 15 , 20 , 15 , 15 , 18 ] )
host_ip = list ( set ( host_ip ) )
2019-01-27 09:37:16 +08:00
print ( ' \033 [94m[*] Searching Shodan. \033 [0m ' )
2019-01-05 00:28:11 +08:00
try :
for ip in host_ip :
2019-01-27 09:37:16 +08:00
print ( ( ' \t Searching for ' + ip ) )
2019-01-05 00:28:11 +08:00
shodan = shodansearch . search_shodan ( )
rowdata = shodan . search_ip ( ip )
time . sleep ( 2 )
tab . add_row ( rowdata )
printedtable = tab . draw ( )
print ( printedtable )
except Exception as e :
2019-01-27 09:37:16 +08:00
print ( f ' \033 [93m[!] Error occurred in the Shodan search module: { e } \033 [0m ' )
2018-10-27 03:42:47 +08:00
else :
pass
2014-12-17 07:25:12 +08:00
2018-12-23 04:29:11 +08:00
# Here we need to add explosion mode.
2019-01-11 10:09:47 +08:00
# We have to take out the TLDs to do this.
2014-12-17 07:25:12 +08:00
recursion = None
if recursion :
start = 0
for word in vhost :
2018-10-27 04:15:43 +08:00
search = googlesearch . search_google ( word , limit , start )
search . process ( google_dorking )
2014-12-17 07:25:12 +08:00
emails = search . get_emails ( )
hosts = search . get_hostnames ( )
2018-11-23 05:20:06 +08:00
print ( emails )
print ( hosts )
2014-12-17 07:25:12 +08:00
else :
pass
2019-01-01 07:14:12 +08:00
# Reporting
2014-12-17 07:25:12 +08:00
if filename != " " :
try :
2019-01-21 05:13:18 +08:00
print ( ' \n NEW REPORTING BEGINS. ' )
2018-12-16 01:22:02 +08:00
db = stash . stash_manager ( )
scanboarddata = db . getscanboarddata ( )
2018-12-19 17:08:42 +08:00
latestscanresults = db . getlatestscanresults ( word )
2019-01-11 11:56:49 +08:00
previousscanresults = db . getlatestscanresults ( word , previousday = True )
2018-12-19 17:08:42 +08:00
latestscanchartdata = db . latestscanchartdata ( word )
2018-12-17 00:37:36 +08:00
scanhistorydomain = db . getscanhistorydomain ( word )
2018-12-19 17:08:42 +08:00
pluginscanstatistics = db . getpluginscanstatistics ( )
2018-12-16 01:22:02 +08:00
generator = statichtmlgenerator . htmlgenerator ( word )
2018-12-19 17:08:42 +08:00
HTMLcode = generator . beginhtml ( )
2018-12-19 17:09:01 +08:00
HTMLcode + = generator . generatelatestscanresults ( latestscanresults )
2019-01-11 11:56:49 +08:00
HTMLcode + = generator . generatepreviousscanresults ( previousscanresults )
2019-01-22 04:46:10 +08:00
graph = reportgraph . GraphGenerator ( word )
2018-12-19 17:08:42 +08:00
HTMLcode + = graph . drawlatestscangraph ( word , latestscanchartdata )
2019-01-11 11:56:49 +08:00
HTMLcode + = graph . drawscattergraphscanhistory ( word , scanhistorydomain )
HTMLcode + = generator . generatepluginscanstatistics ( pluginscanstatistics )
2018-12-23 21:13:08 +08:00
HTMLcode + = generator . generatedashboardcode ( scanboarddata )
2018-12-24 04:23:01 +08:00
HTMLcode + = ' <p><span style= " color: #000000; " >Report generated on ' + str (
datetime . datetime . now ( ) ) + ' </span></p> '
2018-12-20 03:39:33 +08:00
HTMLcode + = '''
< / body >
< / html >
'''
2019-01-13 14:17:06 +08:00
Html_file = open ( ' report.html ' , ' w ' )
2018-12-16 01:22:02 +08:00
Html_file . write ( HTMLcode )
Html_file . close ( )
2019-01-11 13:14:44 +08:00
print ( ' NEW REPORTING FINISHED! ' )
print ( ' [*] Saving files. ' )
2019-01-23 23:59:11 +08:00
html = htmlExport . htmlExport (
all_emails ,
full ,
vhost ,
dnsres ,
dnsrev ,
filename ,
word ,
shodanres ,
dnstldres )
2014-12-17 07:25:12 +08:00
save = html . writehtml ( )
except Exception as e :
2018-11-23 05:20:06 +08:00
print ( e )
2019-01-27 09:37:16 +08:00
print ( ' \n \033 [93m[!] An error occurred creating the file. \033 [0m ' )
2014-12-17 07:25:12 +08:00
try :
2019-01-13 14:17:06 +08:00
filename = filename . split ( ' . ' ) [ 0 ] + ' .xml '
2014-12-17 07:25:12 +08:00
file = open ( filename , ' w ' )
file . write ( ' <?xml version= " 1.0 " encoding= " UTF-8 " ?><theHarvester> ' )
for x in all_emails :
file . write ( ' <email> ' + x + ' </email> ' )
2016-02-13 19:56:21 +08:00
for x in full :
2019-01-13 14:17:06 +08:00
x = x . split ( ' : ' )
2016-02-13 19:56:21 +08:00
if len ( x ) == 2 :
2019-01-05 00:28:11 +08:00
file . write (
' <host> ' + ' <ip> ' + x [ 1 ] + ' </ip><hostname> ' + x [ 0 ] + ' </hostname> ' + ' </host> ' )
2016-02-13 19:56:21 +08:00
else :
file . write ( ' <host> ' + x + ' </host> ' )
2014-12-17 07:25:12 +08:00
for x in vhost :
2019-01-13 14:17:06 +08:00
x = x . split ( ' : ' )
2016-02-13 19:56:21 +08:00
if len ( x ) == 2 :
2019-01-05 00:28:11 +08:00
file . write (
' <vhost> ' + ' <ip> ' + x [ 1 ] + ' </ip><hostname> ' + x [ 0 ] + ' </hostname> ' + ' </vhost> ' )
2016-02-13 19:56:21 +08:00
else :
file . write ( ' <vhost> ' + x + ' </vhost> ' )
if shodanres != [ ] :
shodanalysis = [ ]
for x in shodanres :
2019-01-13 14:17:06 +08:00
res = x . split ( ' SAPO ' )
2016-02-13 19:56:21 +08:00
file . write ( ' <shodan> ' )
file . write ( ' <host> ' + res [ 0 ] + ' </host> ' )
file . write ( ' <port> ' + res [ 2 ] + ' </port> ' )
file . write ( ' <banner><!-- ' + res [ 1 ] + ' --></banner> ' )
reg_server = re . compile ( ' Server:.* ' )
temp = reg_server . findall ( res [ 1 ] )
if temp != [ ] :
2019-01-13 14:17:06 +08:00
shodanalysis . append ( res [ 0 ] + ' : ' + temp [ 0 ] )
2016-02-13 19:56:21 +08:00
file . write ( ' </shodan> ' )
if shodanalysis != [ ] :
2018-12-16 11:07:37 +08:00
shodanalysis = sorted ( set ( shodanalysis ) )
2016-02-13 19:56:21 +08:00
file . write ( ' <servers> ' )
for x in shodanalysis :
file . write ( ' <server> ' + x + ' </server> ' )
file . write ( ' </servers> ' )
2018-12-23 04:29:11 +08:00
2014-12-17 07:25:12 +08:00
file . write ( ' </theHarvester> ' )
2016-03-05 23:25:44 +08:00
file . flush ( )
file . close ( )
2019-01-27 09:37:16 +08:00
print ( ' [*] Files saved. ' )
2014-12-17 07:25:12 +08:00
except Exception as er :
2019-01-27 09:37:16 +08:00
print ( f ' \033 [93m[!] An error occurred saving XML file: { er } \033 [0m ' )
2019-01-11 15:21:45 +08:00
print ( ' \n \n ' )
sys . exit ( 0 )
2014-12-17 07:25:12 +08:00
2018-12-16 11:07:37 +08:00
2019-01-13 14:17:06 +08:00
if __name__ == ' __main__ ' :
2019-01-20 11:02:29 +08:00
if python_version ( ) [ 0 : 3 ] < ' 3.6 ' :
2019-01-27 09:37:16 +08:00
print ( ' \033 [93m[!] Make sure you have Python 3.6+ installed, quitting. \033 [0m ' )
2019-01-20 11:02:29 +08:00
sys . exit ( 1 )
2014-12-17 07:25:12 +08:00
try :
2019-01-14 10:11:23 +08:00
start ( )
2014-12-17 07:25:12 +08:00
except KeyboardInterrupt :
2019-01-23 23:59:11 +08:00
print ( ' \n \n \033 [93m[!] ctrl+c detected from user, quitting. \n \n \033 [0m ' )
2018-11-23 05:20:06 +08:00
except Exception :
import traceback
2019-01-24 02:47:48 +08:00
2018-11-23 05:20:06 +08:00
print ( traceback . print_exc ( ) )
2019-01-18 06:05:10 +08:00
sys . exit ( 1 )