forked from TravisFSmith/SweetSecurity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
303 lines (282 loc) · 12.6 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
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
#!/usr/bin/env python
import argparse, fcntl, getpass, json, os, re, shutil, socket, sqlite3, struct, sys
from time import sleep
# Local Installer Scripts
from install import packages
from install import bro
from install import criticalStack
from install import elasticSearch
from install import logstash
from install import kibana
from install import sweetSecurity
from install import apache
from install import fail2ban
# Issue: When using OpenDNS, no hostname resolution
class color:
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0m'
def get_user_input(input_string):
if sys.version_info[0] > 2:
return input(input_string)
else:
return raw_input(input_string)
def getIP(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15]))[20:24])
except:
return ''
def validateIP(ip):
if re.match(r'^(\d{1,3}\.){3}\d{1,3}$', ip):
return True
elif re.match(r'^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](\.[a-zA-Z]{2,})+$', ip):
return True
elif re.match(r'^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]$', ip):
return True
else:
return False
if __name__ == "__main__":
# Check if user is root first...
if os.getuid() != 0:
sys.exit("Must run as root/sudo")
while True:
question = "\033[1m1 - \033[4mFull Install\033[0m: Bro IDS, Critical Stack, ELK Stack, Apache, Sweet Security\n"
question += "\033[1m2 - \033[4mSensor Only\033[0m: Bro IDS, Critical Stack, Logstash, Sweet Security\n"
question += "\033[1m3 - \033[4mWeb Server Only\033[0m: Elasticsearch, Kibana, Apache\n"
question += "\033[1mChoose an Installation Type (1-3)\033[0m: "
installType = get_user_input(question)
if not re.match(r'^[1-3]$', installType):
print("Choose 1, 2, or 3.")
else:
break
memAvailable = 0
memInfo = os.popen('free -t -m').read()
for line in memInfo.splitlines():
if line.rstrip().startswith('Mem:'):
memAvailable = int(line.split()[1])
# Give room for swap space
if memAvailable < 900:
sys.exit('Less than 1GB of memory. You need more than this to continue.')
if installType == '1':
if memAvailable < 1800:
sys.exit('Less than 2GB of memory available. Consider splitting installs across multiple devices.')
# Install prerequisites
packages.install(installType)
interfaces = os.listdir('/sys/class/net/')
userQuestion = "Available Interfaces: \n"
availableInts = []
availableIntNames = []
availableIntIPs = []
d = 0
for interface in interfaces:
if interface != "lo":
if len(getIP(interface)) > 0:
availableInts.append(str(d))
availableIntNames.append(interface)
availableIntIPs.append(getIP(interface))
userQuestion += " %d: %s (%s)\n" % (d, interface, getIP(interface))
d = d + 1
userQuestion += "\033[1mWhich Interface Should be Used(web admin and spoofing)\033[0m: "
if len(availableIntIPs) > 1:
while True:
chosenInt = get_user_input(userQuestion)
if chosenInt not in availableInts:
print(" Invalid Response.")
else:
break
chosenInterface = availableIntNames[int(chosenInt)]
chosenInterfaceIP = availableIntIPs[int(chosenInt)]
elif len(availableIntIPs) == 1:
chosenInterface = availableIntNames[0]
chosenInterfaceIP = availableIntIPs[0]
else:
sys.exit('No available interfaces')
# Create Credentials for apache
while True:
httpUser = get_user_input("\033[1mEnter username for web portal (apache/kibana)\033[0m: ")
if len(httpUser) > 100:
print("Username must be less than 100 characters")
if not re.match(r'[0-9a-zA-Z]+', httpUser):
print("Username must be alphanumeric 0-9, a-z, and A-Z")
else:
break
while True:
httpPass = getpass.getpass("\033[1mEnter password for web portal\033[0m: ")
httpPassConfirm = getpass.getpass("\033[1mConfirm password for web portal\033[0m: ")
if httpPass != httpPassConfirm:
print ("Passwords do not match")
elif len(httpPass) > 100:
print("Password must be less than 100 characters")
elif '"' in httpPass:
print("Password cannot contain double quote character")
else:
break
# Create Credentials for Elasticsearch
while True:
elasticUser = get_user_input("\033[1mEnter username for Elasticsearch\033[0m: ")
if len(elasticUser) > 100:
print("Username must be less than 100 characters")
if not re.match(r'[0-9a-zA-Z]+', elasticUser):
print("Username must be alphanumeric 0-9, a-z, and A-Z")
else:
break
while True:
elasticPass = getpass.getpass("\033[1mEnter password for Elasticsearch\033[0m: ")
elasticPassConfirm = getpass.getpass("\033[1mConfirm password for Elasticsearch\033[0m: ")
if elasticPass != elasticPassConfirm:
print ("Passwords do not match")
elif len(elasticPass) > 100:
print("Password must be less than 100 characters")
elif '"' in elasticPass:
print("Password cannot contain double quote character")
else:
break
if installType == '1':
# Bro IDS, Critical Stack, ELK Stack, Apache, Sweet Security
criticalStackInstalled = False
if os.path.isfile('/usr/bin/critical-stack-intel'):
criticalStackInstalled = True
if criticalStackInstalled == False:
while True:
installCriticalStack = get_user_input(
"\033[1mInstall Critical Stack Threat Intel For Bro IDS (Y/n)\033[0m: ")
if installCriticalStack.lower() not in ('y', 'n', ''):
print "Must choose Y or N."
else:
break
if installCriticalStack.lower() == 'y' or len(installCriticalStack) == 0:
installCriticalStack = 'y'
while True:
csKey = get_user_input(" \033[1mEnter Your Critical Stack API Key\033[0m: ")
if not re.match(r'[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}',
csKey):
print(" Not a valid API key.")
else:
break
bro.install(chosenInterface, 'localhost')
if criticalStackInstalled == False and installCriticalStack.lower() == 'y':
criticalStack.install(csKey)
else:
print "Skipping Critical Stack Install"
# Check if We Should Install Fail2Ban
# while True:
# installFail2Ban = get_user_input("\033[1mInstall Fail2Ban (Y/n)\033[0m: ")
# if installFail2Ban.lower() not in ('y', 'n', ''):
# print "Must choose Y or N."
# else:
# break
# if installFail2Ban == 'y' or installFail2Ban == '':
# fail2ban.install()
apache.install(installType, chosenInterface, chosenInterfaceIP)
print " Creating web portal credentials"
os.popen('sudo htpasswd -cb /etc/apache2/.htpasswd %s "%s"' % (httpUser, httpPass)).read()
os.popen('sudo htpasswd -cb /etc/apache2/.elasticsearch %s "%s"' % (elasticUser, elasticPass)).read()
# Get system default configurations
fileCheckKey = None
while True:
installFileCheck = get_user_input("\033[1mCheck Files Against FileCheck.IO (y/N)\033[0m: ")
if installFileCheck.lower() not in ('y', 'n', ''):
print "Must choose Y or N."
else:
break
if installFileCheck.lower() == 'y':
installFileCheck = 'y'
while True:
fileCheckKey = get_user_input(" \033[1mEnter Your FileCheckIO API Key\033[0m: ")
if not re.match(r'[0-9a-fA-F]{56}', fileCheckKey):
print(" Not a valid API key.")
else:
break
elasticSearch.install(fileCheckKey)
kibana.install(chosenInterfaceIP)
print "Restarting Apache"
os.popen('sudo service apache2 restart').read()
logstash.install('localhost', elasticUser, elasticPass)
sweetSecurity.installClient(chosenInterface)
sweetSecurity.addWebCreds('localhost', httpUser, httpPass,'client')
print "Starting SweetSecurity Client"
os.popen('sudo service sweetsecurity restart').read()
sweetSecurity.installServer()
sweetSecurity.addWebCreds('localhost', httpUser, httpPass, 'server')
print "Starting SweetSecurity Server"
os.popen('sudo service sweetsecurity_server restart').read()
elif installType == '2':
# Bro IDS, Critical Stack, Logstash, Sweet Security
esServer = get_user_input('\033[1mEnter Server IP:\033[0m ')
criticalStackInstalled = False
if os.path.isfile('/usr/bin/critical-stack-intel'):
criticalStackInstalled = True
if criticalStackInstalled == False:
while True:
installCriticalStack = get_user_input(
"\033[1mInstall Critical Stack Threat Intel For Bro IDS (Y/n)\033[0m: ")
if installCriticalStack.lower() not in ('y', 'n', ''):
print("Must choose Y or N.")
else:
break
if installCriticalStack.lower() == 'y' or len(installCriticalStack) == 0:
installCriticalStack = 'y'
while True:
csKey = get_user_input(" \033[1mEnter Your Critical Stack API Key\033[0m: ")
if not re.match(r'[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}',
csKey):
print(" Not a valid API key.")
else:
break
if not validateIP(esServer):
sys.exit('Not a valid IP Address')
bro.install(chosenInterface, esServer)
if criticalStackInstalled == False and installCriticalStack.lower() == 'y':
criticalStack.install(csKey)
logstash.install(esServer, elasticUser, elasticPass)
sweetSecurity.installClient(chosenInterface)
sweetSecurity.addWebCreds(esServer, httpUser, httpPass,'client')
print "Starting SweetSecurity"
os.popen('sudo service sweetsecurity restart').read()
elif installType == '3':
# Elasticsearch, Kibana, Apache
# Check if We Should Install Fail2Ban
while True:
installFail2Ban = get_user_input("\033[1mInstall Fail2Ban (Y/n)\033[0m: ")
if installFail2Ban.lower() not in ('y', 'n', ''):
print "Must choose Y or N."
else:
break
if installFail2Ban == 'y' or installFail2Ban == '':
fail2ban.install()
apache.install(installType, chosenInterface, chosenInterfaceIP)
print " Creating web portal credentials"
os.popen('sudo htpasswd -cb /etc/apache2/.htpasswd %s "%s"' % (httpUser, httpPass)).read()
os.popen('sudo htpasswd -cb /etc/apache2/.elasticsearch %s "%s"' % (elasticUser, elasticPass)).read()
fileCheckKey = None
while True:
installFileCheck = get_user_input("\033[1mCheck Files Against FileCheck.IO (y/N)\033[0m: ")
if installFileCheck.lower() not in ('y', 'n', ''):
print "Must choose Y or N."
else:
break
if installFileCheck.lower() == 'y':
installFileCheck = 'y'
while True:
fileCheckKey = get_user_input(" \033[1mEnter Your FileCheckIO API Key\033[0m: ")
if not re.match(r'[0-9a-fA-F]{56}', fileCheckKey):
print(" Not a valid API key.")
else:
break
elasticSearch.install(fileCheckKey)
print " Creating elasticsearch credentials"
kibana.install(chosenInterfaceIP)
print "Restarting Apache"
os.popen('sudo service apache2 restart').read()
sweetSecurity.installServer()
sweetSecurity.addWebCreds('localhost', httpUser, httpPass, 'server')
print "Starting SweetSecurity Server"
os.popen('sudo service sweetsecurity_server restart').read()