-
Notifications
You must be signed in to change notification settings - Fork 33
/
provision.sh
1481 lines (1304 loc) · 41.2 KB
/
provision.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
USER="vagrant"
PKGDIR=/vagrant/pkgs
HOME=/home/vagrant
PCAP_REPLAY=/srv/replay
# This script is meant to be run on vagrant box images, but let's compensate
[ -d "$HOME" ] || useradd -m -G sudo $USER && mkdir -p $PKGDIR && chown -R $USER: /vagrant
# Determine "Predictable Network Interface Names"
if [[ -n $(ip link show | grep eth0) ]]; then
# legacy naming
IFACE_EXT="eth0"
IFACE_INT="eth1"
IFACE_PATTERN="eth"
elif [[ -n $(ip link show | grep ens1) ]]; then
# vmware (older Ubuntu and Debian?)
IFACE_EXT="ens192"
IFACE_INT="ens192"
IFACE_PATTERN="ens"
elif [[ -n $(ip link show | grep enp11) ]]; then
# vmware (Ubuntu 22.04)
IFACE_EXT="enp11s0"
IFACE_INT="enp11s0"
IFACE_PATTERN="enp"
else
# vbox
IFACE_EXT="enp0s3"
IFACE_INT="enp0s8"
IFACE_PATTERN="enp"
fi
check_service(){
systemctl daemon-reload
systemctl is-enabled $1.service 2>/dev/null | grep "disabled" && systemctl enable $1.service
systemctl status $1.service | egrep "inactive|failed" && systemctl start $1.service
systemctl status $1.service
}
check_service_noverify(){
systemctl daemon-reload
systemctl is-enabled $1.service 2>/dev/null | grep "disabled" && systemctl enable $1.service
}
# params
DEBUG=true
EXPOSE=127.0.0.1
WGET_PARAMS="-4 -q"
GOPATH=$HOME/go/
GOROOT=$HOME/.local/go
PATH=$PATH:/opt/arkime/bin:$GOROOT/bin:$GOPATH/bin
grep PATH /etc/environment || echo "export PATH=$PATH" >> /etc/environment
echo "Installing prerequisite packages..."
apt-get update && apt-get -y install \
jq \
wget \
curl \
tmux \
unzip \
pcregrep \
python3-pip \
python3-yaml \
libpcre3-dev \
libyaml-dev \
uuid-dev \
libmagic-dev \
pkg-config \
g++ \
flex \
bison \
zlib1g-dev \
libffi-dev \
gettext \
libgeoip-dev \
make \
libjson-perl \
libbz2-dev \
libwww-perl \
libpng-dev \
xz-utils \
libffi-dev \
libsnappy-dev \
numactl \
pcregrep \
tcpreplay || exit 1
# versions
UBUNTU_VERSION="2204"
ELASTIC_VERSION="8.13.4"
INFLUX_VERSION="2.7.1"
GRAFANA_VERSION="9.5.3"
TELEGRAF_VERSION="1.26.3"
GOLANG_VERSION="1.22.3"
ARKIME_VERSION="5.1.2"
PIKKSILM_VERSION="0.7.0"
ELA="elasticsearch-oss-${ELASTIC_VERSION}-amd64.deb"
KIBANA="kibana-oss-${ELASTIC_VERSION}-amd64.deb"
INFLUX="influxdb_${INFLUX_VERSION}_amd64.deb"
GRAFANA="grafana_${GRAFANA_VERSION}_amd64.deb"
TELEGRAF="telegraf_${TELEGRAF_VERSION}-1_amd64.deb"
GOLANG="go${GOLANG_VERSION}.linux-amd64.tar.gz"
DOCKER_ELA="docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_VERSION}"
DOCKER_KIBANA="docker.elastic.co/kibana/kibana:${ELASTIC_VERSION}"
DOCKER_LOGSTASH="docker.elastic.co/logstash/logstash:${ELASTIC_VERSION}"
DOCKER_FILEBEAT="docker.elastic.co/beats/filebeat:${ELASTIC_VERSION}"
DOCKER_INFLUXDB="influxdb:${INFLUX_VERSION}-alpine"
DOCKER_GRAFANA="grafana/grafana:${GRAFANA_VERSION}"
ARKIME_FILE="arkime_${ARKIME_VERSION}-1_amd64.deb"
ARKIME_LINK="https://github.com/arkime/arkime/releases/download/v${ARKIME_VERSION}/arkime_${ARKIME_VERSION}-1.ubuntu${UBUNTU_VERSION}_amd64.deb"
ARKIME_JA4_LINK="https://github.com/arkime/arkime/releases/download/v${ARKIME_VERSION}/ja4plus.amd64.so"
GOPHER_URL=$(curl --silent "https://api.github.com/repos/StamusNetworks/gophercap/releases/latest" | jq -r '.assets[] | select(.name=="gopherCap.gz") | .browser_download_url')
PIKKSILM_URL=$(curl -ss -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/markuskont/pikksilm/releases | jq -r ".[] | select(.tag_name==\"v${PIKKSILM_VERSION}\") | .assets | .[] | select(.name==\"pikksilm_${PIKKSILM_VERSION}_linux_amd64.tar.gz\") | .browser_download_url")
ELASTSIC_MEM=512
LOGSTASH_MEM=512
mkdir -p $PKGDIR
if [ "$(id -u)" != "0" ]; then
echo "ERROR - This script must be run as root" 1>&2
exit 1
fi
start=$(date)
# basic OS config
FILE=/etc/sysctl.conf
grep "disable_ipv6" $FILE || cat >> $FILE <<EOF
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
EOF
grep "vm.max_map_count" $FILE || cat >> $FILE <<EOF
vm.max_map_count=262144
EOF
sysctl -p
echo $start > /vagrant/provision.log
echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4
export DEBIAN_FRONTEND=noninteractive
echo "Configuring DOCKER"
docker network ls | grep cdmcs >/dev/null || docker network create -d bridge cdmcs
echo "Provisioning REDIS"
docker ps -a | grep redis || docker run -dit \
--name redis \
-h redis \
--network cdmcs \
--restart unless-stopped \
-p 6379:6379 \
redis
# elastic
echo "Provisioning ELASTICSEARCH"
docker ps -a | grep elastic || docker run -dit \
--name elastic \
-h elastic \
--network cdmcs \
-e "ES_JAVA_OPTS=-Xms${ELASTSIC_MEM}m -Xmx${ELASTSIC_MEM}m" \
-e "discovery.type=single-node" \
-e "xpack.security.enabled=false" \
--restart unless-stopped \
-p 9200:9200 \
$DOCKER_ELA
sleep 25 # With pre-pulled docker images the next steps run before elastic has spun up.
# kibana
echo "Provisioning KIBANA"
docker ps -a | grep kibana || docker run -dit \
--name kibana \
-h kibana \
--network cdmcs \
-e "SERVER_NAME=kibana" \
-e "ELASTICSEARCH_HOSTS=http://elastic:9200" \
--restart unless-stopped \
-p 5601:5601 \
$DOCKER_KIBANA
echo "Provisioning ELASTIC TEMPLATES"
curl -s -XPUT localhost:9200/_template/default -H'Content-Type: application/json' -d '
{
"order" : 0,
"version" : 0,
"index_patterns" : "suricata-*",
"settings" : {
"index" : {
"refresh_interval" : "10s",
"number_of_shards" : 3,
"number_of_replicas" : 0
}
}, "mappings" : {
"dynamic_templates" : [ {
"message_field" : {
"path_match" : "message",
"match_mapping_type" : "string",
"mapping" : {
"type" : "text",
"norms" : false
}
}
}, {
"string_fields" : {
"match" : "*",
"match_mapping_type" : "string",
"mapping" : {
"type" : "text", "norms" : false,
"fields" : {
"keyword" : { "type": "keyword", "ignore_above": 256 }
}
}
}
} ],
"properties" : {
"@timestamp": { "type": "date"},
"@version": { "type": "keyword"},
"geoip" : {
"dynamic": true,
"properties" : {
"ip": { "type": "ip" },
"location" : { "type" : "geo_point" },
"latitude" : { "type" : "half_float" },
"longitude" : { "type" : "half_float" }
}
}
}
}
}
' || exit 1
curl -s -XPUT localhost:9200/_template/suricata -H 'Content-Type: application/json' -d '
{
"order": 10,
"version": 0,
"index_patterns": [
"suricata-*",
"logstash-*"
],
"mappings":{
"properties": {
"src_ip": {
"type": "ip",
"fields": {
"keyword" : { "type": "keyword", "ignore_above": 256 }
}
},
"dest_ip": {
"type": "ip",
"fields": {
"keyword" : { "type": "keyword", "ignore_above": 256 }
}
},
"payload": { "type": "binary" }
}
}
}
' || exit 1
docker ps -a | grep evebox | docker run -tid \
--network cdmcs \
--name evebox \
--restart unless-stopped \
-p 5636:5636 \
jasonish/evebox:master \
-e http://elastic:9200 \
--index suricata \
--host 0.0.0.0 \
echo "Provisioning RSYSLOG"
add-apt-repository -y ppa:adiscon/v8-stable
apt-get update
apt-get install rsyslog rsyslog-mmjsonparse rsyslog-elasticsearch -y
FILE=/etc/rsyslog.d/75-elastic.conf
grep "CDMCS" $FILE || cat >> $FILE <<'EOF'
# CDMCS
module(load="omelasticsearch")
module(load="mmjsonparse")
template(
name="with-logstash-timestamp-format"
type="list") {
constant(value="{\"@timestamp\":\"") property(name="timegenerated" dateFormat="rfc3339")
constant(value="\",") property(name="$!all-json" position.from="3")
}
template(name="JSON" type="list") {
property(name="$!all-json")
}
template(name="suricata-index" type="list") {
constant(value="suricata-")
property(name="timereported" dateFormat="rfc3339" position.from="1" position.to="4")
constant(value=".")
property(name="timereported" dateFormat="rfc3339" position.from="6" position.to="7")
constant(value=".")
property(name="timereported" dateFormat="rfc3339" position.from="9" position.to="10")
constant(value=".")
property(name="timereported" dateFormat="rfc3339" position.from="12" position.to="13")
}
if $syslogtag contains 'suricata' and $msg startswith ' @cee:' then {
action(type="mmjsonparse")
if $parsesuccess == "OK" then action(
type="omelasticsearch"
template="with-logstash-timestamp-format"
server="127.0.0.1"
serverport="9200"
searchIndex="suricata-index"
dynSearchIndex="on"
searchType="_doc"
)
}
EOF
systemctl stop rsyslog.service
rsyslogd -N 1 || exit 1
check_service rsyslogd
# logstash
echo "Provisioning LOGSTASH"
grep redis /etc/hosts || echo "127.0.0.1 redis" >> /etc/hosts
grep elastic /etc/hosts || echo "127.0.0.1 elastic" >> /etc/hosts
mkdir -p /etc/logstash/conf.d/
FILE=/etc/logstash/conf.d/suricata.conf
grep "CDMCS" $FILE || cat > $FILE <<EOF
input {
file {
path => "/var/log/suricata/eve.json"
tags => ["suricata", "CDMCS", "fromfile"]
}
redis {
data_type => "list"
host => "redis"
port => 6379
key => "suricata"
tags => ["suricata", "CDMCS", "fromredis"]
}
}
filter {
json { source => "message" }
if 'syslog' not in [tags] {
mutate { remove_field => [ "message", "Hostname" ] }
}
}
output {
elasticsearch {
hosts => ["elastic"]
index => "logstash-%{+YYYY.MM.dd.hh}"
manage_template => false
document_type => "_doc"
}
}
EOF
docker ps -a | grep logstash || docker run -dit \
--name logstash \
-h logstash \
--network cdmcs \
-v /etc/logstash/conf.d/:/usr/share/logstash/pipeline/ \
-e "ES_JAVA_OPTS=-Xms${LOGSTASH_MEM}m -Xmx${LOGSTASH_MEM}m" \
--restart unless-stopped \
$DOCKER_LOGSTASH
docker stop logstash
sleep 5
echo "Provisioning Filebeat"
FILE=/etc/filebeat.yml
grep "CDMCS" $FILE || cat > $FILE <<EOF
# CDMCS
filebeat.inputs:
- type: log
paths:
- "/var/log/suricata/eve.json"
json.keys_under_root: true
json.add_error_key: true
processors:
- timestamp:
field: timestamp
layouts:
- '2006-01-02T15:04:05Z'
- '2006-01-02T15:04:05.999Z'
test:
- '2019-06-22T16:33:51Z'
- '2019-11-18T04:59:51.123Z'
output.elasticsearch:
hosts: ["elastic:9200"]
index: "filebeat-%{+yyyy.MM.dd}"
bulk_max_size: 10000
logging.level: info
logging.to_files: true
logging.files:
path: /var/log/filebeat
name: filebeat
keepfiles: 7
permissions: 0644
setup.template:
name: 'filebeat'
pattern: 'filebeat-*'
enabled: false
setup.ilm.enabled: false
EOF
docker ps -a | grep filebeat || docker run -dit \
--name filebeat \
-h filebeat \
--network cdmcs \
-v /var/log/suricata:/var/log/suricata:ro \
-v /var/log/filebeat:/var/log/filebeat:rw \
-v /etc/filebeat.yml:/etc/filebeat.yml \
--restart unless-stopped \
$DOCKER_FILEBEAT run -c /etc/filebeat.yml
echo "Configuring interfaces"
FILE=/usr/sbin/replay_iface
[[ -f $FILE ]] || cat > $FILE <<EOF
#!/bin/sh
ip link add capture0 type veth peer name replay0
ip link set dev capture0 mtu 9000
ip link set dev replay0 mtu 9000
ip link set capture0 up
ip link set replay0 up
EOF
chmod 755 $FILE
FILE=/etc/systemd/system/virtIface.service
[[ -f $FILE ]] || cat > $FILE <<EOF
[Unit]
Description=capture interface
After=network.target
[Service]
User=root
Group=root
WorkingDirectory=/var/run/
ExecStart=/usr/sbin/replay_iface
Type=oneshot
[Install]
WantedBy=multi-user.target
EOF
check_service virtIface
delim=";"; ifaces=""; for item in `ls /sys/class/net/ | egrep '^eth|ens|eno|enp|capture|monitoring'`; do ifaces+="$item$delim"; done ; ifaces=${ifaces%"$deli$delim"}
for iface in ${ifaces//;/ }; do
echo "Setting capture params for $iface"
for i in rx tx tso gso gro tx nocache copy sg rxvlan; do ethtool -K $iface $i off > /dev/null 2>&1; done
done
echo "Provisioning SURICATA"
# suricata
install_suricata_from_ppa(){
add-apt-repository -y ppa:oisf/suricata-stable > /dev/null 2>&1 \
&& apt-get update > /dev/null \
&& apt-get install -y suricata > /dev/null
}
suricata -V || install_suricata_from_ppa
pip3 install --upgrade suricata-update
touch /etc/suricata/threshold.config
mkdir -p /var/lib/suricata/rules
[[ -f /var/lib/suricata/rules/scirius.rules ]] || touch /etc/suricata/rules/scirius.rules
[[ -f /var/lib/suricata/rules/suricata.rules ]] || touch /etc/suricata/rules/suricata.rules
FILE=/var/lib/suricata/rules/custom.rules
[[ -f $FILE ]] || cat > $FILE <<EOF
alert http \$HOME_NET any -> \$EXTERNAL_NET any (msg:"CDMCS: External Windows executable download"; flow:established,to_server; content:"GET "; uricontent:".exe"; nocase; classtype:policy-violation; sid:3000001; rev:1; metadata:created_at 2018_01_19, updated_at 2018_01_19;)
alert dns any any -> any any (msg:"CDMCS: DNS request for Facebook"; dns.query; content:"facebook"; classtype:policy-violation; sid:3000002; rev:1; metadata:created_at 2018_01_19, updated_at 2018_01_19;)
alert tls any any -> any any (msg:"CDMCS: Facebook certificate detected"; tls.sni; content: "facebook"; classtype:policy-violation; sid:3000003; rev:1; metadata:created_at 2018_01_19, updated_at 2018_01_19;)
EOF
FILE=/var/lib/suricata/rules/lua.rules
[[ -f $FILE ]] || cat > $FILE <<EOF
alert tls any any -> any any (msg:"CDMCS TLS Self Signed Certificate"; flow:established; luajit:self-signed-cert.lua; tls.store; classtype:protocol-command-decode; sid:3000051; rev:1;)
alert tls any any -> any any (msg:"Recent certificate"; lua:new-cert.lua; tls.store; sid:3000052; rev:1;)
EOF
FILE=/var/lib/suricata/rules/self-signed-cert.lua
[[ -f $FILE ]] || cat > $FILE <<EOF
function init (args)
local needs = {}
needs["tls"] = tostring(true)
return needs
end
function match(args)
version, subject, issuer, fingerprint = TlsGetCertInfo();
if subject == issuer then
return 1
else
return 0
end
end
EOF
FILE=/var/lib/suricata/rules/new-cert.lua
[[ -f $FILE ]] || cat > $FILE <<EOF
function init (args)
local needs = {}
needs["tls"] = tostring(true)
needs["flowint"] = {"cert-age"}
return needs
end
function match(args)
notbefore = TlsGetCertNotBefore()
if not notbefore then
return 0
end
if os.time() - notbefore < 3 * 3600 then
ScFlowintSet(0, os.time() - notbefore)
return 1
end
return 0
end
EOF
if $DEBUG ; then ip addr show; fi
systemctl stop suricata
pgrep Suricata || [[ -f /var/run/suricata.pid ]] && rm /var/run/suricata.pid
echo "Adding datasets for SURICATA"
FILE=/etc/suricata/cdmcs-datasets.yaml
grep "CDMCS" $FILE || cat >> $FILE <<EOF
%YAML 1.1
---
# CDMCS
datasets:
defaults:
memcap: 10mb
hashsize: 1024
ua-seen:
type: sha256
state: ua-sha256-seen.lst
dns-sha256-seen:
type: sha256
state: dns-sha256-seen.lst
memcap: 100mb
hashsize: 4096
EOF
FILE=/var/lib/suricata/rules/datasets.rules
[[ -f $FILE ]] || cat > $FILE <<EOF
alert http any any -> \$EXTERNAL_NET any (msg:"CDMCS: Collect unique user-agents"; http.user_agent; dataset:set,http-user-agents, type string, state http-user-agents.lst; bypass; sid:3000007; rev:1; metadata:created_at 2020_02_28, updated_at 2020_02_28;)
alert http any any -> any any (msg:"CDMCS: Listed UA seen"; http.user_agent; to_sha256; dataset:isset,ua-seen; classtype:policy-violation; sid:3000004; rev:1; metadata:created_at 2020_01_29, updated_at 2020_01_29;)
alert dns any any -> any any (msg:"CDMCS: Listed DNS hash seen"; dns.query; to_sha256; dataset:isset,dns-sha256-seen; classtype:policy-violation; sid:3000005; rev:1; metadata:created_at 2020_01_29, updated_at 2020_01_29;)
EOF
mkdir -p /var/lib/suricata/data
touch /var/lib/suricata/rules/http-user-agents.lst
echo "Adding detects for SURICATA"
FILE=/etc/suricata/cdmcs-detect.yaml
grep "CDMCS" $FILE || cat >> $FILE <<EOF
%YAML 1.1
---
# CDMCS
security:
# if true, prevents process creation from Suricata by calling
# setrlimit(RLIMIT_NPROC, 0)
limit-noproc: true
# Use landlock security module under Linux
landlock:
enabled: no
directories:
#write:
# - /var/run/
# /usr and /etc folders are added to read list to allow
# file magic to be used.
read:
- /usr/
- /etc/
- /etc/suricata/
lua:
# Allow Lua rules. Disabled by default.
allow-rules: true
af-packet:
- interface: ${IFACE_EXT}
cluster-id: 98
cluster-type: cluster_flow
defrag: yes
- interface: capture0
cluster-id: 97
cluster-type: cluster_flow
defrag: yes
default-rule-path: /var/lib/suricata/rules
rule-files:
- suricata.rules
- custom.rules
- lua.rules
- datasets.rules
sensor-name: CDMCS
EOF
echo "Adding outputs for SURICATA"
FILE=/etc/suricata/cdmcs-logging.yaml
grep "CDMCS" $FILE || cat >> $FILE <<EOF
%YAML 1.1
---
# CDMCS
outputs:
- fast:
enabled: no
filename: fast.log
append: yes
- tls-store:
enabled: yes
- eve-log:
enabled: 'yes'
filetype: regular
filename: alert.json
community-id: yes
community-id-seed: 0
types:
- alert:
payload: no
payload-buffer-size: 4kb
payload-printable: yes
packet: yes
http-body: no
http-body-printable: yes
metadata: yes
tagged-packets: no
- eve-log:
enabled: 'yes'
filetype: regular
filename: eve.json
redis:
server: 127.0.0.1
port: 6379
async: true
mode: list
pipelining:
enabled: yes
batch-size: 10
types:
- alert:
payload: yes
payload-buffer-size: 4kb
payload-printable: yes
packet: yes
http-body: yes
http-body-printable: yes
metadata: yes
tagged-packets: yes
- http:
extended: yes
- dns:
version: 2
- tls:
extended: yes
- files:
force-magic: no
- smtp:
extended: yes
- dnp3
- nfs
- smb
- tftp
- ike
- krb5
- dhcp:
enabled: yes
extended: yes
- ssh
- flow
- eve-log:
enabled: 'yes'
filetype: syslog
filename: eve.json
prefix: "@cee: "
identity: "suricata"
facility: local5
level: Info
redis:
server: 127.0.0.1
port: 6379
async: true
mode: list
pipelining:
enabled: yes
batch-size: 10
types:
- alert:
payload: yes
payload-buffer-size: 4kb
payload-printable: yes
packet: yes
http-body: yes
http-body-printable: yes
metadata: yes
tagged-packets: yes
- http:
extended: yes
- dns:
version: 2
- tls:
extended: yes
- files:
force-magic: no
- smtp:
extended: yes
- dnp3
- nfs
- smb
- tftp
- ike
- krb5
- dhcp:
enabled: yes
extended: yes
- ssh
- stats:
totals: yes
threads: yes
deltas: yes
- flow
- eve-log:
enabled: 'yes'
filetype: redis
filename: eve.json
redis:
server: 127.0.0.1
port: 6379
async: true
mode: list
pipelining:
enabled: yes
batch-size: 10
types:
- alert:
payload: no
payload-buffer-size: 4kb
payload-printable: yes
packet: yes
http-body: no
http-body-printable: yes
metadata: yes
tagged-packets: no
- http:
extended: yes
- dns:
version: 2
- tls:
extended: yes
- files:
force-magic: no
- smtp:
extended: yes
- dnp3
- nfs
- smb
- tftp
- ike
- krb5
- dhcp:
enabled: yes
extended: yes
- ssh
- flow
EOF
echo "Adding includes for SURICATA"
FILE=/etc/suricata/suricata.yaml
grep "cdmcs" $FILE || cat >> $FILE <<EOF
include:
- /etc/suricata/cdmcs-detect.yaml
- /etc/suricata/cdmcs-logging.yaml
- /etc/suricata/cdmcs-datasets.yaml
EOF
[[ -f /etc/init.d/suricata ]] && rm /etc/init.d/suricata
FILE=/etc/systemd/system/suricata.service
grep "suricata" $FILE || cat > $FILE <<EOF
[Unit]
Description=suricata daemon
After=network.target
[Service]
User=root
Group=root
WorkingDirectory=/var/run/
ExecStart=/usr/bin/suricata -c /etc/suricata/suricata.yaml --pidfile /var/run/suricata.pid --af-packet -D -vvv
Type=forking
[Install]
WantedBy=multi-user.target
EOF
check_service suricata || exit 1
echo "Updating rules"
suricata-update enable-source ptresearch/attackdetection
suricata-update enable-source sslbl/ssl-fp-blacklist
suricata-update enable-source oisf/trafficid
suricata-update enable-source tgreen/hunting
suricata-update list-enabled-sources
suricata-update
sleep 10
suricatasc -c "reload-rules"
suricatasc -c "dataset-add ua-seen sha256 53c5f12948a236c0a34e4cb17c51a337ef61524cb4363023f242115f11555d1f"
suricatasc -c "dataset-add http-content-delivery string $(echo -n download.windowsupdate.com | base64)"
suricatasc -c "dataset-add http-content-delivery string $(echo -n security.debian.com | base64)"
echo "Provisioning Pikksilm"
mkdir -p /var/lib/pikksilm
grep pikksilm /etc/passwd || useradd --system -d /var/lib/pikksilm pikksilm
chown pikksilm /var/lib/pikksilm
cd $PKGDIR
echo "Downloading pikksilm from ${PIKKSILM_URL}"
wget -O pikksilm.tar.gz $PIKKSILM_URL
tar -xzf pikksilm.tar.gz -C /usr/local/bin
which pikksilm || exit 1
pikksilm --config /etc/pikksilm.toml config
FILE=/etc/systemd/system/pikksilm.service
grep "pikksilm" $FILE || cat > $FILE <<EOF
[Unit]
Description=Pikksilm EDR to NDR correlator and enrichment
After=network.target
[Service]
Type=simple
Restart=on-failure
EnvironmentFile=-/etc/pikksilm.env
ExecStart=/usr/local/bin/pikksilm --config /etc/pikksilm.yaml run
WorkingDirectory=/
User=pikksilm
Group=daemon
[Install]
WantedBy=multi-user.target
EOF
check_service pikksilm
sleep 3
journalctl -u pikksilm.service --output cat -n 10
echo "Provision arkime from $ARKIME_LINK"
cd $PKGDIR
[[ -f $ARKIME_FILE ]] || wget -O $ARKIME_FILE $WGET_PARAMS $ARKIME_LINK
dpkg -s arkime || dpkg -i $ARKIME_FILE
apt-get -f -y install
echo "Configuring arkime"
cd /opt/arkime/etc
FILE=/opt/arkime/etc/config.ini
[[ -f config.ini ]] || cp config.ini.sample $FILE
sed -i "s/ARKIME_ELASTICSEARCH/http:\/\/localhost:9200/g" $FILE
sed -i "s/ARKIME_INTERFACE/$ifaces/g" $FILE
sed -i "s/ARKIME_INSTALL_DIR/\/opt\/arkime/g" $FILE
sed -i "s/ARKIME_INSTALL_DIR/\/opt\/arkime/g" $FILE
sed -i "s/ARKIME_PASSWORD/test123/g" $FILE
echo "configuring arkime rules"
RULE_FILE="/opt/arkime/etc/rules.conf"
grep "rules" $RULE_FILE || cat >> $RULE_FILE <<EOF
---
version: 1
rules:
- name: "Drop tls"
when: "fieldSet"
fields:
protocols:
- tls
ops:
_maxPacketsToSave: 12
- name: "Set custom protocol on certain hosts"
when: "fieldSet"
fields:
protocols:
- http
- tls
host.http:
- testmyids.com
- self-signed.badssl.com
ops:
"tags": "IDStest"
- name: "Set custom protocol when observing programming language package downloads"
when: "fieldSet"
fields:
protocols:
- tls
host.http:
- go.googlesource.com
- files.pythonhosted.org
ops:
"protocols": "pkg-management"
EOF
echo "Downloading Arkime JA4 support"
cd /opt/arkime/plugins
wget $ARKIME_JA4_LINK
cd -
echo "Configuring capture plugins"
sed -i -e 's,#wiseHost=127.0.0.1,wiseHost=127.0.0.1\nwiseCacheSecs=60\nplugins=ja4plus.amd64.so;wise.so;suricata.so\nsuricataAlertFile=/var/log/suricata/alert.json\nviewerPlugins=wise.js\nwiseTcpTupleLookups=true\nwiseUdpTupleLookups=true\n,g' $FILE
sed -i "/\[default\]/arulesFiles=$RULE_FILE" $FILE
sed -i "/\[default\]/asnapLen=65536" $FILE
echo "Configuring custom stuff"
grep "custom-fields" $FILE || cat >> $FILE <<EOF
[override-ips]
192.168.56.0/24=tag:private-net;country:PRIVATE;asn:AS0000 This is neat
10.0.2.0/24=tag:private-net;country:VIRTUALBOX;asn:AS0000 This is neat
EOF
grep "custom-fields" $FILE || cat >> $FILE <<EOF
[custom-fields]
cdmcs.name=kind:lotermfield;count:true;friendly:Name;db:cdmcs.name;help:Traffic owner
cdmcs.type=kind:lotermfield;count:true;friendly:Type;db:cdmcs.type;help:Traffic type
EOF
grep "custom-views" $FILE || cat >> $FILE <<EOF
[custom-views]
cdmcs=title:Cyber Defence Monitoring Course;require:cdmcs;fields:cdmcs.name,cdmcs.type
sysmon=title:Sysmon correlation;require:sysmon;fields:sysmon.parentprocessname,sysmon.parentprocesspid,sysmon.processname,sysmon.processpid,sysmon.username,sysmon.hostname,sysmon.hostip,sysmon.hostmac
EOF
grep "wise-types" $FILE || cat >> $FILE <<EOF
[wise-types]
communityid=communityId
EOF
echo "Adding custom node sections"
grep "polar" $FILE || cat >> $FILE <<EOF
[polar]
pcapReadMethod=pcap-over-ip-server
viewPort=8006
simpleCompression=none
EOF
echo "Configuring wise"
TAGGER_FILE="/opt/arkime/etc/tagger.txt"
[[ -f $TAGGER_FILE ]] || cat > $TAGGER_FILE <<EOF
#field:cdmcs.name;shortcut:0
#field:cdmcs.type;shortcut:1
192.168.56.11;0=local
10.0.2.15;0=local
8.8.8.8;0=google;1=dns
8.8.4.4;0=google;1=dns
1.1.1.1;0=cloudflare;1=dns
66.6.32.31;0=tumblr;1=web
66.6.33.31;0=tumblr;1=web
66.6.33.159;0=tumblr;1=web
EOF
for addr in $(dig A sysadminnid.tumblr.com | grep IN | grep -v \; | pcregrep -o1 'tumblr\.com\.\s+\d+\s+\w+\s+A\s+(\S+)'); do
docker exec redis redis-cli set $addr "$addr;cdmcs.name=tumblr;cdmcs.type=web"
done
cp wise.ini.sample wiseService.ini
grep CDMCS wiseService.ini || cat >> wiseService.ini <<EOF
# CDMCS
[reversedns]
ips=10.0.0.0/8
field=asset
[cache]
type=redis
url=redis://127.0.0.1:6379/1
redisURL=redis://127.0.0.1:6379/1
[file:ip]
file=${TAGGER_FILE}
tags=ipwise
type=ip
format=tagger
[redis:ip]
url=redis://127.0.0.1:6379/0
redisURL=redis://127.0.0.1:6379/0
tags=redis
type=ip
format=tagger