-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.py
375 lines (304 loc) · 11.4 KB
/
main.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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
import ctypes
import os
import subprocess
import sys
import webbrowser
sys.path.insert(1, '.\\scripts')
from bgpRouting import *
from common import *
from crypto import *
from deploy import *
from fping import *
from fwall import *
from interfaces import *
from ipconf import *
from showExcept import *
from sshSet import *
from tcp import *
from updateWindows import *
from winInstallers import *
import helpDict
import manual
import showDict
import webDict
import winOsDict
import winPopenDict
def parse_file(filepath):
with open(filepath) as file:
split_file = file.read().split('\n')
return split_file
# Command lists
CRYPTO_GENERAL = parse_file('.\\command-sets\\cryptoCmds.txt')
CRYPTO_IPSEC = parse_file('.\\command-sets\\cryptoIpsecCmds.txt')
CRYPTO_PPTP = parse_file('.\\command-sets\\cryptoPptpCmds.txt')
FWALL_GENERAL = parse_file('.\\command-sets\\fwallCmds.txt')
FWALL_SHOW = parse_file('.\\command-sets\\fwallShowCmds.txt')
INSTALL_CMDS = parse_file('.\\command-sets\\installCmds.txt')
UNINSTALL_CMDS = parse_file('.\\command-sets\\uninstallCmds.txt')
IP_CMDS = parse_file('.\\command-sets\\ipCmds.txt')
SHOW_CMDS = parse_file('.\\command-sets\\showCmds.txt')
WIN_OS_CMDS = parse_file('.\\command-sets\\winOsCmds.txt')
WIN_POPEN_CMDS = parse_file('.\\command-sets\\winPopenCmds.txt')
SSH_CMDS = parse_file('.\\command-sets\\sshCmds.txt')
# Check to see if user ran Igloo as admin
def admin_check():
is_an_admin = ctypes.windll.shell32.IsUserAnAdmin()
if is_an_admin == False:
with open('.\\miscellaneous\\no_admin.txt', 'r') as file:
print(file.read())
cli()
sys.exit()
# Return current username
def who_am_i():
get_username = pshell_decoder('whoami')
format_username = get_username.split("\\", 1)[1].strip()
return format_username
def check_pshell_profile():
# creates powershell alias for igloo upon launch.
# skip this process if execution policy is resrictive.
try:
exec_policy = pshell_decoder('Get-ExecutionPolicy')
with open('C:\\Windows\\System32\\\
WindowsPowerShell\\v1.0\\profile.ps1', 'r') as file:
# format the file
read_file = file.read()
split_file = read_file.split('\n')
ticker = 1
for line in split_file:
ticker = ticker + 1
if line == 'Set-Alias -Name igloo -Value \'.\\igloo.exe\'':
ps_file = 0
break
else:
ps_file = 1
if len(split_file) == ticker - 1 and ps_file == 1:
with open('C:\\Windows\\System32\\WindowsPowerShell\
\\v1.0\\profile.ps1', 'a') as file:
file.write('\nSet-Alias -Name igloo -Value \
\'.\\igloo.exe\'')
else:
pass
except FileNotFoundError:
if 'Restricted' in exec_policy:
pass
else:
with open('C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\\
profile.ps1', 'w+') as file:
file.write('Set-Alias -Name igloo -Value \'.\\igloo.exe\'')
# Search winOsDict.py for relevant command
def win_os_tree(win_os_command):
try:
for command in winOsDict.win_os_command_set:
if command == win_os_command:
os.system(winOsDict.win_os_command_set.get(command))
else:
pass
except:
pass
# Search winPopenDict.py for relevant command.
def win_popen_tree(win_popen_command):
try:
for command in winPopenDict.win_popen_command_set:
if command == win_popen_command:
subprocess.Popen(winPopenDict.win_popen_command_set.get(command))
else:
pass
if win_popen_command == 'win reboot':
reboot_loop_keepalive = 1
newline()
while reboot_loop_keepalive == 1:
reboot_confirm = input('confirm~! Are you sure you' \
+ 'want to reboot? (y/n) ')
if reboot_confirm in yes:
reboot_loop_keepalive = 0
subprocess.Popen('shutdown /r /t 0')
elif reboot_confirm in no:
reboot_loop_keepalive = 0
newline()
print('notify~! Reboot cancelled.')
newline()
else:
pass
except:
pass
def crypto_tree(crypto_command):
# User cmd is piped into this function if it matches
# a command in 'cryptoCmds.txt'. Most functions are
# called from crypto.py
if crypto_command in CRYPTO_IPSEC:
crypto_ipsec_options(crypto_command)
elif crypto_command in CRYPTO_PPTP:
crypto_pptp_options(crypto_command)
elif crypto_command == 'crypto generate psk':
generate_psk()
elif crypto_command == 'crypto generate rsa':
generate_rsa()
elif 'crypto del' in crypto_command:
split_command = crypto_command.split(' ')
if len(split_command) == 3:
vpn_name = split_command[2]
crypto_delete(vpn_name)
else:
pass
elif 'crypto connect' in crypto_command:
split_command = crypto_command.split(' ')
if len(split_command) == 3:
vpn_name = split_command[2]
crypto_go(vpn_name)
else:
pass
def cli():
prompt_keepalive = 1
while prompt_keepalive == 1:
try:
if len(sys.argv) > 1:
user_cmd = ' '.join(sys.argv[1:])
prompt_keepalive = 0
else:
user_cmd = input("igloo~$ ")
strip_cmd = user_cmd.rstrip()
split_cmd = strip_cmd.split(' ')
if strip_cmd in helpDict.help_dictionary:
newline()
for command in helpDict.help_dictionary:
if command == strip_cmd:
read_file(helpDict.help_dictionary.get(command))
elif strip_cmd in quit:
prompt_keepalive = 0
newline()
print('notify~! Exiting Igloo...')
newline()
time.sleep(1)
exit()
elif strip_cmd == 'igloo':
try:
newline()
try_exe = pshell_decoder('Start \'C:\\Program Files\
\\Igloo\\igloo.exe\'')
if 'Start' in try_exe:
print('error~! File not found!')
newline()
except:
newline()
print('error~! File not found.')
newline()
elif 'man' in strip_cmd:
for line in manual.manual_dictionary:
if line == strip_cmd:
key = manual.manual_dictionary.get(line)
newline()
print('notify~! Opening {} with default browser.\
'.format(key))
webbrowser.open_new(key)
newline()
elif strip_cmd == 'deploy ad-ds':
active_directory_deployment(strip_cmd)
elif strip_cmd == 'deploy bgp':
deploy_bgp()
elif strip_cmd in SHOW_CMDS:
show_tree(strip_cmd)
elif strip_cmd in WIN_OS_CMDS:
win_os_tree(strip_cmd)
elif strip_cmd in WIN_POPEN_CMDS:
win_popen_tree(strip_cmd)
elif strip_cmd in CRYPTO_GENERAL:
crypto_tree(strip_cmd)
elif 'bgp' in strip_cmd:
bgp_routing(strip_cmd)
elif 'crypto del' in strip_cmd:
crypto_tree(strip_cmd)
elif 'crypto connect' in strip_cmd:
crypto_tree(strip_cmd)
elif strip_cmd in FWALL_SHOW:
fwall_display(strip_cmd)
elif strip_cmd in FWALL_GENERAL:
fwall_toggle(strip_cmd)
elif 'fwall entry' in strip_cmd:
if len(split_cmd) == 7:
fwall_rule_config(split_cmd)
elif len(split_cmd) == 4 and split_cmd[0] == 'no':
fwall_delete(split_cmd)
else:
newline()
read_file('.\\help-files\\helpFwallEntry.txt')
elif strip_cmd in INSTALL_CMDS:
install_tree(strip_cmd)
elif strip_cmd in UNINSTALL_CMDS:
uninstall_tree(strip_cmd)
elif 'int' in strip_cmd:
int_tree(strip_cmd)
elif 'tcp scan' in strip_cmd:
tcp_scan(strip_cmd)
elif 'tcp ping' in strip_cmd:
tcp_ping(strip_cmd)
elif strip_cmd == 'tcp reset':
net_reset()
elif 'no ip route' in strip_cmd:
no_ip_route(strip_cmd)
elif 'ip route' in strip_cmd:
ip_route(strip_cmd)
elif 'ip route-cache' in strip_cmd:
ip_route_cache(strip_cmd)
elif 'ip ttl' in strip_cmd:
ip_ttl(strip_cmd)
elif 'ip address dhcp' in strip_cmd:
ip_address_dhcp(strip_cmd)
elif 'ip address' in strip_cmd:
ip_address_config(strip_cmd)
elif ('ip tcp window-restart' in strip_cmd
or 'ip tcp provider' in strip_cmd
or 'ip tcp port-range' in strip_cmd):
ip_tcp_config(strip_cmd)
elif strip_cmd in IP_CMDS:
ip_general(strip_cmd)
elif strip_cmd in SSH_CMDS:
if 'write' in strip_cmd:
ssh_write_init(strip_cmd)
elif 'show' in strip_cmd:
ssh_show_init(strip_cmd)
else:
pass
elif 'web' in strip_cmd:
for line in webDict.web_dictionary:
if line == strip_cmd:
key = webDict.web_dictionary.get(line)
newline()
print('notify~! Opening {} with default browser.\
'.format(key))
webbrowser.open_new(key)
newline()
else:
pass
elif strip_cmd == 'update':
update_windows()
elif 'fping' in strip_cmd:
fping_script()
elif split_cmd[0] in cmd_exe_options:
try:
os.system(strip_cmd)
newline()
except KeyboardInterrupt:
newline()
newline()
elif split_cmd[0] in pshell_exe_options:
try:
subprocess.call(['powershell.exe', strip_cmd])
newline()
except KeyboardInterrupt:
newline()
newline()
# Allows newlines/returns in the terminal
elif strip_cmd == '':
pass
else:
newline()
print('error~! Invalid command.')
newline()
except:
continue
admin_check()
check_pshell_profile()
if len(sys.argv) <= 1:
splash_screen()
cli()
sys.exit()