/
setup.py
292 lines (251 loc) · 12.4 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
#!/usr/bin/python
############################################################################
# Network-Scout - An Addition to Artillery #
# An artillery logging and web interface #
# By Shawn Jordan and Aedan Somerville #
# Special thanks to Dave Kennedy, DOW Chemical Co., Marshall University #
# Adafruit, Jusbour and the Open Source Community #
# Version 2.0 "THUNDERING HERD" #
################################# GO HERD #######################################
#################################################################################
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#INSTALL ARTILLERY BEFORE INSTALLATION
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#importing necessary modules for setup
import subprocess, re, os, shutil, sys, time
from source import core
answer = ''
option = 0
menuopt = 0
isrpi = ''
ismysql = ''
try:
###Banners everywhere
print("Welcome to Network-Scout - An addition logging application for Artillery.")
print("If you are installing the client side, please download artillery first.\n")
print(
""" * * * \n
| / / \n
| / / \n
| / / \n
____________+___________+______________________+_____\n
NETWORK SCOUT \n
VERSION: 2.0 "THUNDERING HERD" \n
CREATORS: SHAWN JORDAN AND AEDAN SOMERVILLE \n
UPDATED: SEPTEMBER 1, 2015 \n
""")
###This allows us to set up Network Scout for raspberry pi or another system
print("First, we need to know if you are building a Raspberry Pi version of Network Scout." )
isrpi = raw_input("Are you using a Raspberry Pi? ")
##This adds the config option for Pi onto the file
if answer.lower() == 'y' or answer.lower() == 'yes':
confile = open("config", "a")
confile.write('IS_R_PI="YES"')
confile.close()
else:
confile = open("config", "a")
confile.write('IS_R_PI="NO"')
confile.close()
print("OPTIONS: \n1. Install Network-Scout Server\n2. Install Network-Scout Client \n3. Uninstall Network Scout \n4. Exit")
###Menu used for installation of NSServer NSclient and Removal of Network Scout
menuopt = input("Please select one: ")
if menuopt is 1:
option = 1
pass
elif menuopt is 2 and os.path.isdir("/var/artillery/"):
option = 2
pass
elif menuopt is 2:
print "Please install artillery from github.com/TrustedSec."
sys.exit()
elif menuopt is 3 and os.path.isdir("/var/networkscout/"):
option = 3
pass
elif menuopt is 3:
print "Network-Scout was not detected and could not be uninstalled."
sys.exit()
elif menuopt is 4:
sys.exit()
else:
print "Invalid option. Please try again."
sys.exit()
if option == 1:
print "[*]********** Network server is preparing to install..."
os.mkdir("/var/networkscout/")
subprocess.Popen("cp -r * /var/networkscout/", shell=True).wait()
# install to rc.local
print "[*]********** Adding Network-Scout into startup through init scripts..."
if os.path.isdir("/etc/init.d"):
if not os.path.isfile("/etc/init.d/nsserver"):
fileopen = file("startup/startup_network_scout_server", "r")
config = fileopen.read()
filewrite = file("/etc/init.d/nsserver", "w")
filewrite.write(config)
filewrite.close()
print "[*] Triggering update-rc.d on Network Scout to automatic start..."
subprocess.Popen("chmod +x /etc/init.d/nsserver", shell=True).wait()
subprocess.Popen("update-rc.d nsserver defaults", shell=True).wait()
if isrpi.lower() == 'y' or isrpi.lower() == 'yes':
print("[*]********** Downloading LAMP Install Script...")
subprocess.Popen("sudo git clone https://github.com/LikeABoss-001/Raspberry-Pi-LAMP-Install-Script.git", shell=True).wait()
print "[*]********** INSTALLING LAMP..."
print"[!]This may take a few minutes. Feel free to get a coffee. [!]"
subprocess.Popen("sudo chmod +x /home/pi/ns/Raspberry-Pi-LAMP-Install-Script/install.sh && /home/pi/ns/Raspberry-Pi-LAMP-Install-Script/install.sh", shell=True).wait()
subprocess.Popen("rm -rf Raspberry-Pi-LAMP-Install-Script/",shell=True).wait()
subprocess.Popen("sudo apt-get install python-rpi.gpio", shell=True).wait()
print "[*]********** Adding LCD controller into startup through init scripts..."
subprocess.Popen("sudo apt-get install python-rpi.gpio", shell=True).wait()
if os.path.isdir("/etc/init.d"):
if not os.path.isfile("/etc/init.d/lcd_controller"):
fileopen = file("startup/lcd_controller", "r")
config = fileopen.read()
fileopen.close()
filewrite = file("/etc/init.d/lcd_controller", "w")
filewrite.write(config)
filewrite.close()
print "[*] Triggering update-rc.d on LCD Controller to automatic start..."
subprocess.Popen("chmod +x /etc/init.d/lcd_controller", shell=True).wait()
subprocess.Popen("update-rc.d lcd_controller defaults", shell=True).wait()
print "[*]********** Adding Shutdown into startup through init scripts..."
if os.path.isdir("/etc/init.d"):
if not os.path.isfile("/etc/init.d/shutdown_button"):
fileopen = file("startup/shutdown", "r")
config = fileopen.read()
fileopen.close()
filewrite = file("/etc/init.d/shutdown_button", "w")
filewrite.write(config)
filewrite.close()
print "[*] Triggering update-rc.d on Shutdown Button to automatic start..."
subprocess.Popen("chmod +x /etc/init.d/shutdown_button", shell=True).wait()
subprocess.Popen("update-rc.d shutdown_button defaults", shell=True).wait()
subprocess.Popen("chmod 755 /var/networkscout/lcd_controller.py", shell=True).wait()
subprocess.Popen("chmod 755 /var/networkscout/shutdown.py", shell=True).wait()
#moving Adafruit into python library
print("*********************** Putting the Pieces Together ********************")
subprocess.Popen("cp /var/networkscout/source/Adafruit_CharLCD.py /usr/lib/python2.7/", shell=True).wait()
else:
print("We are setting up the website now")
pass
subprocess.Popen("chmod 755 /var/networkscout/nsserver.py", shell=True).wait()
subprocess.Popen("rm /var/networkscout/nsclient.py", shell=True).wait()
####MAY DISCONTINUE DATABASE USAGE FOR NON-PI Users
ismysql = raw_input("Will you be using MySQL? (Y/N) *If not, we will use PHP to create the table* ")
if ismysql.lower() == 'y' or ismysql.lower() == 'yes':
print("************************** Creating Database for Logs ***********************")
subprocess.Popen("sudo apt-get install python-mysqldb", shell=True).wait()
subprocess.Popen("python /var/networkscout/stuff/mysqltablecreator.py", shell=True).wait()
if os.path.isdir("/var/www/html/"):
subprocess.Popen("mv /var/networkscout/website/* /var/www/html/", shell=True).wait()
else:
subprocess.Popen("mv /var/networkscout/website/* /var/www/", shell=True).wait()
else:
if os.path.isdir("/var/www/html/"):
subprocess.Popen("mv /var/networkscout/website_phponly/* /var/www/html/", shell=True).wait()
else:
subprocess.Popen("mv /var/networkscout/website_phponly/* /var/www/", shell=True).wait()
serverip = core.ipgrab()
print("Website created at "+serverip+"/scoutwebsite.php \n")
answer=raw_input("Do you wish to reboot your pi? [yes|no] ")
if answer.lower() == 'y' or answer.lower() == 'yes':
subprocess.Popen("reboot", shell=True)
else:
pass
elif option == 2:
print("[*]********** Installing network-scout...")
core.kill_artillery()
os.mkdir("/var/networkscout")
subprocess.Popen("cp -r ./* /var/networkscout/", shell=True).wait()
#modifying artillery
print("[*]**********Modding Artillery for NS logging...")
mod = open("stuff/artilleryfunction", "r")
contents = mod.read()
artillery = open("/var/artillery/src/core.py", "a")
artillery.write(contents)
artillery.close()
mod.close()
#Adding nslog to all parts of artillery
core.modify_program("warn_the_good_guys","/var/artillery/src/harden.py"," nslog(warning)")
core.modify_program("warn_the_good_guys","/var/artillery/src/honeypot.py"," nslog(subject)")
core.modify_program("warn_the_good_guys","/var/artillery/src/monitor.py"," nslog(subject)")
core.modify_program("warn_the_good_guys","/var/artillery/src/ssh_monitor.py"," nslog(subject)")
print("[*]********** Creating Log Directory and File...")
# create the database directories if they aren't there
if not os.path.isdir("/var/artillery/log/"):
os.makedirs("/var/artillery/log/")
if not os.path.isfile("/var/artillery/log/logs.txt"):
filewrite = file("/var/artillery/log/logs.txt", "w")
filewrite.write(" ")
filewrite.close()
# install to rc.local
print "[*]********** Adding Network-Scout into startup through init scripts..."
if os.path.isdir("/etc/init.d"):
if not os.path.isfile("/etc/init.d/nsclient"):
fileopen = file("startup/startup_network_scout_client", "r")
config = fileopen.read()
fileopen.close()
filewrite = file("/etc/init.d/nsclient", "w")
filewrite.write(config)
filewrite.close()
print "[*] Triggering update-rc.d on Network Scout to automatic start..."
subprocess.Popen("chmod +x /etc/init.d/nsclient", shell=True).wait()
subprocess.Popen("update-rc.d nsclient defaults", shell=True).wait()
if isrpi.lower() == 'y' or isrpi.lower() == 'yes':
print "[*]********** Adding LCD controller into startup through init scripts..."
subprocess.Popen("sudo apt-get install python-rpi.gpio", shell=True).wait()
if os.path.isdir("/etc/init.d"):
if not os.path.isfile("/etc/init.d/lcd_controller"):
fileopen = file("startup/lcd_controller", "r")
config = fileopen.read()
fileopen.close()
filewrite = file("/etc/init.d/lcd_controller", "w")
filewrite.write(config)
filewrite.close()
print "[*] Triggering update-rc.d on LCD Controller to automatic start..."
subprocess.Popen("chmod +x /etc/init.d/lcd_controller", shell=True).wait()
subprocess.Popen("update-rc.d lcd_controller defaults", shell=True).wait()
print "[*]********** Adding Shutdown into startup through init scripts..."
if os.path.isdir("/etc/init.d"):
if not os.path.isfile("/etc/init.d/shutdown_button"):
fileopen = file("startup/shutdown", "r")
config = fileopen.read()
fileopen.close()
filewrite = file("/etc/init.d/shutdown_button", "w")
filewrite.write(config)
filewrite.close()
print "[*] Triggering update-rc.d on Shutdown Button to automatic start..."
subprocess.Popen("chmod +x /etc/init.d/shutdown_button", shell=True).wait()
subprocess.Popen("update-rc.d shutdown_button defaults", shell=True).wait()
subprocess.Popen("chmod 755 /var/networkscout/lcd_controller.py", shell=True).wait()
subprocess.Popen("chmod 755 /var/networkscout/shutdown.py", shell=True).wait()
subprocess.Popen("cp /var/networkscout/source/Adafruit_CharLCD.py /usr/lib/python2.7/", shell=True).wait()
else:
pass
print("[*]********** Adding access to scripts for init.d...")
subprocess.Popen("chmod 755 /var/networkscout/nsclient.py", shell=True).wait()
subprocess.Popen("rm /var/networkscout/nsserver.py", shell=True).wait()
answer=raw_input("Do you wish to reboot your computer? [yes|no] ")
if answer.lower() == 'y' or answer.lower() == 'yes':
subprocess.Popen("reboot", shell=True)
else:
pass
elif option == 3:
answer = raw_input("Do you want to uninstall network-scout: [ yes | no } ")
if answer.lower() == "y" or answer.lower() == "yes":
subprocess.Popen("rm -rf /var/networkscout", shell=True)
if os.path.isfile("/etc/init.d/nsclient"):
os.remove("/etc/init.d/nsclient")
os.remove("/etc/init.d/lcd_controller")
os.remove("/etc/init.d/shutdown_button")
else:
os.remove("/etc/init.d/nsserver")
os.remove("/etc/init.d/lcd_controller")
os.remove("/etc/init.d/shutdown_button")
subprocess.Popen("python /var/networkscout/stuff/mysqluninstaller.py", shell=True)
subprocess.Popen("rm /var/www/*", shell=True)
subprocess.Popen("apt-get purge `dpkg -l | awk -F ' ' ' /php|mysql|otherpackages/ { print $2 } '`", shell=True)
print "[*] Network-Scout has been uninstalled. Manually kill the process if it is still running."
else:
print "There was an issue installing Network-Scout."
except Exception, e:
print("There was an issue installing network-scout") + format(e)
sys.exit()