-
Notifications
You must be signed in to change notification settings - Fork 2
/
netengine.py
executable file
·163 lines (138 loc) · 4.2 KB
/
netengine.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
#!/usr/bin/env python
import config
import copy
import man_pages
import signal
import sys
LANGUAGES_SUPPORTED = ["en", "es"]
LANGUAGE_SELECTION = "en"
CURRENT_IP = next(iter(config.machines))
CURRENT_MACHINE_CONFIG = {}
CMDS = {
"man": {
"num_params": 1,
"run": lambda arg: man_pages.show_man_page(arg, LANGUAGE_SELECTION)
},
"ssh": {
"num_params": 1,
"run": lambda arg: ssh(arg)
},
"nmap": {
"num_params": 0,
"run": lambda arg: nmap()
},
"tools": {
"num_params": 0,
"run": lambda arg: list_tools()
},
"ifconfig": {
"num_params": 0,
"run": lambda arg: ip_config()
},
"users": {
"num_params": 0,
"run": lambda arg: list_users()
},
"groups": {
"num_params": 0,
"run": lambda arg: list_groups()
},
"history": {
"num_params": 0,
"run": lambda arg: show_history()
},
"language": {
"num_params": 0,
"run": lambda arg: set_language()
},
"exit": {
"num_params": 0,
"run": lambda arg: exit()
}
}
def signal_handler(signal, frame):
exit()
def exit():
print("\nBuh bye....")
sys.exit(0)
def get_current_machine_config():
current_machine = config.machines[CURRENT_IP]
return current_machine
def is_supported_language(lang):
global LANGUAGES_SUPPORTED
return lang is not None and lang in LANGUAGES_SUPPORTED
def set_language():
global LANGUAGE_SELECTION
language = None
# validate input
while not is_supported_language(language):
language = input(copy.copy_text["LANGUAGE_CHOICE"][LANGUAGE_SELECTION] + " ")
if not is_supported_language(language):
print(copy.copy_text["LANGUAGE_UNSUPPORTED"][LANGUAGE_SELECTION])
LANGUAGE_SELECTION = language
print(copy.copy_text["LANGUAGE_CHANGED"][LANGUAGE_SELECTION])
def ip_config():
print(CURRENT_IP)
def list_tools():
current_machine = get_current_machine_config()
for command in current_machine["commands"].keys():
print(command)
def list_users():
current_machine = get_current_machine_config()
for user in current_machine["users"]:
print(user["username"])
def list_groups():
current_machine = get_current_machine_config()
for group in current_machine["groups"]:
print(group)
def show_history():
current_machine = get_current_machine_config()
for entry in current_machine["history"]:
print(entry)
def nmap():
current_machine = get_current_machine_config()
firewall_rules = current_machine["firewall_rules"]
for egress_deny in firewall_rules["egress"]["deny"]:
if egress_deny["port"] == "*":
print(copy.copy_text["FIREWALL_RULE_VIOLATION"][LANGUAGE_SELECTION] + ": ")
return
for machine in config.machines:
print(machine)
def ssh(ip_address):
global CURRENT_IP
if not ip_address in config.machines:
print(copy.copy_text["INVALID_IP"][LANGUAGE_SELECTION])
else:
CURRENT_IP = ip_address
def process_command(command, argument):
global CMDS
if command not in CMDS.keys():
print(copy.copy_text["INVALID_CMD"][LANGUAGE_SELECTION])
elif CMDS[command]["num_params"] > 0 and not argument:
print(copy.copy_text["INVALID_PARAM_NUM"][LANGUAGE_SELECTION])
else:
CMDS[command]["run"](argument)
def input_loop():
#print(copy.copy_text["SELECT_TOOL"][LANGUAGE_SELECTION] + ": ")
user_input = input("user@" + CURRENT_IP + ":~$ ")
parsed_input = user_input.split()
command = parsed_input[0]
if len(parsed_input) > 0:
if len(parsed_input) > 1:
argument = parsed_input[1]
else:
argument = None
process_command(command, argument)
else:
print(copy.copy_text["INVALID_PARAM_NUM"][LANGUAGE_SELECTION])
return
if __name__ == "__main__":
signal.signal(signal.SIGINT, signal_handler)
lang = None
while not is_supported_language(lang):
lang = input("Select your language: ")
if not is_supported_language(lang):
print("We're sorry, your choice is currently unavailable.")
LANGUAGE_SELECTION = lang
while True:
input_loop()