-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathiot_ep.py
More file actions
164 lines (132 loc) · 4.47 KB
/
iot_ep.py
File metadata and controls
164 lines (132 loc) · 4.47 KB
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
# -*- coding: utf-8 -*-
u"""IoT Console Script.
Project:
╔═╗┌─┐┌─┐┬ ┬┬─┐┌─┐╔╦╗┌─┐┌─┐
╚═╗├┤ │ │ │├┬┘├┤ ║ ├┤ ├─┤
╚═╝└─┘└─┘└─┘┴└─└─┘ ╩ └─┘┴ ┴
Author: Abhishek Sharma <abhishek_official@hotmail.com> , Aug 20 2019
Version: 1.5.1
Module: SecureTea
"""
from securetea.args import args_helper
from securetea.modes import iot_mode
from securetea.lib.firewall.utils import get_interface
import platform
import argparse
def get_args():
"""
Get arguments.
Raises:
None
Returns:
Args: total arguments
"""
parser = argparse.ArgumentParser(description='Arguments of SecureTea')
parser.add_argument(
'--conf',
type=str,
required=False,
help='Path of config file. default:- "~/.securetea/securetea.conf" '
)
parser.add_argument(
'--debug',
default=False,
action="store_true",
help='Debug true or false'
)
return parser.parse_args()
def get_credentials():
"""
Get credentials either through the saved configurations or
through interactive setup mode.
Args:
None
Raises:
None
Returns:
final_creds (dict): Collected credentials
"""
args = get_args()
debug = bool(args.debug)
final_creds = {"debug": debug}
# Create ArgsHelper object for collecting configurations
args_helper_obj = args_helper.ArgsHelper(args=args)
if int(platform.sys.version_info[0]) < 3: # if Python 2.X.X
config_decision = raw_input("[!] Do you want to use the saved configuratons? (Y/y): ").strip(" ")
else:
config_decision = str(input("[!] Do you want to use the saved configuratons? (Y/y): ")).strip(" ")
if (config_decision.lower() == "y"):
# Fetch credentials
creds = args_helper_obj.securetea_conf.get_creds(args_helper_obj.args)
if creds.get("firewall"):
_extracted_from_get_credentials_24(
final_creds,
"firewall",
creds,
"\n[!] Select network interface for Firewall",
)
if creds.get("ids"):
_extracted_from_get_credentials_24(
final_creds,
"ids",
creds,
"\n[!] Select network interface for Intrusion Detection System",
)
if creds.get("iot-check"):
final_creds["iot-check"] = creds["iot-check"]
else:
_extracted_from_get_credentials_41(args_helper_obj, final_creds)
return final_creds
def _extracted_from_get_credentials_41(args_helper_obj, final_creds):
# Start interactive setup for Firewall
firewall = args_helper_obj.configureFirewall()
# Start interactive setup for IDS
ids = args_helper_obj.configureIDS()
# Start interactive setup for IoT Checker
iot_check = args_helper_obj.configureIoTChecker()
if firewall:
_extracted_from_get_credentials_48(
final_creds,
"firewall",
firewall,
"\n[!] Select network interface for Firewall",
)
if ids:
_extracted_from_get_credentials_48(
final_creds,
"ids",
ids,
"\n[!] Select network interface for Intrusion Detection System",
)
if iot_check:
final_creds["iot-check"] = iot_check
def _extracted_from_get_credentials_48(final_creds, arg1, arg2, arg3):
final_creds[arg1] = arg2
interface = final_creds[arg1]["interface"]
if not interface or interface == "XXXX":
_extracted_from_get_credentials_27(arg3, final_creds, arg1)
def _extracted_from_get_credentials_24(final_creds, arg1, creds, arg3):
final_creds[arg1] = creds[arg1]
interface = final_creds[arg1]["interface"]
if not interface or interface == "XXXX":
_extracted_from_get_credentials_27(arg3, final_creds, arg1)
def _extracted_from_get_credentials_27(arg0, final_creds, arg2):
print(arg0)
interface = get_interface()
final_creds[arg2]["interface"] = interface
def start_iot_process():
"""
Start SecureTea in iot mode.
Args:
None
Raises:
None
Returns:
None
"""
# Collect credentials
cred = get_credentials()
# Initialize IotMode object
iot_mode_obj = iot_mode.IoTMode(cred=cred, debug=cred["debug"])
# Start SecureTea in IoT mode
iot_mode_obj.start_iot_mode()