Skip to content

Instantly share code, notes, and snippets.

@lowk3v
Last active October 12, 2019 14:00
Show Gist options
  • Save lowk3v/9b0a937b173e715417886515d77cdfa4 to your computer and use it in GitHub Desktop.
Save lowk3v/9b0a937b173e715417886515d77cdfa4 to your computer and use it in GitHub Desktop.
Information gathering: real ip, server deploy
#!/usr/bin/python3
# Version: 2.0
# Author: Kev
import os
import sys
import threading
import datetime
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import requests
NORMAL_HEADER = ['vary', 'Expires', 'Cache-Control', 'Content-Encoding', 'Content-Encoding', 'Host', 'User-Agent', 'Accept', 'Accept-Language', 'Referer', 'Content-Type', 'Content-Length', 'Connection', 'Cookie', 'Set-Cookie', 'Keep-Alive', 'Date', 'Strict-Transport-Security',
]
def color(string, color):
nc = '\033[0m'
color_list = {
'light gray': '\033[0;37m%s'+nc,
'red': '\033[0;31m%s'+nc,
'green': '\033[0;32m%s'+nc,
'blue': '\033[0;34m%s'+nc,
}
if color in color_list: return color_list[color] % string
return string
def http_code(code):
color_code = {
'200': color('200', 'green'),
'302': color('302', 'light gray'),
'403': color('302', 'red'),
'404': color('404', 'light gray'),
}
if code in color_code: return color_code[code]
return code
def gathering(target, custom_port=''):
global NORMAL_HEADER, COLOR
# Check port 80, 443 and custom port only
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
if target == 'Not Found': return ''
else: target = target + ':' + custom_port
try: res = requests.get('https://'+target, verify=False, timeout=3)
except:
try: res = requests.get('http://'+target, timeout=3)
except: return ''
# Check interesting header is exists
for header in NORMAL_HEADER:
if header in res.headers: del res.headers[header]
return ('{code} -- {header}'.format(
code=http_code(str(res.status_code)),
header='; '.join('{}: {}'.format(color(key, 'green'), value) for key, value in res.headers.items())
),
'{code} -- {header}'.format(
code=str(res.status_code),
header='; '.join('{}: {}'.format(key, value) for key, value in res.headers.items())
)
)
def rFile(filename):
f = open(filename, "rb")
for line in f:
domain, ip = line.split(b',')
yield (domain.strip().decode(), ip.strip().decode())
f.close()
def logging(ip, domains):
global output_file
for domain in domains:
hdr_rich, hdr_raw = gathering(domain)
if domains.index(domain) == 0:
print("{: <31} {: <60} {: <20}".format(color(ip, 'red'), domain, hdr_rich))
print("{: <20} {: <50} {: <20}".format(ip, domain, hdr_raw), file=open(output_file, 'a'))
else:
print("{: <20} {: <60} {: <20}".format('', domain, hdr_rich))
print("{: <20} {: <50} {: <20}".format('', domain, hdr_raw), file=open(output_file, 'a'))
def _try():
global hosts, totalline
group_by_ip = dict()
while True:
try:
domain, ip = hosts.__next__()
if ip in group_by_ip:
group_by_ip[ip].append(domain)
else:
group_by_ip[ip] = []
except StopIteration:
break
for ip in group_by_ip:
logging(ip, group_by_ip[ip])
if __name__ == '__main__':
if len(sys.argv) < 2:
print('Tool render from result hosts.txt of Aquatone-discovery')
print(sys.argv[0] + " " + color('HOST', 'green') + " " + color('OUTPUT FILE', 'green'))
sys.exit()
if len(sys.argv) == 2:
output_file = './output_' + datetime.datetime.now().strftime('%d_%M_%S')
else:
output_file = sys.argv[2]
input_file = os.environ['HOME'] + '/aquatone/' + sys.argv[1] + '/hosts.txt'
# Check run Aquatone-discovery before
if not os.path.isfile(input_file):
print(color('Run Aquatone-discovery Before', 'green'))
sys.exit()
#
totalline = 0
with open(input_file,'r') as f:
for _ in f: totalline += 1
print(totalline, 'The result is saved into '+output_file)
#
hosts = rFile(input_file)
for i in range(20):
threading.Thread(target=_try).start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment