forked from thewhiteh4t/FinalRecon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfinalrecon.py
331 lines (289 loc) · 9.92 KB
/
finalrecon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/usr/bin/env python3
import os
import sys
import atexit
import importlib.util
R = '\033[31m' # red
G = '\033[32m' # green
C = '\033[36m' # cyan
W = '\033[0m' # white
pid_path = '/var/run/finalrecon.pid'
fail = False
if os.path.exists(pid_path):
print(R + '[-]' + C + ' One instance of FinalRecon is already running!' + W)
with open(pid_path, 'r') as pidfile:
pid = pidfile.read()
print(G + '[+]' + C + ' PID : ' + W + str(pid))
print(G + '[>]' + C + ' If FinalRecon crashed, execute : ' + W + 'sudo rm {}'.format(pid_path))
sys.exit()
else:
with open(pid_path, 'w') as pidfile:
pidfile.write(str(os.getpid()))
import platform
if platform.system() == 'Linux':
if os.geteuid() != 0:
print('\n' + R + '[-]' + C + ' Please Run as Root!' + '\n')
sys.exit()
else:
pass
else:
pass
path_to_script = os.path.dirname(os.path.realpath(__file__))
with open(path_to_script + '/requirements.txt', 'r') as rqr:
pkg_list = rqr.read().strip().split('\n')
print('\n' + G + '[+]' + C + ' Checking Dependencies...' + W + '\n')
for pkg in pkg_list:
spec = importlib.util.find_spec(pkg)
if spec is None:
print(R + '[-]' + W + ' {}'.format(pkg) + C + ' is not Installed!' + W)
fail = True
else:
pass
if fail == True:
print('\n' + R + '[-]' + C + ' Please Execute ' + W + 'pip3 install -r requirements.txt' + C + ' to Install Missing Packages' + W + '\n')
sys.exit()
import argparse
version = '1.0.8'
gh_version = ''
twitter_url = ''
discord_url = ''
parser = argparse.ArgumentParser(description='FinalRecon - The Last Recon Tool You Will Need | v{}'.format(version))
parser.add_argument('url', help='Target URL')
parser.add_argument('--headers', help='Header Information', action='store_true')
parser.add_argument('--sslinfo', help='SSL Certificate Information', action='store_true')
parser.add_argument('--whois', help='Whois Lookup', action='store_true')
parser.add_argument('--crawl', help='Crawl Target', action='store_true')
parser.add_argument('--dns', help='DNS Enumeration', action='store_true')
parser.add_argument('--sub', help='Sub-Domain Enumeration', action='store_true')
parser.add_argument('--trace', help='Traceroute', action='store_true')
parser.add_argument('--dir', help='Directory Search', action='store_true')
parser.add_argument('--ps', help='Fast Port Scan', action='store_true')
parser.add_argument('--full', help='Full Recon', action='store_true')
ext_help = parser.add_argument_group('Extra Options')
ext_help.add_argument('-t', type=int, help='Number of Threads [ Default : 30 ]')
ext_help.add_argument('-T', type=float, help='Request Timeout [ Default : 30.0 ]')
ext_help.add_argument('-w', help='Path to Wordlist [ Default : wordlists/dirb_common.txt ]')
ext_help.add_argument('-r', action='store_true', help='Allow Redirect [ Default : False ]')
ext_help.add_argument('-s', action='store_false', help='Toggle SSL Verification [ Default : True ]')
ext_help.add_argument('-sp', type=int, help='Specify SSL Port [ Default : 443 ]')
ext_help.add_argument('-d', help='Custom DNS Servers [ Default : 1.1.1.1 ]')
ext_help.add_argument('-e', help='File Extensions [ Example : txt, xml, php ]')
ext_help.add_argument('-m', help='Traceroute Mode [ Default : UDP ] [ Available : TCP, ICMP ]')
ext_help.add_argument('-p', type=int, help='Port for Traceroute [ Default : 80 / 33434 ]')
ext_help.add_argument('-tt', type=float, help='Traceroute Timeout [ Default : 1.0 ]')
ext_help.add_argument('-o', help='Export Output [ Default : txt ] [ Available : xml, csv ]')
ext_help.set_defaults(
t=30,
T=30.0,
w='wordlists/dirb_common.txt',
r=False,
s=True,
sp=443,
d='1.1.1.1',
e='',
m='UDP',
p=33434,
tt=1.0,
o='txt')
args = parser.parse_args()
target = args.url
headinfo = args.headers
sslinfo = args.sslinfo
whois = args.whois
crawl = args.crawl
dns = args.dns
trace = args.trace
dirrec = args.dir
pscan = args.ps
full = args.full
threads = args.t
tout = args.T
wdlist = args.w
redir = args.r
sslv = args.s
sslp = args.sp
dserv = args.d
filext = args.e
subd = args.sub
mode = args.m
port = args.p
tr_tout = args.tt
output = args.o
import json
import socket
import requests
import datetime
import ipaddress
import tldextract
type_ip = False
data = {}
meta = {}
def fetch_meta():
global gh_version, twitter_url, discord_url
try:
rqst = requests.get('https://raw.githubusercontent.com/thewhiteh4t/finalrecon/master/metadata.json', timeout=5)
sc = rqst.status_code
if sc == 200:
metadata = rqst.text
json_data = json.loads(metadata)
gh_version = json_data['metadata']['version']
twitter_url = json_data['metadata']['twitter']
discord_url = json_data['metadata']['discord']
else:
with open('metadata.json', 'r') as metadata:
json_data = json.loads(metadata.read())
gh_version = json_data['metadata']['version']
twitter_url = json_data['metadata']['twitter']
discord_url = json_data['metadata']['discord']
except Exception as exc:
print('\n' + R + '[-]' + C + ' Exception : ' + W + str(exc))
with open('metadata.json', 'r') as metadata:
json_data = json.loads(metadata.read())
gh_version = json_data['metadata']['version']
twitter_url = json_data['metadata']['twitter']
discord_url = json_data['metadata']['discord']
def banner():
banner = r'''
______ __ __ __ ______ __
/\ ___\/\ \ /\ "-.\ \ /\ __ \ /\ \
\ \ __\\ \ \\ \ \-. \\ \ __ \\ \ \____
\ \_\ \ \_\\ \_\\"\_\\ \_\ \_\\ \_____\
\/_/ \/_/ \/_/ \/_/ \/_/\/_/ \/_____/
______ ______ ______ ______ __ __
/\ == \ /\ ___\ /\ ___\ /\ __ \ /\ "-.\ \
\ \ __< \ \ __\ \ \ \____\ \ \/\ \\ \ \-. \
\ \_\ \_\\ \_____\\ \_____\\ \_____\\ \_\\"\_\
\/_/ /_/ \/_____/ \/_____/ \/_____/ \/_/ \/_/'''
print(G + banner + W + '\n')
print(G + '[>]' + C + ' Created By : ' + W + 'thewhiteh4t')
print(G + ' |---> ' + C + 'Twitter : ' + W + twitter_url)
print(G + ' |---> ' + C + 'Discord : ' + W + discord_url)
print(G + '[>]' + C + ' Version : ' + W + version + '\n')
def ver_check():
print(G + '[+]' + C + ' Checking for Updates...', end='')
if version == gh_version:
print(C + '[' + G + ' Up-To-Date ' + C +']' + '\n')
else:
print(C + '[' + G + ' Available : {} '.format(gh_version) + C + ']' + '\n')
def full_recon():
from modules.sslinfo import cert
from modules.crawler import crawler
from modules.headers import headers
from modules.dns import dnsrec
from modules.traceroute import troute
from modules.whois import whois_lookup
from modules.dirrec import hammer
from modules.portscan import ps
from modules.subdom import subdomains
headers(target, output, data)
cert(hostname, sslp, output, data)
whois_lookup(ip, output, data)
dnsrec(domain, output, data)
if type_ip == False:
subdomains(domain, tout, output, data)
else:
pass
troute(ip, mode, port, tr_tout, output, data)
ps(ip, output, data)
crawler(target, output, data)
hammer(target, threads, tout, wdlist, redir, sslv, dserv, output, data, filext)
try:
fetch_meta()
banner()
ver_check()
if target.startswith(('http', 'https')) == False:
print(R + '[-]' + C + ' Protocol Missing, Include ' + W + 'http://' + C + ' or ' + W + 'https://' + '\n')
sys.exit()
else:
pass
if target.endswith('/') == True:
target = target[:-1]
else:
pass
print (G + '[+]' + C + ' Target : ' + W + target)
ext = tldextract.extract(target)
domain = ext.registered_domain
hostname = '.'.join(part for part in ext if part)
try:
ipaddress.ip_address(hostname)
type_ip = True
ip = hostname
except:
try:
ip = socket.gethostbyname(hostname)
print ('\n' + G + '[+]' + C + ' IP Address : ' + W + str(ip))
except Exception as e:
print ('\n' + R + '[-]' + C + ' Unable to Get IP : ' + W + str(e))
sys.exit()
start_time = datetime.datetime.now()
meta.update({'Version': str(version)})
meta.update({'Date': str(datetime.date.today())})
meta.update({'Target': str(target)})
meta.update({'IP Address': str(ip)})
meta.update({'Start Time': str(start_time.strftime('%I:%M:%S %p'))})
data['module-FinalRecon'] = meta
if output != 'None':
fname = os.getcwd() + '/dumps/' + hostname + '.' + output
output = {
'format': output,
'file': fname,
'export': False
}
from modules.export import export
if full == True:
full_recon()
if headinfo == True:
from modules.headers import headers
headers(target, output, data)
if sslinfo == True:
from modules.sslinfo import cert
cert(hostname, sslp, output, data)
if whois == True:
from modules.whois import whois_lookup
whois_lookup(ip, output, data)
if crawl == True:
from modules.crawler import crawler
crawler(target, output, data)
if dns == True:
from modules.dns import dnsrec
dnsrec(domain, output, data)
if subd == True and type_ip == False:
from modules.subdom import subdomains
subdomains(domain, tout, output, data)
elif subd == True and type_ip == True:
print(R + '[-]' + C + ' Sub-Domain Enumeration is Not Supported for IP Addresses' + W + '\n')
sys.exit()
else:
pass
if trace == True:
from modules.traceroute import troute
if mode == 'TCP' and port == 33434:
port = 80
troute(ip, mode, port, tr_tout, output, data)
else:
troute(ip, mode, port, tr_tout, output, data)
if pscan == True:
from modules.portscan import ps
ps(ip, output, data)
if dirrec == True:
from modules.dirrec import hammer
hammer(target, threads, tout, wdlist, redir, sslv, dserv, output, data, filext)
if any([full, headinfo, sslinfo, whois, crawl, dns, subd, trace, pscan, dirrec]) != True:
print ('\n' + R + '[-] Error : ' + C + 'Atleast One Argument is Required with URL' + W)
output = 'None'
sys.exit()
end_time = datetime.datetime.now() - start_time
print ('\n' + G + '[+]' + C + ' Completed in ' + W + str(end_time) + '\n')
@atexit.register
def call_export():
meta.update({'End Time': str(datetime.datetime.now().strftime('%I:%M:%S %p'))})
meta.update({'Completion Time': str(end_time)})
if output != 'None':
output['export'] = True
export(output, data)
os.remove(pid_path)
sys.exit()
except KeyboardInterrupt:
print (R + '[-]' + C + ' Keyboard Interrupt.' + W + '\n')
os.remove(pid_path)
sys.exit()