forked from OWASP/SecureTea-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
256 lines (217 loc) · 7.03 KB
/
setup.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
# -*- coding: utf-8 -*-
u"""SecureTea setup.
Project:
╔═╗┌─┐┌─┐┬ ┬┬─┐┌─┐╔╦╗┌─┐┌─┐
╚═╗├┤ │ │ │├┬┘├┤ ║ ├┤ ├─┤
╚═╝└─┘└─┘└─┘┴└─└─┘ ╩ └─┘┴ ┴
Version: 2.1
Module: SecureTea
Attributes:
distros (list): Description
files_definition (TYPE): Description
os_name (TYPE): Description
"""
from setuptools import find_packages
from setuptools import setup
import platform
import subprocess
import re
os_name = platform.dist()[0]
if not os_name:
if 'amzn' in platform.uname()[2]:
os_name = 'centos'
files_definition = [
('/etc/securetea', ['securetea.conf']),
('', ['securetea.conf']),
('/etc/securetea/asp', [
'securetea/lib/auto_server_patcher/configs/commands.json',
'securetea/lib/auto_server_patcher/configs/config.json'
]),
('/etc/securetea/log_monitor/server_log/payloads', [
'securetea/lib/log_monitor/server_log/rules/payloads/bad_ua.txt',
'securetea/lib/log_monitor/server_log/rules/payloads/lfi.txt',
'securetea/lib/log_monitor/server_log/rules/payloads/port_scan_ua.txt',
'securetea/lib/log_monitor/server_log/rules/payloads/sqli.txt',
'securetea/lib/log_monitor/server_log/rules/payloads/web_shell.txt',
'securetea/lib/log_monitor/server_log/rules/payloads/xss.txt']),
('/etc/securetea/log_monitor/server_log/regex', [
'securetea/lib/log_monitor/server_log/rules/regex/sqli.txt',
'securetea/lib/log_monitor/server_log/rules/regex/xss.txt']),
('/etc/securetea/log_monitor/system_log', [
'securetea/lib/log_monitor/system_log/harmful_command.txt'
]),
('/etc/securetea/web_deface', [
'securetea/lib/web_deface/config/path_map.json'
]),
('/etc/securetea/antivirus', [
'securetea/lib/antivirus/config/config.json'
])
]
# dependency-name to command mapping dict
DEPENDENCY_COMMAND_MAP = {
"libnetfilter-queue-dev": {"debian": "sudo apt-get install "
"build-essential python-dev "
"libnetfilter-queue-dev"},
"clamav": {"debian": "sudo apt-get install clamav"}
}
def execute_command(command):
"""Execute the commnand passed & return the output.
Args:
command (str): Command to execute
Returns:
output (str): Output of the command execution
"""
success = True
try:
output = subprocess.check_output(command, shell=True)
except subprocess.CalledProcessError:
success = False
if success:
return output.decode("utf-8")
else:
return None
def verify_installation(output):
"""Verify whether the installation is successful or not.
Args:
output (str): Output after the execution
Returns:
TYPE: bool
"""
found = re.findall(
r'([0-9]+\supgraded).*([0-9]+\snewly installed)',
output
)
upgraded = found[0][0]
installed = found[0][1]
upgraded_num = re.findall(r'^[0-9]+', upgraded)
upgraded_num = int(upgraded_num[0])
installed_num = re.findall(r'^[0-9]+', installed)
installed_num = int(installed_num[0])
if (upgraded_num > 0 or installed_num > 0):
return True
def install_dependency(dependency, command):
"""Install the dependency.
Args:
dependency (str): Name of the dependency
command (str): Command to execute to install
the dependency
"""
print("[!] installing ", dependency)
# install the dependency
output = execute_command(command)
if output:
if verify_installation(output):
print("[+] ", dependency, " --installed")
else:
print("[-] ", dependency, "--failed")
def check_dependency():
"""Check for the dependencies in the system."""
# categorize OS
if os_name.lower() in ["ubuntu", "kali", "debian"]:
system = "debian"
# elif some other based OS
else: # if OS not in listing
print("[!] No suitable command for OS: {0}".format(os_name))
# exit & continue with rest of the installation
return
for dependency in DEPENDENCY_COMMAND_MAP.keys():
flag = 0
# if debian
if system == "debian":
# command for debian based OS to check installed or not
command = "dpkg -s " + dependency + " |grep Status"
output = execute_command(command)
if output:
if "install ok installed" in output:
print("[!] ", dependency, " --already installed")
flag = 1 # installed
# elif some other based OS
# add logic here to check whether dependency is installed
# not installed (common for all)
if flag == 0:
# get the OS specific command
command = DEPENDENCY_COMMAND_MAP[dependency][system]
install_dependency(dependency, command)
check_dependency()
entry_points = {
'console_scripts': [
'securetea=securetea.entry_points.securetea_core_ep:run_core',
'securetea-server=securetea.entry_points.server_ep:start_server_process',
'securetea-system=securetea.entry_points.system_ep:start_system_process',
'securetea-iot=securetea.entry_points.iot_ep:start_iot_process'
]
}
server_requirements = [
"pathlib",
"wget",
"yara-python",
"clamd",
"beautifulsoup4",
"lxml",
"clamd"
]
system_requirements = [
"pathlib",
"wget",
"yara-python",
"clamd",
"beautifulsoup4",
"lxml",
"clamd"
]
iot_requirements = [
"shodan"
]
setup(
name='securetea',
version='2.1',
packages=find_packages(exclude=[
"test",
"*.test",
"*.test.*",
"test.*"
]),
data_files=files_definition,
entry_points=entry_points,
license='MIT',
description='SecureTea',
long_description=open('doc/en-US/user_guide_pypi.md').read(),
long_description_content_type='text/markdown',
url='https://github.com/OWASP/SecureTea-Project',
author='OWASP SecureTea',
author_email='rejah.rehim@owasp.org',
install_requires=[
"requests",
"requests_oauthlib",
"py_cpuinfo",
"psutil",
"flask",
"flask_cors",
"pynput",
"python-telegram-bot",
"twilio",
"boto3",
"geocoder",
"pyudev",
"ipwhois",
"future",
"scapy",
"NetfilterQueue"
],
extras_require={
'server': server_requirements,
'system': system_requirements,
'iot': iot_requirements
},
python_requires='>=2.7',
classifiers=[
'Development Status :: 4 - Beta',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.6',
'Natural Language :: English',
'Topic :: Software Development :: Version Control :: Git',
'Topic :: Software Development :: Testing :: Unit',
],
zip_safe=False
)