12
12
import argparse
13
13
import requests
14
14
import traceback
15
- from os import path , kill , mkdir
15
+ from os import path , kill , mkdir , getenv , environ
16
16
from json import loads , decoder
17
17
from packaging import version
18
+ import utils
18
19
19
20
parser = argparse .ArgumentParser ()
20
21
parser .add_argument ('-k' , '--kml' , help = 'KML filename' )
21
22
parser .add_argument ('-p' , '--port' , type = int , default = 8080 , help = 'Web server port [ Default : 8080 ]' )
22
23
parser .add_argument ('-u' , '--update' , action = 'store_true' , help = 'Check for updates' )
23
24
parser .add_argument ('-v' , '--version' , action = 'store_true' , help = 'Prints version' )
25
+ parser .add_argument ('-t' , '--template' , type = int , help = 'Load template and loads parameters from env variables' )
26
+ parser .add_argument ('-d' , '--debugHTTP' , type = bool , default = False , help = 'Disable HTTPS redirection for testing only' )
27
+
24
28
25
29
args = parser .parse_args ()
26
30
kml_fname = args .kml
27
- port = args .port
31
+ port = getenv ( "PORT" ) or args .port
28
32
chk_upd = args .update
29
33
print_v = args .version
34
+ if (getenv ("DEBUG_HTTP" ) and (getenv ("DEBUG_HTTP" ) == "1" or getenv ("DEBUG_HTTP" ).lower () == "true" )) or args .debugHTTP == True :
35
+ environ ["DEBUG_HTTP" ] = "1"
36
+ else :
37
+ environ ["DEBUG_HTTP" ] = "0"
38
+
39
+ templateNum = int (getenv ("TEMPLATE" )) if getenv ("TEMPLATE" ) and getenv ("TEMPLATE" ).isnumeric () else args .template
40
+
30
41
31
42
path_to_script = path .dirname (path .realpath (__file__ ))
32
43
51
62
52
63
def chk_update ():
53
64
try :
54
- print ('> Fetching Metadata...' , end = '' , flush = True )
65
+ print ('> Fetching Metadata...' , end = '' )
55
66
rqst = requests .get (META_URL , timeout = 5 )
56
67
meta_sc = rqst .status_code
57
68
if meta_sc == 200 :
@@ -64,15 +75,15 @@ def chk_update():
64
75
else :
65
76
print ('> Already up to date.' )
66
77
except Exception as exc :
67
- print (f'Exception : { str (exc )} ' )
78
+ utils . print (f'Exception : { str (exc )} ' )
68
79
69
80
70
81
if chk_upd is True :
71
82
chk_update ()
72
83
sys .exit ()
73
84
74
85
if print_v is True :
75
- print (VERSION )
86
+ utils . print (VERSION )
76
87
sys .exit ()
77
88
78
89
import importlib
@@ -96,15 +107,15 @@ def banner():
96
107
\___ \ \ ___/\ ___/ | < \ ___/ | | \/
97
108
/____ > \___ >\___ >|__|_ \ \___ >|__|
98
109
\/ \/ \/ \/ \/'''
99
- print (f'{ G } { art } { W } \n ' )
100
- print (f'{ G } [>] { C } Created By : { W } thewhiteh4t' )
101
- print (f'{ G } |---> { C } Twitter : { W } { twitter_url } ' )
102
- print (f'{ G } |---> { C } Community : { W } { comms_url } ' )
103
- print (f'{ G } [>] { C } Version : { W } { VERSION } \n ' )
110
+ utils . print (f'{ G } { art } { W } \n ' )
111
+ utils . print (f'{ G } [>] { C } Created By : { W } thewhiteh4t' )
112
+ utils . print (f'{ G } |---> { C } Twitter : { W } { twitter_url } ' )
113
+ utils . print (f'{ G } |---> { C } Community : { W } { comms_url } ' )
114
+ utils . print (f'{ G } [>] { C } Version : { W } { VERSION } \n ' )
104
115
105
116
106
117
def template_select (site ):
107
- print (f'{ Y } [!] Select a Template :{ W } \n ' )
118
+ utils . print (f'{ Y } [!] Select a Template :{ W } \n ' )
108
119
109
120
with open (TEMPLATES_JSON , 'r' ) as templ :
110
121
templ_info = templ .read ()
@@ -113,28 +124,34 @@ def template_select(site):
113
124
114
125
for item in templ_json ['templates' ]:
115
126
name = item ['name' ]
116
- print (f'{ G } [{ templ_json ["templates" ].index (item )} ] { C } { name } { W } ' )
127
+ utils . print (f'{ G } [{ templ_json ["templates" ].index (item )} ] { C } { name } { W } ' )
117
128
118
129
try :
119
- selected = int (input (f'{ G } [>] { W } ' ))
130
+ selected = - 1
131
+ if templateNum is not None :
132
+ if templateNum >= 0 and templateNum < len (templ_json ['templates' ]):
133
+ selected = templateNum
134
+ utils .print (f'{ G } [+] { C } Template choosen :{ W } { templateNum } : ' + templ_json ['templates' ][templateNum ]["name" ])
135
+ else :
136
+ selected = int (input (f'{ G } [>] { W } ' ))
120
137
if selected < 0 :
121
138
print ()
122
- print (f'{ R } [-] { C } Invalid Input!{ W } ' )
139
+ utils . print (f'{ R } [-] { C } Invalid Input!{ W } ' )
123
140
sys .exit ()
124
141
except ValueError :
125
142
print ()
126
- print (f'{ R } [-] { C } Invalid Input!{ W } ' )
143
+ utils . print (f'{ R } [-] { C } Invalid Input!{ W } ' )
127
144
sys .exit ()
128
145
129
146
try :
130
147
site = templ_json ['templates' ][selected ]['dir_name' ]
131
148
except IndexError :
132
149
print ()
133
- print (f'{ R } [-] { C } Invalid Input!{ W } ' )
150
+ utils . print (f'{ R } [-] { C } Invalid Input!{ W } ' )
134
151
sys .exit ()
135
152
136
153
print ()
137
- print (f'{ G } [+] { C } Loading { Y } { templ_json ["templates" ][selected ]["name" ]} { C } Template...{ W } ' )
154
+ utils . print (f'{ G } [+] { C } Loading { Y } { templ_json ["templates" ][selected ]["name" ]} { C } Template...{ W } ' )
138
155
139
156
module = templ_json ['templates' ][selected ]['module' ]
140
157
if module is True :
@@ -148,8 +165,8 @@ def template_select(site):
148
165
def server ():
149
166
print ()
150
167
preoc = False
151
- print (f'{ G } [+] { C } Port : { W } { port } \n ' )
152
- print (f'{ G } [+] { C } Starting PHP Server...{ W } ' , end = '' , flush = True )
168
+ utils . print (f'{ G } [+] { C } Port : { W } { port } \n ' )
169
+ utils . print (f'{ G } [+] { C } Starting PHP Server...{ W } ' , end = '' )
153
170
cmd = ['php' , '-S' , f'0.0.0.0:{ port } ' , '-t' , f'template/{ SITE } /' ]
154
171
155
172
with open (LOG_FILE , 'w+' ) as phplog :
@@ -163,17 +180,17 @@ def server():
163
180
php_sc = php_rqst .status_code
164
181
if php_sc == 200 :
165
182
if preoc :
166
- print (f'{ C } [ { G } ✔{ C } ]{ W } ' )
167
- print (f'{ Y } [!] Server is already running!{ W } ' )
183
+ utils . print (f'{ C } [ { G } ✔{ C } ]{ W } ' )
184
+ utils . print (f'{ Y } [!] Server is already running!{ W } ' )
168
185
print ()
169
186
else :
170
- print (f'{ C } [ { G } ✔{ C } ]{ W } ' )
187
+ utils . print (f'{ C } [ { G } ✔{ C } ]{ W } ' )
171
188
print ()
172
189
else :
173
- print (f'{ C } [ { R } Status : { php_sc } { C } ]{ W } ' )
190
+ utils . print (f'{ C } [ { R } Status : { php_sc } { C } ]{ W } ' )
174
191
cl_quit (proc )
175
192
except requests .ConnectionError :
176
- print (f'{ C } [ { R } ✘{ C } ]{ W } ' )
193
+ utils . print (f'{ C } [ { R } ✘{ C } ]{ W } ' )
177
194
cl_quit (proc )
178
195
return proc
179
196
@@ -184,7 +201,7 @@ def wait():
184
201
sleep (2 )
185
202
size = path .getsize (RESULT )
186
203
if size == 0 and printed is False :
187
- print (f'{ G } [+] { C } Waiting for Client...{ Y } [ctrl+c to exit]{ W } \n ' )
204
+ utils . print (f'{ G } [+] { C } Waiting for Client...{ Y } [ctrl+c to exit]{ W } \n ' )
188
205
printed = True
189
206
if size > 0 :
190
207
data_parser ()
@@ -198,7 +215,7 @@ def data_parser():
198
215
try :
199
216
info_json = loads (info_file )
200
217
except decoder .JSONDecodeError :
201
- print (f'{ R } [-] { C } Exception : { R } { traceback .format_exc ()} { W } ' )
218
+ utils . print (f'{ R } [-] { C } Exception : { R } { traceback .format_exc ()} { W } ' )
202
219
else :
203
220
var_os = info_json ['os' ]
204
221
var_platform = info_json ['platform' ]
@@ -212,7 +229,7 @@ def data_parser():
212
229
213
230
data_row .extend ([var_os , var_platform , var_cores , var_ram , var_vendor , var_render , var_res , var_browser , var_ip ])
214
231
215
- print (f'''{ Y } [!] Device Information :{ W }
232
+ utils . print (f'''{ Y } [!] Device Information :{ W }
216
233
217
234
{ G } [+] { C } OS : { W } { var_os }
218
235
{ G } [+] { C } Platform : { W } { var_platform }
@@ -226,7 +243,7 @@ def data_parser():
226
243
''' )
227
244
228
245
if ip_address (var_ip ).is_private :
229
- print (f'{ Y } [!] Skipping IP recon because IP address is private{ W } ' )
246
+ utils . print (f'{ Y } [!] Skipping IP recon because IP address is private{ W } ' )
230
247
else :
231
248
rqst = requests .get (f'https://ipwhois.app/json/{ var_ip } ' )
232
249
s_code = rqst .status_code
@@ -243,7 +260,7 @@ def data_parser():
243
260
244
261
data_row .extend ([var_continent , var_country , var_region , var_city , var_org , var_isp ])
245
262
246
- print (f'''{ Y } [!] IP Information :{ W }
263
+ utils . print (f'''{ Y } [!] IP Information :{ W }
247
264
248
265
{ G } [+] { C } Continent : { W } { var_continent }
249
266
{ G } [+] { C } Country : { W } { var_country }
@@ -258,7 +275,7 @@ def data_parser():
258
275
try :
259
276
result_json = loads (results )
260
277
except decoder .JSONDecodeError :
261
- print (f'{ R } [-] { C } Exception : { R } { traceback .format_exc ()} { W } ' )
278
+ utils . print (f'{ R } [-] { C } Exception : { R } { traceback .format_exc ()} { W } ' )
262
279
else :
263
280
status = result_json ['status' ]
264
281
if status == 'success' :
@@ -271,7 +288,7 @@ def data_parser():
271
288
272
289
data_row .extend ([var_lat , var_lon , var_acc , var_alt , var_dir , var_spd ])
273
290
274
- print (f'''{ Y } [!] Location Information :{ W }
291
+ utils . print (f'''{ Y } [!] Location Information :{ W }
275
292
276
293
{ G } [+] { C } Latitude : { W } { var_lat }
277
294
{ G } [+] { C } Longitude : { W } { var_lon }
@@ -281,13 +298,13 @@ def data_parser():
281
298
{ G } [+] { C } Speed : { W } { var_spd }
282
299
''' )
283
300
284
- print (f'{ G } [+] { C } Google Maps : { W } https://www.google.com/maps/place/{ var_lat .strip (" deg" )} +{ var_lon .strip (" deg" )} ' )
301
+ utils . print (f'{ G } [+] { C } Google Maps : { W } https://www.google.com/maps/place/{ var_lat .strip (" deg" )} +{ var_lon .strip (" deg" )} ' )
285
302
286
303
if kml_fname is not None :
287
304
kmlout (var_lat , var_lon )
288
305
else :
289
306
var_err = result_json ['error' ]
290
- print (f'{ R } [-] { C } { var_err } \n ' )
307
+ utils . print (f'{ R } [-] { C } { var_err } \n ' )
291
308
292
309
csvout (data_row )
293
310
clear ()
@@ -304,15 +321,15 @@ def kmlout(var_lat, var_lon):
304
321
with open (f'{ path_to_script } /{ kml_fname } .kml' , 'w' ) as kml_gen :
305
322
kml_gen .write (kml_sample_data )
306
323
307
- print (f'{ Y } [!] KML File Generated!{ W } ' )
308
- print (f'{ G } [+] { C } Path : { W } { path_to_script } /{ kml_fname } .kml' )
324
+ utils . print (f'{ Y } [!] KML File Generated!{ W } ' )
325
+ utils . print (f'{ G } [+] { C } Path : { W } { path_to_script } /{ kml_fname } .kml' )
309
326
310
327
311
328
def csvout (row ):
312
329
with open (DATA_FILE , 'a' ) as csvfile :
313
330
csvwriter = writer (csvfile )
314
331
csvwriter .writerow (row )
315
- print (f'{ G } [+] { C } Data Saved : { W } { path_to_script } /db/results.csv\n ' )
332
+ utils . print (f'{ G } [+] { C } Data Saved : { W } { path_to_script } /db/results.csv\n ' )
316
333
317
334
318
335
def clear ():
@@ -342,7 +359,7 @@ def cl_quit(proc):
342
359
wait ()
343
360
data_parser ()
344
361
except KeyboardInterrupt :
345
- print (f'{ R } [-] { C } Keyboard Interrupt.{ W } ' )
362
+ utils . print (f'{ R } [-] { C } Keyboard Interrupt.{ W } ' )
346
363
cl_quit (SERVER_PROC )
347
364
else :
348
365
repeat ()
0 commit comments