forked from hadojae/redonion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredonion_bootstrap_6.sh
executable file
·1431 lines (1277 loc) · 51.5 KB
/
redonion_bootstrap_6.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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#######################################
# Red Onion Install Script v0.1
# https://github.com/hadojae/redonion
# tested on Centos/RHEL 6.6
########################################
####################################################
### MODIFY THESE GLOBALS TO SUIT YOUR DEPLOYMENT ###
####################################################
sniff_int="eth1" # Whatever interface you will use for sniffing
manage_int="eth0" # Whatever interface you will use for management
manage_ip="10.10.2.113" # Management IP address
user_drop="ro" # A user account to drop permissions to during install
wrk_dir="/home/ro/redonion" # The directory you will be installing from
num_bro_pf_proc="4" # The number of BRO load balanced worked processes you want to run
install_dir="/opt" # Where you want to install the tools
pf_num_rings="32768" # Number of rings you want to allocate for pf_ring
pf_trans_mode="0" # Mode you want pf_ring to run in - 0 (no pfring nic drivers) 1 (both) or 2 (only pfring drivers)
etpro_license="" # Enter in etpro license, if empty will install community ruleset
proxy_ip="" # Proxy IP address/dns
proxy_port="" # Proxy Port
### Moloch Config Variables ###
es_mem="1G" # How much memory should elasticsearch for moloch have? (< 32G)
moloch_user="ro" # What user should moloch use
moloch_group="ro" # What group should moloch use
moloch_password="OmG_R0_Rul3z!1!" # Password for Moloch
moloch_fqdn="redonion.localhost" # FQDN for Moloch Cert
moloch_country="US" # Country for Moloch Cert
moloch_state="IL" # State for Moloch Cert
moloch_orgname="BLAH" # Org Name for Moloch Cert
moloch_orgunit="NO" # Org unit for Moloch Cert
moloch_locality="HERE" # Locality for Moloch Cert
es_ver="1.5.2" # What version of elasticsearch are you using for moloch?
esdb_dir="$install_dir/esdb" # Where should Moloch store elasticsearch data?
pcap_data_dir="$install_dir/moloch/raw" # Where should Moloch store raw pcaps? eg. $dir_1;$dir_2;$dir_3
#netflow_collector="10.10.2.120:9995" # IP address and port of a netflow collector. If none leave empty.
#netflow_version="5" # What version of Netflow do you want to use? If none leave empty.
### Log Aggregation Globals ###
log_method="logstash_elasticsearch" # options are splunk, logstash_elasticsearch, or logstash_syslog
splunk_fwd="10.10.2.23:9997" # if using splunk, the ip and port you're forwarding logs to, if multiple separate by comma and space
splunk_bro_index="redonion_bro" # if using splunk, the name of the index you want to use for Bro logs
splunk_suricata_index="redonion_suri" # if using splunk, the name of the index you want to use for Suricata logs
logstash_elasticsearch_host="10.10.2.23" # if using logstash_elasticsearch mode - the host/ip of your receiving node on your cluster
logstash_elasticsearch_port=9200 # if using logstash_elasticsearch mode - the port elasticsearch wants traffic on *no quotes
logstash_syslog_ip="10.10.2.23" # if using logstash_syslog, the ip of your syslog receiver
logstash_syslog_port=514 # if using logstash_syslog, the port your syslog receiver expects traffic on *no quotes
logstash_syslog_protocol="udp" # if using logstash_syslog, the protocol you want to use - tcp or udp
#############################################
##### LEAVE EVERYTHING BELOW THIS ALONE #####
#############################################
# Pretty status notifications / error handling function
print_status()
{
echo -e "\x1B[01;34m[*]\x1B[0m $1"
}
print_good()
{
echo -e "\x1B[01;32m[*]\x1B[0m $1"
}
print_error()
{
echo -e "\x1B[01;31m[*]\x1B[0m $1"
}
print_notification()
{
echo -e "\x1B[01;33m[*]\x1B[0m $1"
}
handle_error()
{
if [ $? == 0 ]; then
print_good "Success!"
else
print_error "Failure...exiting..."
exit $?
fi
}
pause()
{
read -p "$*"
}
space_pls()
{
echo -e "\n";
}
logo()
{
space_pls
echo -e "\x1B[01;31m.______ ._______.______ ._______ .______ .___ ._______ .______ \x1B[0m"
echo -e "\x1B[01;31m: __ \ : .____/:_ _ \ : .___ \ : \ : __|: .___ \ : \ \x1B[0m"
echo -e "\x1B[01;31m| \____|| : _/\ | | | | : | || || : || : | || |\x1B[0m"
echo -e "\x1B[01;31m| : \ | / \| . | | | : || | || || : || | |\x1B[0m"
echo -e "\x1B[01;31m| |___\|_.: __/|. ____/ \_. ___/ |___| || | \_. ___/ |___| |\x1B[0m"
echo -e "\x1B[01;31m|___| :/ :/ :/ |___||___| :/ |___|\x1B[0m"
echo -e "\x1B[01;31m : : : \x1B[0m"
echo -e ""
echo -e "\x1B[01;30m CENTOS/RHEL+PFRING+SURICATA+BRO+MOLOCH+ET+SPLUNK/ELK==WIN! \x1B[0m"
echo -e ""
echo -e "\x1B[01;32m REDONION v0.1 {https://github.com/hadojae/redonion} \x1B[0m"
space_pls
}
########################################
# Functions...
letsgo()
{
#Check for root user
if [ "$UID" -eq 0 ]; then
sleep 0
else
print_error "Check for root user failed. Please run this script as root."
exit 1
fi
# Check to see that we're on 6.7 Centos
if [ -f /etc/centos-release ]; then
distro="CentOS"
if [[ ! `grep 6.7 /etc/centos-release` ]]; then
print_error "This build script is tested on CENTOS 6.7. Please update via yum."
exit 0
fi
fi
# Haven't tested on RHEL7 yet
if [ -f /etc/redhat-release ]; then
distro="RHEL"
if [[ ! `grep 6.7 /etc/redhat-release` ]]; then
print_error "This build script is tested on RHEL 6.7. Please update via yum or if you're on 7, sorry this doesnt work yet.."
exit 0
fi
fi
# Check for known bad kernel
if [ `uname -r` == "2.6.32-504.el6.x86_64" ]; then
print_error "It looks like you need to update and reboot. This kernel is no good for pf_ring stuff."
exit 0
fi
# Make sure that we are running on RHEL or Centos
if [[ ! -f /etc/redhat-release && ! -f /etc/centos-release ]]; then
print_error "I'm sorry, this distibution is not yet supported."
exit 0
fi
# Make sure that there are no kernel updates.
if [[ -z `yum check-update | grep kernel` ]]; then
print_good "Kernel appears to be up to date."
else
print_error "You appear to have kernel updates available. Please update via yum, reboot and run this script again."
exit 0
fi
# Warn the user if we are not installing on the newest kernel version
newest_kernel=$(rpm -q --last kernel | perl -pe 's/^kernel-(\S+).*/$1/' | head -1)
current_kernel=$(uname -r)
if [ ! $newest_kernel == $current_kernel ]; then
print_error "It looks like you are not installing on the most recent kernel. Are you sure you don't want to reboot before you run this?"
pause "Please press [ENTER] to continue or CTRL+C to quit."
fi
# Make sure epel is installed on centos
if [ -f /etc/centos-release ]; then
if [[ ! `yum repolist | grep epel | awk '{ print $1 }'` ]]; then
print_status "Epel not found, installing epel..."
rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
handle_error
fi
fi
# Check to make sure that the user that we are running as and dropping permissions to exists
if id -u "$user_drop" >/dev/null 2>&1; then
print_good "user $user_drop exists"
else
print_error "The user \"$user_drop\" does not exist. Please create the user or select and different user and run again."
exit 0
fi
# Check to see that the first character of wrk_dir and install_dir are / and that the last is not a /
if [[ `echo $wrk_dir | head -c 1` != "/" ]]; then
print_error "It looks like you dont have a / as the first character in the wrk_dir variable. Full path please."
exit 0
fi
if [[ `echo $install_dir | head -c 1` != "/" ]]; then
print_error "It looks like you dont have a / as the first character in the install_dir variable. Full path please."
exit 0
fi
if [ `echo ${install_dir: -1} == "/"` ]; then
print_error "It looks like you included a trailing / in the install_dir variable, remove that."
exit 0
fi
if [ `echo ${wrk_dir: -1} == "/"` ]; then
print_error "It looks like you included a trailing / in the wrk_dir variable, remove that."
exit 0
fi
#Check to see that timezone is set to UTC
if [[ -z `date | grep UTC` ]]; then
print_error "Looks like UTC isnt set. You want this."
rm -rf /etc/localtime
ln -f -s /usr/share/zoneinfo/UTC /etc/localtime
fi
# Check to see that root umask 022 at login
if [[ -z "$(grep 022 /root/.bashrc)" ]]; then
print_error "Root needs umask 022"
echo -e "umask 022" >> /root/.bashrc
source /root/.bashrc
umask 022
if [[ $(umask) != 0022 ]]; then
print_error "IDK. Something didnt work."
exit 0
fi
fi
# Make sure swap is off
swapoff -a
if [[ -z `crontab -l | grep swapoff` ]]; then
print_error "Swap is not disabled at boot, fixing."
line_swapoff="@reboot swapoff -a"
(crontab -l; echo "$line_swapoff") | crontab -
handle_error
fi
# Add unlimited memlock
if [[ -z "$(grep -E 'memlock.*unlimited' /etc/security/limits.conf)" ]]; then
print_error "Memlock is not set to unlimited, fixing."
echo -e "* - memlock unlimited" >> /etc/security/limits.conf
fi
#Check to see that the sniffing ethernet port is up and configured properly
if [[ $sniff_int != $manage_int ]]; then
# Don't use ifconfig it's deprecated. opt for IPROUTE2
if [[ -z `ifconfig | grep $sniff_int` ]]; then
print_error "Looks like the interface isnt configured..."
sed -i 's/ONBOOT=no/ONBOOT=yes/' /etc/sysconfig/network-scripts/ifcfg-$sniff_int
sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=static/' /etc/sysconfig/network-scripts/ifcfg-$sniff_int
echo -e "PROMISC=yes" >> /etc/sysconfig/network-scripts/ifcfg-$sniff_int
echo -e "IPV6INIT=no" >> /etc/sysconfig/network-scripts/ifcfg-$sniff_int
echo -e "PEERDNS=no" >> /etc/sysconfig/network-scripts/ifcfg-$sniff_int
service network restart
ifconfig $sniff_int promisc
ethtool -G $sniff_int rx 4096 #Add this to crontab @reboot
ifconfig $sniff_int txqueuelen 10000
fi
else
ifconfig $sniff_int promisc
ethtool -G $sniff_int rx 4096 #Add this to crontab @reboot
ifconfig $sniff_int txqueuelen 10000
fi
# Kernel Tuning
# http://pevma.blogspot.com/2014/03/suricata-prepearing-10gbps-network.html
if [[ "$(sysctl -n net.core.netdev_max_backlog)" -ne 250000 ]]; then
echo 'net.core.netdev_max_backlog=250000' >> /etc/sysctl.conf
echo 'net.core.rmem_max=16777216' >> /etc/sysctl.conf
echo 'net.core.rmem_default=16777216' >> /etc/sysctl.conf
echo 'net.core.optmem_max=16777216' >> /etc/sysctl.conf
sysctl -p
fi
#Check to see if we need to deal with a proxy and make sure it starts with http
if [ -z $proxy_ip ]; then
proxy_status=false
else
proxy_status=true
if [[ -z `echo $proxy_ip | grep http` ]]; then
print_error "The proxy IP needs to begin with http, please change it."
exit 0
fi
fi
#Check to see that all the global variables are properly set
if [[ -z "$sniff_int" || -z "$manage_int" || -z "$manage_ip" || -z "$user_drop" || -z "$wrk_dir" || -z "$install_dir" || -z "$proxy_status" || -z "$num_bro_pf_proc" || -z "$pf_num_rings" || -z "$pf_trans_mode" ]]; then
print_error "You must set the mandatory global variables."
exit 0
fi
#Check to see if we're using ETPro or ET Community sigs
if [[ -z "$etpro_license" ]]; then
et_status="ET Community Ruleset"
else
et_status="ET PRO Ruleset"
fi
#Check to see if we're installing moloch
if [[ $launch_param == "-ro" || $launch_param == "-moloch" ]]; then
moloch_me_maybe=true
if [[ -z "$es_mem" || -z "$moloch_user" || -z "$moloch_password" || -z "$moloch_group" || -z "$moloch_fqdn" || -z "$moloch_country" || -z "$moloch_state" || -z "$moloch_orgname" || -z "$moloch_orgunit" || -z "$moloch_locality" || -z "$es_ver" || -z "$esdb_dir" || -z "$pcap_data_dir" ]]; then
print_error "You appear to be installing moloch and have not properly set all the variables."
exit 0
fi
fi
#Check to see if we've properly set log aggregation variables...
if [[ $launch_param == "-ro" || $launch_param == "-logagg" ]]; then
if [ -z $log_method ]; then
print_error "Make sure you've set the log_method global variable."
exit 0
fi
if [[ $log_method != "logstash_elasticsearch" && $log_method != "logstash_syslog" && $log_method != "splunk" ]]; then
print_error "Make sure you've selected one of the log aggregation options. Make sure there are no typos. :)"
fi
if [[ -z $splunk_bro_index || -z $splunk_suricata_index ]]; then
print_error "Make sure you've set the log aggregation index variables for bro and suricata."
exit 0
fi
if [[ $log_method == "splunk" ]]; then
if [ -z $splunk_fwd ]; then
print_error "Since you selected to use splunk log aggregation, you need to set the splunk_fwd variable."
exit 0
fi
fi
if [[ $log_method == "logstash_elasticsearch" ]]; then
if [ -z $logstash_elasticsearch_host ]; then
print_error "Since you selected to use the logstash_elasticsearch log aggregation, you need to set the logstash_elasticsearch_host global variable to tell us where to send logs."
exit 0
fi
fi
if [[ $log_method == "logstash_elasticsearch" ]]; then
if [ -z $logstash_elasticsearch_port ]; then
print_error "Since you selected to use the logstash_elasticsearch log aggregation, you need to set the logstash_elasticsearch_port global variable to tell us where to send logs."
exit 0
fi
fi
if [[ $log_method == "logstash_syslog" ]]; then
if [ -z $logstash_syslog_ip ]; then
print_error "Since you selected to use logstash_syslog log aggregation, you need to set the logstash_syslog_ip variable so we know where to send syslog."
exit 0
fi
fi
if [[ $log_method == "logstash_syslog" ]]; then
if [ -z $logstash_syslog_port ]; then
print_error "Since you selected to use logstash_syslog log aggregation, you need to set the logstash_syslog_port variable so we know where to send syslog."
exit 0
fi
fi
if [[ $log_method == "logstash_syslog" ]]; then
if [ -z $logstash_syslog_protocol ]; then
print_error "Since you selected to use logstash_syslog log aggregation, you need to set the logstash_syslog_protocol variable so we know what protocol to send syslog on."
exit 0
fi
fi
fi
# Check to see that NTOP repo is there, if not, write it
cat << EOF > /etc/yum.repos.d/ntop.repo
[ntop]
name=ntop packages
baseurl=http://packages.ntop.org/centos-stable/6Server/x86_64/
enabled=1
#proxy=$proxy_ip:$proxy_port
gpgcheck=1
gpgkey=http://packages.ntop.org/centos-stable/RPM-GPG-KEY-deri
[ntop-noarch]
name=ntop packages
baseurl=http://packages.ntop.org/centos-stable/6Server/noarch/
enabled=1
#proxy=$proxy_ip:$proxy_port
gpgcheck=1
gpgkey=http://packages.ntop.org/centos-stable/RPM-GPG-KEY-deri
EOF
if [ $proxy_status == true ]; then
sed -i "s/#proxy=/proxy=/" /etc/yum.repos.d/ntop.repo
fi
# set proxies if needed
if [ $proxy_status == true ]; then
#Normal proxy stuff (wget, curl, yum)
HTTP_PROXY=$proxy_ip":"$proxy_port
http_proxy=$proxy_ip":"$proxy_port
HTTPS_PROXY=$proxy_ip":"$proxy_port
https_proxy=$proxy_ip":"$proxy_port
ftp_proxy=$proxy_ip":"$proxy_port
export http_proxy https_proxy ftp_proxy HTTP_PROXY HTTPS_PROXY
#GIT proxy stuff
git config --global http.proxy $proxy_ip:$proxy_port
git config --global https.proxy $proxy_ip:$proxy_port
#NPM proxy stuff
#npm config set proxy $proxy_ip:$proxy_port
#npm config set https-proxy $proxy_ip:$proxy_port
fi
# Check to see if a pfring enabled driver is enabled on the sniffing interface.
sniff_driver=$(ethtool -i $sniff_int | grep driver | awk '{ print $2 }')
if [[ $sniff_driver == "igb" || $sniff_driver == "ixgbe" || $sniff_driver == "e1000e" ]]; then
pfring_zc_enabled=true
else
pfring_zc_enabled=false
print_error "Your server doesnt appear have a pfring supported nic, you are using $sniff_driver."
print_error "We will continue to build, but you may see issues at large capture rates without a pfring supported nic."
if [ $pf_trans_mode != 0 ]; then
print_error "You need to set the pf_trans_mode global variable to 0 as you are not using a pfring supported nic."
exit 0
fi
fi
#Print build debugging statement to show all the variables set
echo -e ""
print_good "I will now be building \x1B[01;31m$build_param\x1B[0m on $distro with the following specifications:"
echo -e ""
# General build stuff
print_status "Working directory: $wrk_dir"
print_status "Installation directory: $install_dir"
print_status "Sniffing interface: $sniff_int"
print_status "Management interface: $manage_int"
print_status "Management IP Address: $manage_ip"
print_status "Drop permissions to: $user_drop"
print_status "Proxy status: $proxy_status"
# Bro
if [[ $launch_param == "-ro" || $launch_param == "-bro" ]]; then
print_status "BRO pfring load balancers: $num_bro_pf_proc"
fi
# Pfring
if [[ $launch_param == "-ro" || $launch_param == "-pfring" ]]; then
print_status "Pfring number of rings: $pf_num_rings"
print_status "Pfring transparent mode: $pf_trans_mode"
fi
# Log Aggregation
if [[ $launch_param == "-ro" || $launch_param == "-logagg" ]]; then
print_status "Log Aggregation: $log_method"
if [[ $log_method == "splunk" ]]; then
print_status "Splunk Forwarder IP: $splunk_fwd"
print_status "Bro Index Name: $bro_index"
print_status "Suricata Index Name: $suricata_index"
elif [[ $log_method == "logstash_elasticsearch" ]]; then
print_status "Log Aggregation Elasticsearch Host: $logstash_elasticsearch_host"
print_status "Log Aggregation Elasticsearch Port: $logstash_elasticsearch_port"
elif [[ $log_method == "logstash_syslog" ]]; then
print_status "Syslog Receiver IP: $logstash_syslog_ip"
print_status "Syslog Receiver Port : $logstash_syslog_port"
print_status "Syslog Receiver Protocol: $logstash_syslog_protocol"
fi
fi
# ETPRO
if [[ $launch_param == "-ro" || $launch_param == "-suricata" ]]; then
print_status "EmergingThreats License: $et_status"
fi
# Moloch
if [[ $moloch_me_maybe == true ]]; then
print_status "Memory Allocated to ES: $es_mem"
print_status "Elasticsearch Version: $es_ver"
print_status "Elasticsearch DB Location: $esdb_dir"
print_status "Raw Pcap Storage Location: $pcap_data_dir"
print_status "Moloch User: $moloch_user"
print_status "Moloch Group: $moloch_group"
print_status "Moloch Password: $moloch_password"
print_status "Moloch FQDN: $moloch_fqdn"
print_status "Moloch Country: $moloch_country"
print_status "Moloch State: $moloch_state"
print_status "Moloch Org Name: $moloch_orgname"
print_status "Moloch Org Unit: $moloch_orgunit"
print_status "Moloch Locality: $moloch_locality"
fi
# Date
print_status "Current Date: $(date)"
echo -e ""
pause "Please verify the above settings and press [ENTER] to continue or CTRL+C to quit."
}
pf_ring_rpm()
{
space_pls
print_status "!!!!!!!!!!!!!!!!!!!!!!!!!!"
print_status "!!! Installing PF_RING !!!"
print_status "!!!!!!!!!!!!!!!!!!!!!!!!!!"
space_pls
# Install prereqs
if [ -f /etc/centos-release ]; then
yum -y install numactl-devel vim-enhanced wget kernel-headers flex bison gcc gcc-c++ make kernel-devel man man-pages screen htop
fi
sniff_driver=$(ethtool -i $sniff_int | grep driver | awk '{ print $2 }')
if [[ $sniff_driver == "igb" || $sniff_driver == "e1000e" || $sniff_driver == "ixgbe" ]]; then
pfring_zc_enabled=true
else
pfring_zc_enabled=false
fi
# Check to see if we want to install...
SKIP=0
if [ -d "$install_dir/pfring/kernel" ]; then
print_error "It looks like pfring may already be downloaded, do you want to install it again? (y/n): "
read answer
if [[ $answer == "y" ]] ; then
print_status "Pulling pfring src from Github"
git clone -b 6.0.3-stable https://github.com/ntop/PF_RING $install_dir/pfring
handle_error
SKIP=0
else
SKIP=1
fi
else
print_status "Pulling pfring src from Github"
git clone https://github.com/ntop/PF_RING $install_dir/pfring
handle_error
fi
if [[ $SKIP == 0 ]]; then
# Compile Kernel Module
print_status "cd $install_dir/pfring/kernel..."
cd $install_dir/pfring/kernel
handle_error
print_status "chown -R $user_drop:$user_drop $install_dir/pfring/..."
chown -R $user_drop:$user_drop $install_dir/pfring/
handle_error
if [ $pfring_zc_enabled == true ]; then
print_status "yum clean all"
yum clean all
handle_error
print_status "yum update"
yum update
handle_error
print_status "yum install pfring dkms stuff via ntop repo"
yum -y install pfring pfring-drivers-zc-dkms igb-zc
handle_error
dkms status
sleep 10
else
print_status "yum clean all"
yum clean all
handle_error
print_status "yum update"
yum update
handle_error
print_status "yum install pfring"
yum -y install pfring
handle_error
dkms status
sleep 10
fi
# Compile Userland Libraries
print_status "Compiling userland libraries..."
print_status "cd ../userland/lib..."
cd ../userland/lib
handle_error
print_status "./configure --prefix=/usr/local/pfring..."
./configure --prefix=/usr/local/pfring
handle_error
print_status "make clean..."
make clean
handle_error
print_status "make..."
make
handle_error
print_status "make install..."
make install
handle_error
# Build Libpcap - libpcap is lnk to the numbered version in the same dir...
print_status "Building libpcap..."
print_status "cd ../libpcap..."
cd ../libpcap
handle_error
print_status "./configure --prefix=/usr/local/pfring..."
./configure --prefix=/usr/local/pfring
handle_error
print_status "make clean..."
make clean
handle_error
print_status "make..."
make
handle_error
print_status "make install..."
make install
handle_error
# Build tcpdump
print_status "Building tcpdump..."
print_status "cd ../tcpdump-4.1.1..."
cd ../tcpdump-4.1.1
handle_error
print_status "./configure --prefix=/usr/local/pfring..."
./configure --prefix=/usr/local/pfring
handle_error
print_status "make clean..."
make clean
handle_error
print_status "make..."
make
handle_error
print_status "make install..."
make install
handle_error
ldconfig
handle_error
# Load Kernel Module
print_status "Loading kernel module..."
print_status "modprobe pf_ring..."
modprobe pf_ring transparent_mode=$pf_trans_mode enable_tx_capture=0 min_num_slots=$pf_num_rings
handle_error
lsmod | grep pf_ring
sleep 10
# Configure Linker
print_status "Configuring linker..."
echo "/usr/local/lib" > /etc/ld.so.conf.d/local.conf && ldconfig
handle_error
# Load at boot
print_status "Setting up persistance..."
print_status "modprobe pf_ring...set options..."
echo "modprobe pf_ring transparent_mode=$pf_trans_mode enable_tx_capture=0 min_num_slots=$pf_num_rings" > /etc/sysconfig/modules/pf_ring.modules
handle_error
if [ $pfring_zc_enabled == true ]; then
print_status "echo "modprobe ${sniff_driver}_zc" >> /etc/sysconfig/modules/pf_ring.modules..."
echo "modprobe ${sniff_driver}_zc" >> /etc/sysconfig/modules/pf_ring.modules
handle_error
fi
print_status "chmod +x /etc/sysconfig/modules/pf_ring.modules..."
chmod +x /etc/sysconfig/modules/pf_ring.modules
handle_error
if [ $pfring_zc_enabled == true ]; then
print_status "fixing up /etc/modprobe.d/pfring-zc.conf for reboot so that it loads the right igb-zc driver instead of igb..."
sed -i "s,$sniff_driver-zc,$sniff_driver," /etc/modprobe.d/pfring-zc.conf
handle_error
fi
# Enable NIC driver if needed
if [ $pfring_zc_enabled == true ]; then
print_status "Unloading nic driver for sniffing interface...assuming $sniff_driver..."
rmmod $sniff_driver
handle_error
modprobe ${sniff_driver}_zc
handle_error
lsmod | grep pf_ring
lsmod | grep ${sniff_driver}_zc
sleep 10
fi
print_status "moving back to the working dir..."
cd $wrk_dir
handle_error
else
space_pls
print_good "Skipped PF_RING install..."
fi
space_pls
print_status "PF_RING install has completed."
space_pls
}
bro()
{
print_status "!!!!!!!!!!!!!!!!!!!!!!!!!!"
print_status "!!!!! Installing BRO !!!!!"
print_status "!!!!!!!!!!!!!!!!!!!!!!!!!!"
space_pls
sniff_driver=$(ethtool -i $sniff_int | grep driver | awk '{ print $2 }')
if [[ $sniff_driver == "igb" || $sniff_driver == "e1000e" || $sniff_driver == "ixgbe" ]]; then
pfring_zc_enabled=true
else
pfring_zc_enabled=false
fi
SKIP=0
if [ -d "$install_dir/bro/bin" ]; then
print_error "It looks like bro may already be installed...do you want to install it again? (y/n): "
read answer
if [[ $answer == "y" ]]; then
print_status "Proceeding to re-install bro..."
else
SKIP=1
fi
else
print_status "Proceeding to install bro..."
fi
if [[ $SKIP == 0 ]]; then
# Prereqs
if [ -f /etc/centos-release ]; then
print_status "installing prereqs via yum..."
yum -y install cmake make gcc gcc-c++ flex bison openssl-devel python-devel swig zlib-devel file-devel geoip-devel sendmail libpcap-devel screen htop
fi
#decompress, cd to source
cd $wrk_dir
wget "https://www.bro.org/downloads/release/bro-2.4.1.tar.gz"
handle_error
tar xzf bro-2.4.1.tar.gz
handle_error
cd bro-2.4.1/
handle_error
#install bro
print_status "./configure --prefix=$install_dir/bro/ --with-pcap=/usr/local/pfring..."
export LDFLAGS="-Wl,--no-as-needed -lrt"
export LIBS="-lrt -lnuma"
./configure --prefix=$install_dir/bro/ --with-pcap=/usr/local/pfring
handle_error
print_status "make clean..."
make clean
handle_error
print_status "make...(bro takes a while to make)"
make
handle_error
print_status "make install..."
make install
handle_error
print_status "Building BRO config based on global vars..."
sed -i 's,interface=eth0,#interface=eth0,' $install_dir/bro/etc/node.cfg
echo -e "[manager]\ntype=manager\nhost=$manage_ip\n\n" >> $install_dir/bro/etc/node.cfg
handle_error
echo -e "[proxy-1]\ntype=proxy\nhost=$manage_ip\n\n" >> $install_dir/bro/etc/node.cfg
handle_error
echo -e "[worker-1]\ntype=worker\nhost=$manage_ip\ninterface=$sniff_int\nlb_method=pf_ring\nlb_procs=$num_bro_pf_proc" >> $install_dir/bro/etc/node.cfg
handle_error
sed -i 's/\[bro\]/#\[bro\]/' $install_dir/bro/etc/node.cfg
handle_error
sed -i 's/type=standalone/#type=standalone/' $install_dir/bro/etc/node.cfg
handle_error
sed -i 's/host=localhost/#host=localhost/' $install_dir/bro/etc/node.cfg
handle_error
print_status "Ok, here's the config file for bro..."
cat $install_dir/bro/etc/node.cfg
sleep 10
if [ $pfring_zc_enabled == "true" ]; then
print_status "Checking to make sure bro compiled with pfring properly..."
if [[ -z `ldd $install_dir/bro/bin/bro | grep pfring` ]]; then
print_error "It looks like bro didnt properly link libpcap...here look:"
ldd $install_dir/bro/bin/bro | grep libpcap
print_error "That should point to '/usr/local/pfring/lib/libpcap.so.1'"
print_error "You will need to make sure pfring installed properly and that bro is properly searching for the so."
exit 0
else
print_good "Looks good."
ldd $install_dir/bro/bin/bro | grep libpcap
fi
fi
print_status "cleanup..."
rm -rf $wrk_dir/bro-2.4.1
handle_error
$install_dir/bro/bin/broctl cron enable
handle_error
$install_dir/bro/bin/broctl install
handle_error
$install_dir/bro/bin/broctl check
handle_error
print_status "adding broctl cron..."
line_bro="0-59/5 * * * * $install_dir/bro/bin/broctl cron"
(crontab -l; echo "$line_bro" ) | crontab -
sed -i "s,/var/opt/bro/spool,${install_dir}/bro/spool," $install_dir/bro/etc/broctl.cfg
handle_error
sed -i "s,/var/opt/bro/logs,${install_dir}/bro/logs," $install_dir/bro/etc/broctl.cfg
handle_error
print_status "moving back to the working dir..."
cd $wrk_dir
handle_error
else
space_pls
print_good "Skipped BRO install..."
fi
space_pls
print_status "BRO install has completed."
space_pls
}
suricata()
{
print_status "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
print_status "!!!!! Installing Suricata !!!!!"
print_status "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
space_pls
sniff_driver=$(ethtool -i $sniff_int | grep driver | awk '{ print $2 }')
if [[ $sniff_driver == "igb" || $sniff_driver == "e1000e" || $sniff_driver == "ixgbe" ]]; then
pfring_zc_enabled=true
else
pfring_zc_enabled=false
fi
SKIP=0
if [ -d "$install_dir/suricata/bin" ]; then
print_error "It looks like suricata may already be installed...do you want to install it again? (y/n): "
read answer
if [[ $answer == "y" ]]; then
print_status "Proceeding to re-install suricata..."
print_status "Moving the suricata folder to old_suricata..."
mv $install_dir/suricata $install/old_suricata
print_status "Removing lua .so's so they can be rebuilt..."
rm -f /usr/lib64/lua/5.1/zip.so
rm -f /usr/lib64/lua/5.1/apr
rm -f /usr/lib64/lua/5.1/ltn12ce
rm -f /usr/lib64/lua/5.1/zlib.so
rm -f /usr/lib64/lua/5.1/struct.so
print_status "Removing decompressed lua thirdparty modules so they can be rebuilt..."
rm -f $wrk_dir/lua_stuff
else
SKIP=1
fi
else
print_status "Proceeding to install suricata..."
fi
if [[ $SKIP == 0 ]]; then
# Prereqs
if [ -f /etc/centos-release ]; then
yum -y install libpcap libpcap-devel libnet libnet-devel pcre pcre-devel gcc gcc-c++ automake autoconf screen htop libtool make libyaml libyaml-devel zlib zlib-devel file-devel wget git-core nss-util nss-util-devel nss-devel nspr-devel nspr GeoIP-devel GeoIP python-simplejson python-setuptools python-instant python-distutils-extra
fi
# Lua scripting support
if [ -f /etc/centos-release ]; then
yum install -y zip unzip luarocks cmake lua-devel apr-devel apr-util-devel libapreq2 libapreq2-devel zziplib zziplib-devel
fi
print_status "Decompressing Lua Thirdparty Modules"
mkdir $wrk_dir/lua_stuff
tar xzf $wrk_dir/lua_thirdparty.tar.gz -C $wrk_dir/lua_stuff
# PCRE
cd $wrk_dir/lua_stuff
handle_error
tar -xzvf pcre-8.35.tar.gz
handle_error
cd pcre-8.35
handle_error
./configure --prefix=/usr/local/pcre-8.35/ --enable-jit --enable-utf8 --enable-unicode-properties
handle_error
make -j
handle_error
make install
handle_error
cd ..
luarocks install struct
handle_error
luarocks install lua-apr
handle_error
luarocks install luazip
handle_error
# LUA ZLIB
mkdir lua-zlib
handle_error
cd lua-zlib
handle_error
unzip $wrk_dir/lua_stuff/lua-zlib.zip
handle_error
cmake lua-zlib
handle_error
make install
handle_error
cd ..
handle_error
# ltn12ce
unzip ltn12ce.zip
handle_error
cd ltn12ce
handle_error
mkdir build
handle_error
cd build
handle_error
cmake .. -DBUILD_ZLIB=Off
handle_error
make
handle_error
make install
handle_error
cd ..
handle_error
# LuaBitOp
cd $wrk_dir/lua_stuff
handle_error
tar xzf LuaBitOp-1.0.2.tar.gz
handle_error
cd LuaBitOp-1.0.2
handle_error
make
handle_error
make install
handle_error
# Links so lua can find things where it expects them
ln -s /usr/lib/lua/5.1/zip.so /usr/lib64/lua/5.1/zip.so
handle_error
ln -s /usr/lib/lua/5.1/apr /usr/lib64/lua/5.1/apr
handle_error
ln -s /usr/local/lib/lua/ltn12ce /usr/lib64/lua/5.1/ltn12ce
handle_error
ln -s /usr/local/share/lua/cmod/zlib.so /usr/lib64/lua/5.1/zlib.so
handle_error
ln -s /usr/lib/lua/5.1/struct.so /usr/lib64/lua/5.1/struct.so
handle_error
rm -rf $wrk_dir/lua_stuff
handle_error
# Uncompress Suri install files
cd $wrk_dir
wget "http://www.openinfosecfoundation.org/download/suricata-2.0.9.tar.gz"
handle_error
tar xzf suricata-2.0.9.tar.gz
handle_error
print_status "cd suricata-2.0.9/..."
cd suricata-2.0.9/
handle_error
print_status "Installing suri...wooo..."
print_status "big configure statement w/ pfring stuff..."
LIBS=-lrt ./configure --prefix=$install_dir/suricata/ --enable-pfring --enable-lua --with-libpfring-includes=/usr/local/pfring/include --with-libpfring-libraries=/usr/local/pfring/lib --with-libpcap-includes=/usr/local/pfring/include --with-libpcap-libraries=/usr/local/pfring/lib
handle_error
print_status "make clean..."
make clean
handle_error
print_status "make..."
make
handle_error
print_status "make install-full..."
make install-full
handle_error
print_status "ldconfig..."
ldconfig
handle_error
# Oinkmaster
print_status "Copy over oinkmaster for updating..."
tar xzf $wrk_dir/oinkmaster.tar.gz -C $install_dir
handle_error
# Configure etpro ruleset if set
if [ -z $etpro_license ]; then
print_status "Using Emerging Threats Community Ruleset"
else
print_status "sed -i 's/url = http:\/\/rules.emergingthreats.net\/open\/suricata\/emerging.rules.tar.gz/url = http:\/\/rules.emergingthreatspro.com\/$etpro_license\/suricata-1.3\/etpro.rules.tar.gz/' $install_dir/oinkmaster/oinkmaster.conf..."
sed -i "s,url = http://rules.emergingthreats.net/open/suricata/emerging.rules.tar.gz,url = http://rules.emergingthreatspro.com/$etpro_license/suricata-1.3/etpro.rules.tar.gz," $install_dir/oinkmaster/oinkmaster.conf
handle_error
fi
# Get Rules / Configure Cron
print_status "update ruleset with ET sigs..."
$install_dir/oinkmaster/oinkmaster.pl -C $install_dir/oinkmaster/oinkmaster.conf -o $install_dir/suricata/etc/suricata/rules/
handle_error
print_status "grab the et-luajit-rules..."
git clone https://github.com/EmergingThreats/et-luajit-scripts $install_dir/suricata/et-luajit-scripts
handle_error
cp $install_dir/suricata/et-luajit-scripts/* $install_dir/suricata/etc/suricata/rules/
handle_error
# Add Crontab that will update sigs and reload suri every 12 hours...
cat << EOF > $install_dir/suricata/ruleupdates.sh
#!/bin/sh
$install_dir/oinkmaster/oinkmaster.pl -C $install_dir/oinkmaster/oinkmaster.conf -o $install_dir/suricata/etc/suricata/rules/
cd $install_dir/suricata/et-luajit-scripts/
git pull
cp $install_dir/suricata/et-luajit-scripts/* $install_dir/suricata/etc/suricata/rules/
EOF
chmod +x $install_dir/suricata/ruleupdates.sh
print_status "add crontab to update sigs and reload suri every 12 hours..."