-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathprovision.sh
More file actions
1881 lines (1678 loc) · 61 KB
/
Copy pathprovision.sh
File metadata and controls
1881 lines (1678 loc) · 61 KB
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
# Run non-interactively (no TTY): disable the systemd pager so that `systemctl status`
# and journalctl never spawn `less`, which blocks forever waiting for input when stdin
# is not a terminal (and isn't /dev/null). Without this the script hangs at
# `check_service`'s `systemctl status` under any non-interactive provisioner.
export SYSTEMD_PAGER=cat
export PAGER=cat
# -----------------------------------------------------------------------------
# CDMCS all-in-one "singlehost" provisioner: Arkime + Elasticsearch/Kibana/
# Logstash/Filebeat (ELK) + Suricata + evebox + valkey + Pikksilm (EDR->NDR
# correlation) + PolarProxy + Cont3xt + Parliament + JupyterLab, all on one box.
#
# Usage: provision.sh [USER] [--no-password]
# USER login/stack user to create + use (default: vagrant). The Arkime
# viewer login, JupyterLab token and shell login all use USER.
# --no-password do NOT (re)set USER's password to its username -- preserves an
# existing/managed password (e.g. set by Ansible/Vault) on a re-run.
# A freshly-created user still gets one, to avoid lockout.
# Aliases: --keep-password ; or export SET_PASSWORD=no
#
# Env overrides:
# WORKDIR=<dir> download/cache/log dir (default: /vagrant if present, else
# /opt/cdmcs). The run summary is tee'd to $WORKDIR/provision-summary.txt
# REPO_RAW=<url> base URL to fetch data files (Kibana dashboards) from when not local
# SET_PASSWORD=no same as --no-password
#
# Updating versions: edit the SOFTWARE VERSIONS block below, then bump PROVISION_REV.
# Keep the ELK/evebox/valkey tags in sync with the base template's
# course_docker_images (ansible group_vars) so clones reuse pre-pulled images.
# For the Pikksilm -> Arkime WISE enrichment + its gotchas see
# ../Arkime/pikksilm/README.md.
#
# NB: re-running over an ALREADY-provisioned box does NOT upgrade existing docker
# containers (the `docker ps -a | grep X ||` guards skip them). To pick up new
# versions, `docker rm -f` the old containers first, or provision a fresh box.
# -----------------------------------------------------------------------------
# Script revision = number of git commits that have touched this file
# (singlehost/provision.sh). Bump by 1 each time you commit a change here.
PROVISION_REV=67
echo "=== CDMCS singlehost provision.sh — revision ${PROVISION_REV} ==="
# ============================================================================
# SOFTWARE VERSIONS — update these when refreshing the stack (then bump PROVISION_REV).
# All human-editable version numbers live here so they're easy to find/update. The
# derived download URLs + docker image tags are built from these further down (the
# gophercap/pikksilm asset URLs use jq+curl, so they're resolved after the apt install).
# NB: ELK + evebox + valkey should also match the base template's `course_docker_images`
# (ansible group_vars) so clones reuse pre-pulled images instead of re-downloading.
# ============================================================================
UBUNTU_VERSION="2404" # Ubuntu release number (2404 = 24.04 noble)
ELASTIC_VERSION="9.4.2" # ELK images: elasticsearch / kibana / logstash / filebeat
ARKIME_VERSION="6.5.0" # Arkime .deb (github release)
PIKKSILM_VERSION="2.0.3" # Pikksilm prebuilt binary (github release)
VALKEY_VERSION="8.1" # redis-compatible store (valkey/valkey docker tag)
EVEBOX_TAG="latest" # jasonish/evebox docker tag
ELASTSIC_MEM=512 # Elasticsearch JVM heap (MB)
LOGSTASH_MEM=512 # Logstash JVM heap (MB)
# ============================================================================
USER="${1:-vagrant}" # login user: pass as $1 (e.g. ./provision.sh student25); defaults to vagrant
# Whether to (re)set $USER's password to its username. Default yes (back-compat: a fresh box
# needs a known login). Skip it on a re-run so an existing/managed password (e.g. set by
# Ansible from Vault) is NOT clobbered: pass --no-password (or export SET_PASSWORD=no).
# A *freshly created* user always gets a password regardless, else the account stays locked.
SET_PASSWORD="${SET_PASSWORD:-yes}"
for _arg in "$@"; do
case "$_arg" in
--no-password|--keep-password) SET_PASSWORD="no" ;;
--set-password) SET_PASSWORD="yes" ;;
esac
done
# Working/cache dir for downloads, logs and the dashboards file. On a vagrant box default to
# the synced /vagrant folder; on bare metal use a local dir. Override with WORKDIR=... Data
# files not present locally are fetched from REPO_RAW (so the script also works fetched alone).
WORKDIR="${WORKDIR:-$([ -d /vagrant ] && echo /vagrant || echo /opt/cdmcs)}"
REPO_RAW="${REPO_RAW:-https://raw.githubusercontent.com/ccdcoe/CDMCS/master}"
PKGDIR=$WORKDIR/pkgs
HOME=/home/$USER
PCAP_REPLAY=/srv/replay
# This script is meant to be run on vagrant box images, but let's compensate
# Ensure the login user exists with a known password = its username. On a vagrant box the
# 'vagrant' user already exists; on a bare-metal/non-vagrant run useradd would otherwise
# leave the new account LOCKED (no password set) -- so set it explicitly here.
if id "$USER" >/dev/null 2>&1; then _user_existed=yes; else useradd -m -s /bin/bash -G sudo "$USER"; _user_existed=no; fi
if [ "$SET_PASSWORD" = "yes" ] || [ "$_user_existed" = "no" ]; then
echo "$USER:$USER" | chpasswd
if [ "$SET_PASSWORD" != "yes" ]; then
echo "NB: '$USER' was just created -> set password (= username) anyway, else the account stays locked."
fi
else
echo "Keeping existing password for '$USER' (--no-password / SET_PASSWORD=no)."
fi
mkdir -p $PKGDIR && chown -R $USER: $WORKDIR
# Determine the primary (management) network interface name.
# Prefer the interface that owns the default route -- this works on any machine
# regardless of NIC naming. The legacy name-pattern fallbacks below only kick in if
# there is no default route; relying on them alone can guess wrong (e.g. enp0s3) and
# Suricata/Arkime would then bind a non-existent interface and fail.
IFACE_EXT=$(ip -o route show default 2>/dev/null | awk '{for(i=1;i<=NF;i++) if($i=="dev"){print $(i+1); exit}}')
if [[ -n "$IFACE_EXT" ]]; then
IFACE_INT="$IFACE_EXT"
IFACE_PATTERN="$IFACE_EXT"
elif [[ -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
# Clear any systemd start-limit ("start request repeated too quickly"): a package
# (e.g. suricata) often auto-starts on its default config before we write the CDMCS
# config, crash-loops, and exhausts the burst limit -- which would then make our
# own 'systemctl start' below fail. reset-failed wipes that counter first.
systemctl reset-failed $1.service 2>/dev/null
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
# Download URLs + docker image tags derived from the SOFTWARE VERSIONS block at the top.
# (influxdb/grafana/telegraf/golang and the ELK -oss .debs were dropped in the 2026 cleanup;
# ELK runs from the docker images below and Pikksilm ships a prebuilt binary.)
# The two URLs below use curl+jq, so they're resolved here, after the apt install above.
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}"
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")
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 > $WORKDIR/provision.log
echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4
export DEBIAN_FRONTEND=noninteractive
echo "Configuring DOCKER"
# Install Docker Engine from Docker's OFFICIAL apt repo if it isn't already present.
# Skip entirely when docker is already installed (e.g. baked into the base template).
# We use download.docker.com (current docker-ce + compose plugin), not Ubuntu's docker.io.
if command -v docker >/dev/null 2>&1; then
echo "Docker already installed ($(docker --version)) - skipping install"
else
echo "Docker not found - installing docker-ce from download.docker.com"
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" \
> /etc/apt/sources.list.d/docker.list
apt-get update
apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin || exit 1
systemctl enable --now docker
fi
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 \
valkey/valkey:${VALKEY_VERSION}
# 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:${EVEBOX_TAG} \
-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
# 2026/noble: the adiscon rsyslog package now bundles mmjsonparse.so, so installing
# the separate rsyslog-mmjsonparse conflicts (dpkg overwrite error -> breaks apt ->
# cascades into the suricata install). Drop it; module(load="mmjsonparse") still works.
apt-get install rsyslog 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 "LS_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: filestream
id: suricata-eve
paths:
- "/var/log/suricata/eve.json"
parsers:
- ndjson:
keys_under_root: true
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
# filebeat runs as a non-root user inside the container and must be able to write its own log here
mkdir -p /var/log/filebeat && chmod 777 /var/log/filebeat
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
# Interfaces we capture on: the live wire (reliably found via the default route, see
# IFACE_EXT above) plus the replay veth (capture0, created by virtIface just above).
# Used by the capture-param tuning loop below. NB Arkime's default node sniffs only the
# live wire; capture0 is handled by the dedicated 'replay' node (see config.ini below).
ifaces="$IFACE_EXT;capture0"
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 --break-system-packages --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; lua: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
-- Suricata 8 lua detect API: suricata.tls module; no needs["tls"] (hook comes from the
-- 'alert tls ... lua:' rule). Replaces the removed global TlsGetCertInfo().
local tls = require("suricata.tls")
function init (args)
return {}
end
function match(args)
local version, subject, issuer, fingerprint = tls.get_server_cert_info()
if subject ~= nil and subject == issuer then
return 1
else
return 0
end
end
EOF
FILE=/var/lib/suricata/rules/new-cert.lua
[[ -f $FILE ]] || cat > $FILE <<EOF
-- Suricata 8 lua detect API: suricata.tls module. Replaces TlsGetCertNotBefore().
-- (the old flowint "cert-age" side-effect is dropped; nothing referenced that var.)
local tls = require("suricata.tls")
function init (args)
return {}
end
function match(args)
local notbefore = tls.get_server_cert_not_before()
if not notbefore then
return 0
end
if os.time() - notbefore < 3 * 3600 then
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
# community-id is the join key Pikksilm/Arkime-WISE use to line a flow up with the
# endpoint's Sysmon network event. Seed 0 so it matches Arkime + Winlogbeat (all seed 0).
community-id: yes
community-id-seed: 0
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's own `config` subcommand emits a default with EVERY output disabled, so the
# service logs "winlog: no result handlers" and exits. Write the config directly instead
# (same heredoc style as the other configs) with the redis result handlers enabled:
# correlations -> redis db1 (read by Arkime WISE) and enriched suricata -> redis db1.
# This replicates the pre-2.x flow (Sysmon EventID 1+3 correlation keyed by Community ID).
FILE=/etc/pikksilm.yaml
grep "CDMCS" $FILE 2>/dev/null || cat > $FILE <<'EOF'
# CDMCS
input:
suricata:
redis:
db: 0
host: localhost:6379
key: suricata
password: ""
sysmon:
redis:
db: 0
host: localhost:6379
key: winlogbeat
password: ""
log:
debug: false
interval: 30s
output:
correlations:
file:
enabled: false
path: ""
redis:
db: 1
enabled: true
host: localhost:6379
password: ""
suricata:
file:
enabled: false
path: ""
redis:
db: 1
enabled: true
host: localhost:6379
key: suricata
password: ""
persist:
file:
enabled: false
path: ""
process:
suricata:
buffer: 10000