-
Notifications
You must be signed in to change notification settings - Fork 1
/
Snorter.sh
executable file
·642 lines (517 loc) · 22.3 KB
/
Snorter.sh
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
#!/bin/bash
# lazy script for installing Snort , Barnyard2 , Pulledpork
# Tested on: Kali linux , Ubuntu 14.04
# Copyright (c) 2017 - betmenwasdie // [email protected]
# Usage: $ sudo ./snorter.sh -o OINKCODE -i INTERFACES
RED='\033[0;31m'
ORANGE='\033[0;205m'
YELLOW='\033[0;93m'
GREEN='\033[0;32m'
CYAN='\033[0;96m'
BLUE='\033[0;34m'
VIOLET='\033[0;35m'
NOCOLOR='\033[0m'
BOLD='\033[1m'
function check_root() {
if [ "$(id -u)" != 0 ]; then
echo -ne "\n\t\t${RED}[-] ERROR:${NOCOLOR} Run this script as ${BOLD}ROOT${NOCOLOR}\n"
exit 1
fi
}
function update_upgrade() {
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Updating and Upgrading repositories...\n\n"
sudo apt-get update && sudo apt-get upgrade -y --force-yes
}
function snort_install() {
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Installing dependencies.\n\n"
sudo apt-get install -y --force-yes build-essential libpcap-dev libpcre3-dev libdumbnet-dev bison flex zlib1g-dev git locate vim
#Downloading DAQ and SNORT
cd $HOME && mkdir snort_src && cd snort_src
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Downloading ${BOLD}$DAQ${NOCOLOR}.\n\n"
wget -P $HOME/snort_src https://snort.org/downloads/snort/$DAQ.tar.gz
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Downloading ${BOLD}$SNORT${NOCOLOR}.\n\n"
wget -P $HOME/snort_src https://snort.org/downloads/snort/$SNORT.tar.gz
#Installing DAQ
cd $HOME/snort_src/
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Installing ${BOLD}$DAQ${NOCOLOR}.\n\n"
tar xvfz $DAQ.tar.gz
mv $HOME/snort_src/daq-*/ $HOME/snort_src/daq
cd $HOME/snort_src/daq
./configure && make && sudo make install
echo -ne "\n\t${GREEN}[+] INFO:${NOCOLOR} ${BOLD}$DAQ${NOCOLOR} installed successfully.\n\n"
#Installing SNORT
cd $HOME/snort_src
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Installing ${BOLD}$DAQ${NOCOLOR}.\n\n"
tar xvfz $SNORT.tar.gz > /dev/null 2>&1
rm -r *.tar.gz > /dev/null 2>&1
mv snort-*/ snort
cd snort
./configure --enable-sourcefire && make && sudo make install
echo -ne "\n\t${GREEN}[+] INFO:${NOCOLOR} ${BOLD}$SNORT${NOCOLOR} installed successfully.\n\n"
cd ..
sudo ldconfig
sudo ln -s /usr/local/bin/snort /usr/sbin/snort
#Adding SNORT user and group for running SNORT
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Adding user and group ${BOLD}SNORT${NOCOLOR}.\n\n"
sudo groupadd snort
sudo useradd snort -r -s /sbin/nologin -c SNORT_IDS -g snort
sudo mkdir /etc/snort > /dev/null 2>&1
sudo mkdir /etc/snort/rules > /dev/null 2>&1
sudo mkdir /etc/snort/preproc_rules > /dev/null 2>&1
sudo touch /etc/snort/rules/white_list.rules /etc/snort/rules/black_list.rules /etc/snort/rules/local.rules > /dev/null 2>&1
sudo mkdir /var/log/snort > /dev/null 2>&1
sudo mkdir /usr/local/lib/snort_dynamicrules > /dev/null 2>&1
sudo chmod -R 5775 /etc/snort > /dev/null 2>&1
sudo chmod -R 5775 /var/log/snort > /dev/null 2>&1
sudo chmod -R 5775 /usr/local/lib/snort_dynamicrules > /dev/null 2>&1
sudo chown -R snort:snort /etc/snort > /dev/null 2>&1
sudo chown -R snort:snort /var/log/snort > /dev/null 2>&1
sudo chown -R snort:snort /usr/local/lib/snort_dynamicrules > /dev/null 2>&1
sudo cp ~/snort_src/snort/etc/*.conf* /etc/snort > /dev/null 2>&1
sudo cp ~/snort_src/snort/etc/*.map /etc/snort > /dev/null 2>&1
sudo sed -i 's/include \$RULE\_PATH/#include \$RULE\_PATH/' /etc/snort/snort.conf
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} /var/log/snort and /etc/snort created and configurated.\n\n"
sudo /usr/local/bin/snort -V
echo -ne "\n\t${GREEN}[+] INFO:${NOCOLOR} ${BOLD}SNORT${NOCOLOR} is successfully installed and configurated!"
}
function snort_edit() {
echo -ne "\n\t${YELLOW}[!] INFO:${NOCOLOR} Now it's time to edit the ${BOLD}SNORT${NOCOLOR} configuration file.\n\n"
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Add your ${BOLD}HOME_NET${NOCOLOR} address [Ex: 192.168.1.0/24]"
echo -ne "\n\t${YELLOW}[!] WARNING:${NOCOLOR} Press ${BOLD}ENTER${NOCOLOR} to continue. "
read -n 1 -s
sudo vim /etc/snort/snort.conf -c "/ipvar HOME_NET"
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Add your ${BOLD}EXTERNAL_NET${NOCOLOR} address [Ex: !\$HOME_NET]"
echo -ne "\n\t${YELLOW}[!] WARNING:${NOCOLOR} Press ${BOLD}ENTER${NOCOLOR} to continue. "
read -n 1 -s
sudo vim /etc/snort/snort.conf -c "/ipvar EXTERNAL_NET"
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Adding ${BOLD}RULE_PATH${NOCOLOR} to snort.conf file"
sudo sed -i 's/RULE_PATH\ \.\.\//RULE_PATH\ \/etc\/snort\//g' /etc/snort/snort.conf
sudo sed -i 's/_LIST_PATH\ \.\.\//_LIST_PATH\ \/etc\/snort\//g' /etc/snort/snort.conf
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Enabling ${BOLD}local.rules${NOCOLOR} and adding a PING detection rule..."
sudo sed -i 's/#include \$RULE\_PATH\/local\.rules/include \$RULE\_PATH\/local\.rules/' /etc/snort/snort.conf
sudo chmod 766 /etc/snort/rules/local.rules
sudo echo 'alert icmp any any -> $HOME_NET any (msg:"Atac per PINGs"; sid:10000001; rev:001;)' >> /etc/snort/rules/local.rules
#SNORT OUTPUT: UNIFIED2 --> MANDATORY || CSV/TCPDUMP/BOTH
sudo sed -i 's/# unified2/output unified2: filename snort.u2, limit 128/g' /etc/snort/snort.conf
while true; do
echo -ne "\n\t${YELLOW}[!] WARNING:${NOCOLOR} Unified2 output configured. Configure another output?\n\t\t${YELLOW}1${NOCOLOR} - ${BOLD}CSV${NOCOLOR} output\n\t\t${YELLOW}2${NOCOLOR} - ${BOLD}TCPdump${NOCOLOR} output\n\t\t${YELLOW}3${NOCOLOR} - ${BOLD}CSV${NOCOLOR} and ${BOLD}TCPdump${NOCOLOR} output\n\t\t${YELLOW}4${NOCOLOR} - ${BOLD}None${NOCOLOR}\n\n\tOption [1-4]: "
read OPTION
case $OPTION in
1 )
echo -ne "\n\t${YELLOW}[!] WARNING:${NOCOLOR} ${BOLD}CSV${NOCOLOR} output will be configured\n"
sudo sed -i 's/# syslog/output alert_csv: \/var\/log\/alert.csv default/g' /etc/snort/snort.conf
break
;;
2 )
echo -ne "\n\t${YELLOW}[!] WARNING:${NOCOLOR} ${BOLD}TCPdump${NOCOLOR} output will be configured\n"
sudo sed -i 's/# pcap/output log_tcpdump: snort.log/g' /etc/snort/snort.conf
break
;;
3 )
echo -ne "\n\t${YELLOW}[!] WARNING:${NOCOLOR} ${BOLD}CSV${NOCOLOR} and ${BOLD}TCPdump${NOCOLOR} output will be configured\n"
sudo sed -i 's/# syslog/output alert_csv: \/var\/log\/snort\/alert.csv default/g' /etc/snort/snort.conf
sudo sed -i 's/# pcap/output log_tcpdump: \/var\/log\/snort\/snort.log/g' /etc/snort/snort.conf
break
;;
4 )
echo -ne "\n\t${YELLOW}[!] WARNING:${NOCOLOR} No other output will be configured\n\n"
break
;;
* )
echo -ne "\n\t${RED}[-] ERROR:${NOCOLOR} Invalid option\n\n"
;;
esac
done
}
function snort_test() {
echo -ne "\n\t${YELLOW}[!] WARNING:${NOCOLOR} Starting ${BOLD}SNORT${NOCOLOR} in test mode. Checking configuration file.... \n"
sudo snort -T -c /etc/snort/snort.conf
echo -ne "\n\t${YELLOW}[!] WARNING:${NOCOLOR} Attempting to test ${BOLD}ICMP${NOCOLOR} rule in ${BOLD}$INTERFACE${NOCOLOR}. Send a PING to your ${BOLD}SNORT${NOCOLOR} machine. Press ${BOLD}Ctrl+C${NOCOLOR} once and wait few seconds to stop the process...\n "
echo -ne "\n\t${YELLOW}[!] WARNING:${NOCOLOR} Press ${BOLD}ENTER${NOCOLOR} to continue. "
read -n 1 -s
sudo snort -A console -q -u snort -g snort -c /etc/snort/snort.conf -i $INTERFACE
killall -9 snort
}
function barnyard2_ask() {
while true; do
echo -ne "\n\t${YELLOW}[!] IMPORTANT:${NOCOLOR} Would you like to install ${BOLD}BARNYARD2${NOCOLOR}? [Y/n] "
read OPTION
case $OPTION in
Y|y )
barnyard2_install
break
;;
N|n )
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} ${BOLD}BARNYARD2${NOCOLOR} won't be installed.\n\n"
break
;;
* )
echo -ne "\n\t${RED}[-] ERROR:${NOCOLOR} Invalid option.\n\n"
;;
esac
done
}
function barnyard2_install() {
echo -ne "\n\t${YELLOW}[!] WARNING:${NOCOLOR} Insert new ${BOLD}SNORT${NOCOLOR} Database Password: "
read SNORTSQLPASSWORD
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Installing dependencies."
echo -ne "\n\t${YELLOW}[!] WARNING:${NOCOLOR} You will be asked for a ${BOLD}password for MySQL${NOCOLOR} service if it isn't installed in the system."
echo -ne "\n\t${YELLOW}[!] WARNING:${NOCOLOR} Press ${BOLD}ENTER${NOCOLOR} to continue. "
read -n 1 -s
sudo apt-get install -y --force-yes mysql-server libmysqlclient-dev mysql-client autoconf libtool libdnet checkinstall yagiuda libdnet-dev locate
cd $HOME/snort_src
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Downloading ${BOLD}BARNYARD2${NOCOLOR}.\n\n"
git clone https://github.com/firnsy/barnyard2.git && cd $HOME/snort_src/barnyard2
autoreconf -fvi -I ./m4
ln -s /usr/include/dumbnet.h dnet.h
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Installing ${BOLD}BARNYARD2${NOCOLOR}2.\n\n"
if [ "$MACHINE" == "x86_64" ]; then
./configure --with-mysql --with-mysql-libraries=/usr/lib/x86_64-linux-gnu
elif [ "$MACHINE" == "i386" ]; then
./configure --with-mysql --with-mysql-libraries=/usr/lib/i386-linux-gnu
else
./configure --with-mysql --with-mysql-libraries=/usr/lib/arm-linux-gnueabihf
fi
make
sudo make install
echo -ne "\n\t${GREEN}[+] INFO:${NOCOLOR} ${COLOR}BARNYARD2${NOCOLOR} installed successfully.\n\n"
sudo cp etc/barnyard2.conf /etc/snort > /dev/null 2>&1
sudo mkdir /var/log/barnyard2 > /dev/null 2>&1
sudo chown snort.snort /var/log/barnyard2 > /dev/null 2>&1
sudo touch /var/log/snort/barnyard2.waldo > /dev/null 2>&1
sudo chown snort.snort /var/log/snort/barnyard2.waldo > /dev/null 2>&1
sudo touch /etc/snort/sid-msg.map > /dev/null 2>&1
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} The ${BOLD}SNORT${NOCOLOR} database is going to be created. You will be asked for ${RED}MySQL password 3 times${NOCOLOR}"
echo -ne "\n\t${YELLOW}[!] WARNING:${NOCOLOR} Press ${BOLD}ENTER${NOCOLOR} to continue. "
read -n 1 -s
echo -ne "\n\n"
sudo /etc/init.d/mysql start > /dev/null 2>&1
echo "create database snort;" | mysql -u root -p
mysql -u root -p -D snort < $HOME/snort_src/barnyard2/schemas/create_mysql
echo "grant create, insert, select, delete, update on snort.* to 'snort'@'localhost' identified by '$SNORTSQLPASSWORD'" | mysql -u root -p
sudo echo "output database: log, mysql, user=snort password=$SNORTSQLPASSWORD dbname=snort host=localhost" >> /etc/snort/barnyard2.conf
sudo chmod 766 /etc/snort/barnyard2.conf
sudo chmod o-r /etc/snort/barnyard2.conf
barnyard2 -V
echo -ne "\n\t${GREEN}[+] INFO:${NOCOLOR} ${BOLD}BARNYARD2${NOCOLOR} is successfully installed and configurated!"
}
function pulledpork_ask() {
echo -ne "\n\t${YELLOW}[!] IMPORTANT:${NOCOLOR} Would you like to install ${BOLD}PULLEDPORK${NOCOLOR}? [Y/n] "
while true; do
read OPTION
case $OPTION in
Y|y )
pulledpork_install
pulledpork_edit
break
;;
N|n )
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} ${BOLD}PULLEDPORK${NOCOLOR} won't be installed.\n\n"
break
;;
* )
echo -ne "\n\t${RED}[-] ERROR:${NOCOLOR} Invalid option.\n\n"
;;
esac
done
}
function pulledpork_install() {
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Installing dependencies.\n\n"
sudo apt-get install -y --force-yes libcrypt-ssleay-perl liblwp-useragent-determined-perl
cd $HOME/snort_src
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Downloading ${BOLD}PULLEDPORK${NOCOLOR}.\n\n"
git clone https://github.com/shirkdog/pulledpork.git
cd $HOME/snort_src/pulledpork
sudo cp pulledpork.pl /usr/local/bin > /dev/null 2>&1
sudo chmod +x /usr/local/bin/pulledpork.pl > /dev/null 2>&1
sudo cp etc/*.conf /etc/snort/ > /dev/null 2>&1
sudo mkdir /etc/snort/rules/iplists > /dev/null 2>&1
sudo touch /etc/snort/rules/iplists/default.blacklist > /dev/null 2>&1
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Adding ${BOLD}PULLEDPORK${NOCOLOR} to crontab. [Everyday at 4:15 AM].\n\n"
sudo chmod 766 /etc/crontab
sudo echo "15 4 * * * root pulledpork.pl -c /etc/snort/pulledpork.conf -i disablesid.conf -T -H" >> /etc/crontab
sudo pulledpork.pl -V
echo -ne "\n\t${GREEN}[+] INFO:${NOCOLOR} ${BOLD}PULLEDPORK${NOCOLOR} is successfully installed and configured!"
}
function pulledpork_edit() {
if [ "$(echo ${#OINKCODE})" == "40" ]; then
sudo sed -i "s/<oinkcode>/$OINKCODE/g" /etc/snort/pulledpork.conf
fi
while true; do
echo -ne "\n\t${YELLOW}[!] IMPORTANT:${NOCOLOR} Would you like to enable ${BOLD}Emerging Threats${NOCOLOR} rules? [Y/n] "
read OPTION
case $OPTION in
Y|y )
sudo sed -i "s/#rule_url=https:\/\/rules.emergingthreats.net\//rule_url=https:\/\/rules.emergingthreats.net\//g" /etc/snort/pulledpork.conf
echo -ne "\n\t${GREEN}[+] INFO:${NOCOLOR} ${BOLD}Emerging Threats${NOCOLOR} rules enabled!"
break
;;
N|n )
echo -ne "\n\t${GREEN}[+] INFO:${NOCOLOR} ${BOLD}Emerging Threats${NOCOLOR} rules disabled!"
break
;;
* )
echo -ne "\n\t${RED}[-] ERROR:${NOCOLOR} Invalid option."
;;
esac
done
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Editing ${BOLD}pulledpork.conf${NOCOLOR} settings...\n"
sudo sed -i "s/\/usr\/local\/etc\/snort\//\/etc\/snort\//g" /etc/snort/pulledpork.conf
sudo sed -i "s/# enablesid=/enablesid=/g" /etc/snort/pulledpork.conf
sudo sed -i "s/# dropsid=/enablesid=/g" /etc/snort/pulledpork.conf
sudo sed -i "s/# disablesid=/enablesid=/g" /etc/snort/pulledpork.conf
sudo sed -i "s/# modifysid=/enablesid=/g" /etc/snort/pulledpork.conf
sudo sed -i "s/distro=FreeBSD-8-1/distro=Debian-8-4/g" /etc/snort/pulledpork.conf
}
function service_create() {
while true; do
echo -ne "\n\t${YELLOW}[!] IMPORTANT:${NOCOLOR} Would you like to create a service ${BOLD}snort${NOCOLOR}? [Y/n] "
read OPTION
case $OPTION in
Y|y )
service_add
sudo update-rc.d snort defaults
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Now you can run ${BOLD}sudo service snort {start|stop|status}${NOCOLOR}.\n\n"
break
;;
N|n )
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} The service ${BOLD}snort${NOCOLOR} won't be created.\n\n"
break
;;
* )
echo -ne "\n\t${RED}[-] ERROR:${NOCOLOR} Invalid option.\n\n"
;;
esac
done
if [ -f /etc/snort/pulledpork.conf ]; then
while true; do
echo -ne "\n\t${YELLOW}[!] IMPORTANT:${NOCOLOR} Would you like to download new rules using ${BOLD}PULLEDPORK${NOCOLOR}? [Y/n] "
read OPTION
case $OPTION in
Y|y )
sudo pulledpork.pl -c /etc/snort/pulledpork.conf -i disablesid.conf -T -H
break
;;
N|n )
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} The service ${BOLD}snort${NOCOLOR} won't be created.\n\n"
break
;;
* )
echo -ne "\n\t${RED}[-] ERROR:${NOCOLOR} Invalid option.\n\n"
;;
esac
done
fi
}
function service_add() {
if [ -f /etc/snort/barnyard2.conf ]; then
sudo chmod 777 /etc/init.d
sudo echo """
#!/bin/bash
# /etc/init.d/snort
### BEGIN INIT INFO
# Provides: snortblaster
# Required-Start: \$remote_fs \$syslog
# Required-Stop: \$remote_fs \$syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This service is used to start snort
### END INIT INFO
case '\$1' in
start)
echo 'Starting Snort in IDS mode'
/usr/local/bin/snort -q -u snort -g snort -c /etc/snort/snort.conf -i $INTERFACE &
/usr/local/bin/barnyard2 -c /etc/snort/barnyard2.conf -d /var/log/snort -f snort.u2 -w /var/log/snort/barnyard2.waldo -g snort -u snort &
;;
stop)
echo 'Stopping Snort'
killall snort
;;
*)
echo 'Usage: /etc/init.d/snort start|stop'
exit 1
;;
esac
exit 0
""" > /etc/init.d/snort
sudo chmod +x /etc/init.d/snort
elif [ ! -f /etc/snort/barnyard2.conf ]; then
sudo chmod 777 /etc/init.d
sudo echo """
#!/bin/bash
# /etc/init.d/snort
### BEGIN INIT INFO
# Provides: snortblaster
# Required-Start: \$remote_fs \$syslog
# Required-Stop: \$remote_fs \$syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This service is used to start snort
### END INIT INFO
case '\$1' in
start)
echo 'Starting Snort in IDS mode'
/usr/local/bin/snort -q -u snort -g snort -c /etc/snort/snort.conf -i $INTERFACE &
;;
stop)
echo 'Stopping Snort'
killall snort
;;
*)
echo 'Usage: /etc/init.d/snort start|stop'
exit 1
;;
esac
exit 0
""" > /etc/init.d/snort
sudo chmod +x /etc/init.d/snort
fi
}
function websnort_ask() {
echo -ne "\n\t${YELLOW}[!] IMPORTANT:${NOCOLOR} Would you like to install ${BOLD}WEBSNORT${NOCOLOR} for PCAP Analysis? [Y/n] "
while true; do
read OPTION
case $OPTION in
Y|y )
websnort_install
break
;;
N|n )
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} ${BOLD}WEBSNORT${NOCOLOR} won't be installed.\n\n"
break
;;
* )
echo -ne "\n\t${RED}[-] ERROR:${NOCOLOR} Invalid option.\n\n"
;;
esac
done
}
function websnort_install() {
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Installing dependencies.\n\n"
sudo apt-get install -y --force-yes python-pip
sudo pip install websnort > /dev/null 2>&1
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} running ${BOLD}WEBSNORT${NOCOLOR} on ${BOLD}http://localhost:80${NOCOLOR}.\n\n"
sudo websnort -p 80 > /dev/null 2>&1 &
echo -ne "\n\t${YELLOW}[!] IMPORTANT:${NOCOLOR} Would you like to start ${BOLD}WEBSNORT${NOCOLOR} with the system? [Y/n] "
while true; do
read OPTION
case $OPTION in
Y|y )
echo "sudo websnort -p 80 > /dev/null 2>&1 &" >> $HOME/.bashrc
break
;;
N|n )
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} ${BOLD}WEBSNORT${NOCOLOR} won't start at system boot."
echo -ne "\n\t${YELLOW}[!] INFO:${NOCOLOR} run ${BOLD}sudo websnort -p 80${NOCOLOR} everytime you need ${BOLD}WEBSNORT${NOCOLOR}."
break
;;
* )
echo -ne "\n\t${RED}[-] ERROR:${NOCOLOR} Invalid option.\n\n"
;;
esac
done
echo -ne "\n\t${GREEN}[+] INFO:${NOCOLOR} ${BOLD}WEBSNORT${NOCOLOR} is successfully installed and configured!"
}
function last_steps() {
echo -ne "\n\t${YELLOW}[!] IMPORTANT:${NOCOLOR} Now edit your ${BOLD}/etc/snort/snort.conf${NOCOLOR} and enable the rules you need by uncomment the lines"
echo -ne "\n\t${YELLOW}[!] EXAMPLE:${NOCOLOR} If you want to enable the ${BOLD}Exploit rules${NOCOLOR}, remove the ${RED}${BOLD}#${NOCOLOR}:"
echo -ne "\n\t\t${RED}#${NOCOLOR}include \$RULE_PATH/exploit.rules ${GREEN}-->${NOCOLOR} include \$RULE_PATH/exploit.rules\n\n"
}
function system_reboot() {
while true; do
echo -ne "\n\t${YELLOW}[!] IMPORTANT:${NOCOLOR} Would you like to ${BOLD}REBOOT${NOCOLOR} now? [Y/n] "
read OPTION
case $OPTION in
Y|y )
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Rebooting...\n\n"
sleep 1
sudo reboot
break
;;
N|n )
echo -ne "\n\t${CYAN}[i] INFO:${NOCOLOR} Exiting from the installer. Enjoy ${BOLD}SNORT${NOCOLOR}!\n\n"
break
;;
* )
echo -ne "\n\t${RED}[-] ERROR:${NOCOLOR} Invalid option.\n\n"
;;
esac
done
}
function banner() {
echo -ne """
,-,------,
\\\\(\\\\(_,-- ${RED} ███████╗${ORANGE}███╗ ██╗${YELLOW} ██████╗ ${GREEN}██████╗ ${CYAN}████████╗${BLUE}███████╗${VIOLET}██████╗ ${NOCOLOR}
<\\--/\>/(/(__ ${RED} ██╔════╝${ORANGE}████╗ ██║${YELLOW}██╔═══██╗${GREEN}██╔══██╗${CYAN}╚══██╔══╝${BLUE}██╔════╝${VIOLET}██╔══██╗ ${NOCOLOR}
/. . \ ${RED} ███████╗${ORANGE}██╔██╗ ██║${YELLOW}██║ ██║${GREEN}██████╔╝${CYAN} ██║ ${BLUE}█████╗ ${VIOLET}██████╔╝ ${NOCOLOR}
('') , @ ${RED} ╚════██║${ORANGE}██║╚██╗██║${YELLOW}██║ ██║${GREEN}██╔══██╗${CYAN} ██║ ${BLUE}██╔══╝ ${VIOLET}██╔══██╗ ${NOCOLOR}
\_._, / ${RED} ███████║${ORANGE}██║ ╚████║${YELLOW}╚██████╔╝${GREEN}██║ ██║${CYAN} ██║ ${BLUE}███████╗${VIOLET}██║ ██║ ${NOCOLOR}
)-)_/--( > ${RED} ╚══════╝${ORANGE}╚═╝ ╚═══╝${YELLOW} ╚═════╝ ${GREEN}╚═╝ ╚═╝${CYAN} ╚═╝ ${BLUE}╚══════╝${VIOLET}╚═╝ ╚═╝ ${NOCOLOR}
'''' ''''
"""
}
function help_usage() {
echo -ne "\n\t\t${YELLOW}USAGE:${NOCOLOR} sudo $0 -i ${GREEN}INTERFACE${NOCOLOR}"
echo -ne "\n\t\t${YELLOW}USAGE:${NOCOLOR} sudo $0 -o ${GREEN}OINKCODE${NOCOLOR} -i ${GREEN}INTERFACE${NOCOLOR}"
echo -ne "\n\t\t${YELLOW}Example:${NOCOLOR} sudo $0 -o ${GREEN}123456abcdefgh${NOCOLOR} -i ${GREEN}eth0${NOCOLOR}\n\n"
exit 0
}
function main() {
check_root
update_upgrade
snort_install
snort_edit
snort_test
barnyard2_ask
pulledpork_ask
service_create
websnort_ask
last_steps
system_reboot
}
#PARSE PARAMETERS/CHECK FOR INTERFACE/CHECK FOR OINKCODE
banner
while getopts ":o:i:" OPTION; do
case "${OPTION}" in
o)
OINKCODE=${OPTARG}
;;
i)
INTERFACE=${OPTARG}
;;
*)
help_usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${INTERFACE}" ] ; then
echo -ne "\n\t\t${RED}[-] ERROR:${NOCOLOR} ${BOLD}Interface${NOCOLOR} is mandatory\n"
help_usage
fi
if [ "$(echo ${#OINKCODE})" -eq 40 ]; then
MACHINE=$(echo $(uname -m))
SNORT=$(echo $(curl -s https://www.snort.org | grep "wget" | grep -oP "snort\-\d.\d\.\d(\.\d)?"))
DAQ=$(echo $(curl -s https://www.snort.org | grep "wget" | grep -oP "daq\-\d\.\d\.\d"))
echo -ne "\n\t\t${GREEN}[+] OINKCODE:${NOCOLOR} ${OINKCODE}"
echo -ne "\n\t\t${GREEN}[+] INTERFACE:${NOCOLOR} ${INTERFACE}"
echo -ne "\n\t\t${GREEN}[+] DAQ:${NOCOLOR} $DAQ"
echo -ne "\n\t\t${GREEN}[+] SNORT:${NOCOLOR} $SNORT"
echo -ne "\n\t\t${GREEN}[+] ARCH:${NOCOLOR} $MACHINE\n\n"
main
elif [ "$(echo ${#OINKCODE})" -lt 40 ] && [ "$(echo ${#OINKCODE})" -gt 0 ]; then
echo -ne "\n\t\t${RED}[-] ERROR:${NOCOLOR} Invalid ${BOLD}OINKCODE${NOCOLOR}\n"
help_usage
elif [ $(echo ${#OINKCODE}) -lt 40 ] || [ $(echo ${#OINKCODE}) -gt 1 ]; then
MACHINE=$(echo $(uname -m))
SNORT=$(echo $(curl -s https://www.snort.org | grep "wget" | grep -oP "snort\-\d.\d\.\d(\.\d)?"))
DAQ=$(echo $(curl -s https://www.snort.org | grep "wget" | grep -oP "daq\-\d\.\d\.\d"))
echo -ne "\n\t\t${GREEN}[+] OINKCODE:${NOCOLOR} No OINKCODE provided."
echo -ne "\n\t\t${GREEN}[+] INTERFACE:${NOCOLOR} ${INTERFACE}"
echo -ne "\n\t\t${GREEN}[+] DAQ:${NOCOLOR} $DAQ"
echo -ne "\n\t\t${GREEN}[+] SNORT:${NOCOLOR} $SNORT"
echo -ne "\n\t\t${GREEN}[+] ARCH:${NOCOLOR} $MACHINE\n\n"
main
fi