-
Notifications
You must be signed in to change notification settings - Fork 1
/
INSTALL.sh
1325 lines (1169 loc) · 61.1 KB
/
INSTALL.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
# Color codes
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
RED='\033[0;31m'
VIOLET='\033[0;35m'
NC='\033[0m' # No Color
setVars(){
WWW_USER="www-data"
SUDO_WWW="sudo -H -u ${WWW_USER} "
PATH_TO_MISP="/var/www/MISP"
CAKE="${PATH_TO_MISP}/app/Console/cake"
MISP_BASEURL="${MISP_BASEURL:-""}"
LXC_MISP="lxc exec ${MISP_CONTAINER}"
REDIS_CONTAINER_PORT="6380"
INNODB_BUFFER_POOL_SIZE="2147483648"
INNODB_CHANGE_BUFFERING="none"
INNODB_IO_CAPACITY="1000"
INNODB_IO_CAPACITY_MAX="2000"
INNODB_LOG_FILE_SIZE="629145600"
INNODB_LOG_FILES_IN_GROUP="2"
INNODB_READ_IO_THREADS="16"
INNODB_STATS_PERISTENT="ON"
INNODB_WRITE_IO_THREADS="4"
}
setDefaultArgs(){
default_confirm="no"
default_prod="no"
default_misp_project=$(generateName "misp-project")
default_misp_img=""
default_misp_name=$(generateName "misp")
default_mysql_img=""
default_mysql_name=$(generateName "mysql")
default_mysql_user="misp"
default_mysql_pwd="misp"
default_mysql_db="misp"
default_mysql_root_pwd="misp"
default_redis_img=""
default_redis_name=$(generateName "redis")
default_modules="yes"
default_modules_img=""
default_modules_name=$(generateName "modules")
default_app_partition=""
default_db_partition=""
}
getPHPVersion(){
${LXC_MISP} -- bash -c "php -v | head -n 1 | awk '{print \$2}' | cut -d '.' -f 1,2"
}
info () {
local step=$1
local msg=$2
echo -e "${BLUE}Step $step:${NC} ${GREEN}$msg${NC}" > /dev/tty
}
error() {
local msg=$1
echo -e "${RED}Error: $msg${NC}" > /dev/tty
}
warn() {
local msg=$1
echo -e "${YELLOW}Warning: $msg${NC}" > /dev/tty
}
coreCAKE () {
# IF you have logged in prior to running this, it will fail but the fail is NON-blocking
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} userInit -q
# This makes sure all Database upgrades are done, without logging in.
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin runUpdates
# The default install is Python >=3.6 in a virtualenv, setting accordingly
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.python_bin" "${PATH_TO_MISP}/venv/bin/python"
# Tune global time outs
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Session.autoRegenerate" 0
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Session.timeout" 600
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Session.cookieTimeout" 3600
# Set the default temp dir
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.tmpdir" "${PATH_TO_MISP}/app/tmp"
# Change base url, either with this CLI command or in the UI
[[ ! -z ${MISP_BASEURL} ]] && ${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Baseurl $MISP_BASEURL
[[ ! -z ${MISP_BASEURL} ]] && ${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.external_baseurl" ${MISP_BASEURL}
# Enable GnuPG
echo $GPG_EMAIL_ADDRESSS
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "GnuPG.email" "${GPG_EMAIL_ADDRESS}" # Error
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "GnuPG.homedir" "${PATH_TO_MISP}/.gnupg"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "GnuPG.password" "${GPG_PASSPHRASE}"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "GnuPG.obscure_subject" true
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "GnuPG.key_fetching_disabled" false
# FIXME: what if we have not gpg binary but a gpg2 one?
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "GnuPG.binary" "$(which gpg)"
# LinOTP
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "LinOTPAuth.enabled" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "LinOTPAuth.baseUrl" "https://<your-linotp-baseUrl>"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "LinOTPAuth.realm" "lino"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "LinOTPAuth.verifyssl" true
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "LinOTPAuth.mixedauth" false
# Enable installer org and tune some configurables
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.host_org_id" 1
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.email" "[email protected]"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.disable_emailing" true --force
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.contact" "[email protected]"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.disablerestalert" true
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.showCorrelationsOnIndex" true
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.default_event_tag_collection" 0
# Provisional Cortex tunes
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Cortex_services_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Cortex_services_url" "http://127.0.0.1"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Cortex_services_port" 9000
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Cortex_timeout" 120
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Cortex_authkey" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Cortex_ssl_verify_peer" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Cortex_ssl_verify_host" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Cortex_ssl_allow_self_signed" true
# Provisional Action tunes
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Action_services_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Action_services_url" "http://127.0.0.1"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Action_services_port" 6666
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Action_timeout" 10
# Various plugin sightings settings
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Sightings_policy" 0
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Sightings_anonymise" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Sightings_anonymise_as" 1
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Sightings_range" 365
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Sightings_sighting_db_enable" false
# TODO: Fix the below list
# Set API_Required modules to false
PLUGS=(Plugin.ElasticSearch_logging_enable
Plugin.S3_enable)
for PLUG in "${PLUGS[@]}"; do
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting ${PLUG} false 2> /dev/null
done
# Plugin CustomAuth tuneable
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.CustomAuth_disable_logout" false
# RPZ Plugin settings
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.RPZ_policy" "DROP"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.RPZ_walled_garden" "127.0.0.1"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.RPZ_serial" "\$date00"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.RPZ_refresh" "2h"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.RPZ_retry" "30m"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.RPZ_expiry" "30d"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.RPZ_minimum_ttl" "1h"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.RPZ_ttl" "1w"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.RPZ_ns" "localhost."
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.RPZ_ns_alt" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.RPZ_email" "root.localhost"
# Kafka settings
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_brokers" "kafka:9092"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_rdkafka_config" "/etc/rdkafka.ini"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_include_attachments" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_event_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_event_notifications_topic" "misp_event"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_event_publish_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_event_publish_notifications_topic" "misp_event_publish"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_object_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_object_notifications_topic" "misp_object"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_object_reference_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_object_reference_notifications_topic" "misp_object_reference"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_attribute_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_attribute_notifications_topic" "misp_attribute"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_shadow_attribute_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_shadow_attribute_notifications_topic" "misp_shadow_attribute"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_tag_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_tag_notifications_topic" "misp_tag"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_sighting_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_sighting_notifications_topic" "misp_sighting"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_user_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_user_notifications_topic" "misp_user"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_organisation_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_organisation_notifications_topic" "misp_organisation"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_audit_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Kafka_audit_notifications_topic" "misp_audit"
# ZeroMQ settings
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.ZeroMQ_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.ZeroMQ_host" "127.0.0.1"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.ZeroMQ_port" 50000
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.ZeroMQ_redis_host" "$REDIS_CONTAINER.lxd"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.ZeroMQ_redis_port" $REDIS_CONTAINER_PORT
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.ZeroMQ_redis_database" 1
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.ZeroMQ_redis_namespace" "mispq"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.ZeroMQ_event_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.ZeroMQ_object_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.ZeroMQ_object_reference_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.ZeroMQ_attribute_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.ZeroMQ_sighting_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.ZeroMQ_user_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.ZeroMQ_organisation_notifications_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.ZeroMQ_include_attachments" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.ZeroMQ_tag_notifications_enable" false
# Force defaults to make MISP Server Settings less RED
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.language" "eng"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.proposals_block_attributes" false
# Redis block
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.redis_host" "$REDIS_CONTAINER.lxd"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.redis_port" $REDIS_CONTAINER_PORT
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.redis_database" 13
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.redis_password" ""
# Force defaults to make MISP Server Settings less YELLOW
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.ssdeep_correlation_threshold" 40
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.extended_alert_subject" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.default_event_threat_level" 4
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.newUserText" "Dear new MISP user,\\n\\nWe would hereby like to welcome you to the \$org MISP community.\\n\\n Use the credentials below to log into MISP at \$misp, where you will be prompted to manually change your password to something of your own choice.\\n\\nUsername: \$username\\nPassword: \$password\\n\\nIf you have any questions, don't hesitate to contact us at: \$contact.\\n\\nBest regards,\\nYour \$org MISP support team"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.passwordResetText" "Dear MISP user,\\n\\nA password reset has been triggered for your account. Use the below provided temporary password to log into MISP at \$misp, where you will be prompted to manually change your password to something of your own choice.\\n\\nUsername: \$username\\nYour temporary password: \$password\\n\\nIf you have any questions, don't hesitate to contact us at: \$contact.\\n\\nBest regards,\\nYour \$org MISP support team"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.enableEventBlocklisting" true
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.enableOrgBlocklisting" true
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.log_client_ip" true
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.log_auth" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.log_user_ips" true
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.log_user_ips_authkeys" true
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.disableUserSelfManagement" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.disable_user_login_change" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.disable_user_password_change" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.disable_user_add" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.block_event_alert" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.block_event_alert_tag" "no-alerts=\"true\""
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.block_old_event_alert" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.block_old_event_alert_age" ""
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.block_old_event_alert_by_date" ""
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.event_alert_republish_ban" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.event_alert_republish_ban_threshold" 5
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.event_alert_republish_ban_refresh_on_retry" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.incoming_tags_disabled_by_default" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.maintenance_message" "Great things are happening! MISP is undergoing maintenance, but will return shortly. You can contact the administration at \$email."
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.footermidleft" "This is an initial install"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.footermidright" "Please configure and harden accordingly"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.welcome_text_top" "Initial Install, please configure"
# TODO: Make sure $FLAVOUR is correct
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.welcome_text_bottom" "Welcome to MISP on ${FLAVOUR}, change this message in MISP Settings"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.attachments_dir" "${PATH_TO_MISP}/app/files"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.download_attachments_on_load" true
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.event_alert_metadata_only" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.title_text" "MISP"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.terms_download" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.showorgalternate" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "MISP.event_view_filter_fields" "id, uuid, value, comment, type, category, Tag.name"
# Force defaults to make MISP Server Settings less GREEN
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "debug" 0
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Security.auth_enforced" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Security.log_each_individual_auth_fail" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Security.rest_client_baseurl" ""
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Security.advanced_authkeys" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Security.password_policy_length" 12
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Security.password_policy_complexity" '/^((?=.*\d)|(?=.*\W+))(?![\n])(?=.*[A-Z])(?=.*[a-z]).*$|.{16,}/'
# Appease the security audit, #hardening
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Security.disable_browser_cache" true
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Security.check_sec_fetch_site_header" true
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Security.csp_enforce" true
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Security.advanced_authkeys" true
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Security.do_not_log_authkeys" true
# Appease the security audit, #loggin
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Security.username_in_response_header" true
}
updateGOWNT () {
# Update the galaxies…
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin updateGalaxies
# Updating the taxonomies…
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin updateTaxonomies
# Updating the warning lists…
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin updateWarningLists
# Updating the notice lists…
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin updateNoticeLists
# Updating the object templates…
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin updateObjectTemplates "1337"
}
setupGnuPG() {
GPG_REAL_NAME="Autogenerated Key"
GPG_COMMENT="WARNING: MISP AutoGenerated Key consider this Key VOID!"
GPG_EMAIL_ADDRESS="[email protected]"
GPG_KEY_LENGTH="3072"
GPG_PASSPHRASE="$(openssl rand -hex 32)"
# Check if the .gnupg directory exists on the LXD container
${LXC_MISP} -- sudo -u www-data -H sh -c "[ -d $PATH_TO_MISP/.gnupg ]" && {
echo "Existing key found on the container. Deleting..."
${LXC_MISP} -- sudo -u www-data -H sh -c "rm -rf $PATH_TO_MISP/.gnupg"
echo "Existing key deleted"
}
${LXC_MISP} -- sudo -u www-data -H sh -c "echo \"%echo Generating a default key
Key-Type: default
Key-Length: $GPG_KEY_LENGTH
Subkey-Type: default
Name-Real: $GPG_REAL_NAME
Name-Comment: $GPG_COMMENT
Name-Email: $GPG_EMAIL_ADDRESS
Expire-Date: 0
Passphrase: $GPG_PASSPHRASE
# Do a commit here, so that we can later print \"done\"
%commit
%echo done\" > /tmp/gen-key-script"
${LXC_MISP} -- sudo -u www-data -H sh -c "gpg --homedir $PATH_TO_MISP/.gnupg --batch --gen-key /tmp/gen-key-script"
# Export the public key to the webroot
${LXC_MISP} -- sudo -u www-data -H sh -c "gpg --homedir $PATH_TO_MISP/.gnupg --export --armor $GPG_EMAIL_ADDRESS | tee $PATH_TO_MISP/app/webroot/gpg.asc"
${LXC_MISP} -- rm /tmp/gen-key-script
}
checkRessourceExist() {
local resource_type="$1"
local resource_name="$2"
case "$resource_type" in
"container")
lxc info "$resource_name" &>/dev/null
;;
"image")
lxc image list --format=json | jq -e --arg alias "$resource_name" '.[] | select(.aliases[].name == $alias) | .fingerprint' &>/dev/null
;;
"project")
lxc project list --format=json | jq -e --arg name "$resource_name" '.[] | select(.name == $name) | .name' &>/dev/null
;;
"storage")
lxc storage list --format=json | jq -e --arg name "$resource_name" '.[] | select(.name == $name) | .name' &>/dev/null
;;
"network")
lxc network list --format=json | jq -e --arg name "$resource_name" '.[] | select(.name == $name) | .name' &>/dev/null
;;
"profile")
lxc profile list --format=json | jq -e --arg name "$resource_name" '.[] | select(.name == $name) | .name' &>/dev/null
;;
esac
return $?
}
waitForContainer() {
local container_name="$1"
while true; do
status=$(lxc list --format=json | jq -e --arg name "$container_name" '.[] | select(.name == $name) | .status')
if [ $status = "\"Running\"" ]; then
echo -e "${BLUE}$container_name ${GREEN}is running.${NC}"
break
fi
echo "Waiting for $container_name container to start."
sleep 5
done
}
generateName(){
local name="$1"
echo "${name}-$(date +%Y-%m-%d-%H-%M-%S)"
}
checkSoftwareDependencies() {
local dependencies=("jq")
for dep in "${dependencies[@]}"; do
if ! command -v "$dep" &> /dev/null; then
echo -e "${RED}Error: $dep is not installed.${NC}"
exit 1
fi
done
}
checkNamingConvention(){
local input="$1"
local pattern="^[a-zA-Z0-9-]+$"
if ! [[ "$input" =~ $pattern ]]; then
error "Invalid Name $input. Please use only alphanumeric characters and hyphens."
# exit 1
return 1
fi
return 0
}
interactiveConfig(){
# Installer output
echo
echo "################################################################################"
echo -e "# Welcome to the ${BLUE}MISP-airgap${NC} Installer Script #"
echo "#------------------------------------------------------------------------------#"
echo -e "# This installer script will guide you through the installation process of #"
echo -e "# ${BLUE}MISP${NC} using LXD. #"
echo -e "# #"
echo -e "# ${VIOLET}Please note:${NC} #"
echo -e "# ${VIOLET}Default values provided below are for demonstration purposes only and should${NC} #"
echo -e "# ${VIOLET}be changed in a production environment.${NC} #"
echo -e "# #"
echo "################################################################################"
echo
declare -A nameCheckArray
# Ask for LXD project name
while true; do
read -r -p "Name of the misp project (default: $default_misp_project): " misp_project
PROJECT_NAME=${misp_project:-$default_misp_project}
if ! checkNamingConvention "$PROJECT_NAME"; then
continue
fi
if checkRessourceExist "project" "$PROJECT_NAME"; then
error "Project '$PROJECT_NAME' already exists."
continue
fi
break
done
# Ask for MISP image
while true; do
read -r -e -p "What is the path to the misp image (default: $default_misp_img): " misp_img
misp_img=${misp_img:-$default_misp_img}
if [ ! -f "$misp_img" ]; then
error "The specified file does not exist."
continue
fi
MISP_IMAGE=$misp_img
break
done
# Ask for MISP container name
while true; do
read -r -p "Name of the misp container (default: $default_misp_name): " misp_name
MISP_CONTAINER=${misp_name:-$default_misp_name}
if [[ ${nameCheckArray[$MISP_CONTAINER]+_} ]]; then
error "Name '$MISP_CONTAINER' has already been used. Please choose a different name."
continue
fi
if ! checkNamingConvention "$MISP_CONTAINER"; then
continue
fi
nameCheckArray[$MISP_CONTAINER]=1
break
done
# Ask for MySQL image
while true; do
read -r -e -p "What is the path to the MySQL image (default: $default_mysql_img): " mysql_img
mysql_img=${mysql_img:-$default_mysql_img}
if [ ! -f "$mysql_img" ]; then
error "The specified file does not exist."
continue
fi
MYSQL_IMAGE=$mysql_img
break
done
# Ask for MySQL container name
while true; do
read -r -p "Name of the MySQL container (default: $default_mysql_name): " mysql_name
MYSQL_CONTAINER=${mysql_name:-$default_mysql_name}
if [[ ${nameCheckArray[$MYSQL_CONTAINER]+_} ]]; then
error "Name '$MYSQL_CONTAINER' has already been used. Please choose a different name."
continue
fi
if ! checkNamingConvention "$MYSQL_CONTAINER"; then
continue
fi
nameCheckArray[$MYSQL_CONTAINER]=1
break
done
# Ask for MySQL credentials
read -r -p "MySQL Database (default: $default_mysql_db): " mysql_db
MYSQL_DATABASE=${mysql_db:-$default_mysql_db}
read -r -p "MySQL User (default: $default_mysql_user): " mysql_user
MYSQL_USER=${mysql_user:-$default_mysql_user}
read -r -p "MySQL User Password (default: $default_mysql_pwd): " mysql_pwd
MYSQL_PASSWORD=${mysql_pwd:-$default_mysql_pwd}
read -r -p "MySQL Root Password (default: $default_mysql_root_pwd): " mysql_root_pwd
MYSQL_ROOT_PASSWORD=${mysql_root_pwd:-$default_mysql_root_pwd}
# Ask for Redis image
while true; do
read -r -e -p "What is the path to the Redis image (default: $default_redis_img): " redis_img
redis_img=${redis_img:-$default_redis_img}
if [ ! -f "$redis_img" ]; then
error "The specified file does not exist."
continue
fi
REDIS_IMAGE=$redis_img
break
done
# Ask for Redis container name
while true; do
read -r -p "Name of the Redis container (default: $default_redis_name): " redis_name
REDIS_CONTAINER=${redis_name:-$default_redis_name}
if [[ ${nameCheckArray[$REDIS_CONTAINER]+_} ]]; then
error "Name '$REDIS_CONTAINER' has already been used. Please choose a different name."
continue
fi
if ! checkNamingConvention "$REDIS_CONTAINER"; then
continue
fi
nameCheckArray[$REDIS_CONTAINER]=1
break
done
# Ask for MISP Modules installation
read -r -p "Do you want to install MISP Modules (y/n, default: $default_modules): " modules
modules=${modules:-$default_modules}
MODULES=$(echo "$modules" | grep -iE '^y(es)?$' > /dev/null && echo true || echo false)
if $MODULES; then
# Ask for MISP Modules image
while true; do
read -r -e -p "What is the path to the Modules image (default: $default_modules_img): " modules_img
modules_img=${modules_img:-$default_modules_img}
if [ ! -f "$modules_img" ]; then
error "The specified file does not exist."
continue
fi
MODULES_IMAGE=$modules_img
break
done
# Ask for MISP Modules container name
while true; do
read -r -p "Name of the Modules container (default: $default_modules_name): " modules_name
MODULES_CONTAINER=${modules_name:-$default_modules_name}
if [[ ${nameCheckArray[$MODULES_CONTAINER]+_} ]]; then
error "Name '$MODULES_CONTAINER' has already been used. Please choose a different name."
continue
fi
if ! checkNamingConvention "$MODULES_CONTAINER"; then
continue
fi
nameCheckArray[$MODULES_CONTAINER]=1
break
done
fi
# Ask for dedicated partitions
read -r -p "Dedicated partition for MISP container (leave blank if none): " app_partition
APP_PARTITION=${app_partition:-$default_app_partition}
read -r -p "Dedicated partition for DB container (leave blank if none): " db_partition
DB_PARTITION=${db_partition:-$default_db_partition}
# Ask if used in prod
read -r -p "Do you want to use this setup in production (y/n, default: $default_prod): " prod
prod=${prod:-$default_prod}
PROD=$(echo "$prod" | grep -iE '^y(es)?$' > /dev/null && echo true || echo false)
if $PROD; then
checkForDefault
fi
# Output values set by the user
echo -e "\nValues set:"
echo "--------------------------------------------------------------------------------------------------------------------"
echo -e "PROJECT_NAME: ${GREEN}$PROJECT_NAME${NC}"
echo "--------------------------------------------------------------------------------------------------------------------"
echo -e "${BLUE}MISP:${NC}"
echo -e "MISP_IMAGE: ${GREEN}$MISP_IMAGE${NC}"
echo -e "MISP_CONTAINER: ${GREEN}$MISP_CONTAINER${NC}"
echo "--------------------------------------------------------------------------------------------------------------------"
echo -e "${BLUE}MySQL:${NC}"
echo -e "MYSQL_IMAGE: ${GREEN}$MYSQL_IMAGE${NC}"
echo -e "MYSQL_CONTAINER: ${GREEN}$MYSQL_CONTAINER${NC}"
echo -e "MYSQL_DATABASE: ${GREEN}$MYSQL_DATABASE${NC}"
echo -e "MYSQL_USER: ${GREEN}$MYSQL_USER${NC}"
echo -e "MYSQL_PASSWORD: ${GREEN}$MYSQL_PASSWORD${NC}"
echo -e "MYSQL_ROOT_PASSWORD: ${GREEN}$MYSQL_ROOT_PASSWORD${NC}"
echo "--------------------------------------------------------------------------------------------------------------------"
echo -e "${BLUE}Redis:${NC}"
echo -e "REDIS_IMAGE: ${GREEN}$REDIS_IMAGE${NC}"
echo -e "REDIS_CONTAINER: ${GREEN}$REDIS_CONTAINER${NC}"
echo "--------------------------------------------------------------------------------------------------------------------"
echo -e "${BLUE}MISP Modules:${NC}"
echo -e "MISP Modules: ${GREEN}$MODULES${NC}"
if $MODULES; then
echo -e "MODULES_IMAGE: ${GREEN}$MODULES_IMAGE${NC}"
echo -e "MODULES_CONTAINER: ${GREEN}$MODULES_CONTAINER${NC}"
fi
echo "--------------------------------------------------------------------------------------------------------------------"
echo -e "${BLUE}Storage:${NC}"
echo -e "APP_PARTITION: ${GREEN}$APP_PARTITION${NC}"
echo -e "DB_PARTITION: ${GREEN}$DB_PARTITION${NC}"
echo "--------------------------------------------------------------------------------------------------------------------"
echo -e "${BLUE}Security:${NC}"
echo -e "PROD: ${GREEN}$PROD${NC}\n"
echo "--------------------------------------------------------------------------------------------------------------------"
# Ask for confirmation
read -r -p "Do you want to proceed with the installation? (y/n): " confirm
confirm=${confirm:-$default_confirm}
if [[ $confirm != "y" ]]; then
warn "Installation aborted."
exit 1
fi
}
setupLXD(){
# Create Project
lxc project create "$PROJECT_NAME"
lxc project switch "$PROJECT_NAME"
# Create storage pools
APP_STORAGE=$(generateName "app-storage")
if checkRessourceExist "storage" "$APP_STORAGE"; then
error "Storage '$APP_STORAGE' already exists."
exit 1
fi
lxc storage create "$APP_STORAGE" zfs source="$APP_PARTITION"
DB_STORAGE=$(generateName "db-storage")
if checkRessourceExist "storage" "$DB_STORAGE"; then
error "Storage '$DB_STORAGE' already exists."
exit 1
fi
lxc storage create "$DB_STORAGE" zfs source="$DB_PARTITION"
# Create Network
NETWORK_NAME=$(generateName "net")
# max len of 15
NETWORK_NAME=${NETWORK_NAME:0:14}
if checkRessourceExist "network" "$NETWORK_NAME"; then
error "Network '$NETWORK_NAME' already exists."
fi
lxc network create "$NETWORK_NAME" --type=bridge
# Create Profiles
APP_PROFILE=$(generateName "app")
if checkRessourceExist "profile" "$APP_PROFILE"; then
error "Profile '$APP_PROFILE' already exists."
fi
lxc profile create "$APP_PROFILE"
lxc profile device add "$APP_PROFILE" root disk path=/ pool="$APP_STORAGE"
lxc profile device add "$APP_PROFILE" eth0 nic name=eth0 network="$NETWORK_NAME"
DB_PROFILE=$(generateName "db")
echo "db-profile: $DB_PROFILE"
if checkRessourceExist "profile" "$DB_PROFILE"; then
error "Profile '$DB_PROFILE' already exists."
fi
lxc profile create "$DB_PROFILE"
lxc profile device add "$DB_PROFILE" root disk path=/ pool="$DB_STORAGE"
lxc profile device add "$DB_PROFILE" eth0 nic name=eth0 network="$NETWORK_NAME"
}
importImages(){
# Import Images
MISP_IMAGE_NAME=$(generateName "misp")
echo "image: $MISP_IMAGE_NAME"
if checkRessourceExist "image" "$MISP_IMAGE_NAME"; then
error "Image '$MISP_IMAGE_NAME' already exists."
fi
lxc image import "$MISP_IMAGE" --alias "$MISP_IMAGE_NAME"
MYSQL_IMAGE_NAME=$(generateName "mysql")
if checkRessourceExist "image" "$MYSQL_IMAGE_NAME"; then
error "Image '$MYSQL_IMAGE_NAME' already exists."
fi
lxc image import "$MYSQL_IMAGE" --alias "$MYSQL_IMAGE_NAME"
REDIS_IMAGE_NAME=$(generateName "redis")
if checkRessourceExist "image" "$REDIS_IMAGE_NAME"; then
error "Image '$REDIS_IMAGE_NAME' already exists."
fi
lxc image import "$REDIS_IMAGE" --alias "$REDIS_IMAGE_NAME"
if $MODULES; then
MODULES_IMAGE_NAME=$(generateName "modules")
if checkRessourceExist "image" "$MODULES_IMAGE_NAME"; then
error "Image '$MODULES_IMAGE_NAME' already exists."
fi
lxc image import "$MODULES_IMAGE" --alias "$MODULES_IMAGE_NAME"
fi
}
launchContainers(){
# Launch Containers
lxc launch $MISP_IMAGE_NAME $MISP_CONTAINER --profile=$APP_PROFILE
lxc launch $MYSQL_IMAGE_NAME $MYSQL_CONTAINER --profile=$DB_PROFILE
lxc launch $REDIS_IMAGE_NAME $REDIS_CONTAINER --profile=$DB_PROFILE
if $MODULES; then
lxc launch $MODULES_IMAGE_NAME $MODULES_CONTAINER --profile=$APP_PROFILE
fi
}
configureMISPForDB(){
## Edit database conf
${LXC_MISP} -- sed -i "s/'database' => 'misp'/'database' => '$MYSQL_DATABASE'/" $PATH_TO_MISP/app/Config/database.php
${LXC_MISP} -- sed -i "s/localhost/$MYSQL_CONTAINER.lxd/" $PATH_TO_MISP/app/Config/database.php
${LXC_MISP} -- sed -i "s/'login' => '.*'/'login' => '$MYSQL_USER'/" "$PATH_TO_MISP/app/Config/database.php"
${LXC_MISP} -- sed -i "s/8889/3306/" $PATH_TO_MISP/app/Config/database.php
${LXC_MISP} -- sed -i "s/'password' => '.*'/'password' => '$MYSQL_PASSWORD'/" "$PATH_TO_MISP/app/Config/database.php"
# Write credentials to MISP
${LXC_MISP} -- sh -c "echo 'Admin (root) DB Password: $MYSQL_ROOT_PASSWORD \nUser ($MYSQL_USER) DB Password: $MYSQL_PASSWORD' > /home/misp/mysql.txt"
}
editMySQLConf(){
local key=$1
local value=$2
local container=$3
lxc exec $container -- bash -c "\
if grep -q '^$key' /etc/mysql/mariadb.conf.d/50-server.cnf; then \
sed -i 's/^$key.*/$key = $value/' /etc/mysql/mariadb.conf.d/50-server.cnf; \
else \
awk -v $key='$key = $value' \
'/^\[mysqld\]/ {print; print $key; next} {print}' \
/etc/mysql/mariadb.conf.d/50-server.cnf > /tmp/php.ini.modified && \
mv /tmp/php.ini.modified /etc/mysql/mariadb.conf.d/50-server.cnf; \
fi"
}
configureMySQL(){
## Add user + DB
lxc exec $MYSQL_CONTAINER -- mariadb -u root -e "CREATE DATABASE $MYSQL_DATABASE;"
lxc exec $MYSQL_CONTAINER -- mariadb -u root -e "GRANT ALL PRIVILEGES ON $MYSQL_DATABASE.* TO '$MYSQL_USER'@'$MISP_CONTAINER.lxd' IDENTIFIED BY '$MYSQL_PASSWORD';"
## Configure remote access
lxc exec $MYSQL_CONTAINER -- sed -i 's/bind-address = 127.0.0.1/bind-address = 0.0.0.0/' "/etc/mysql/mariadb.conf.d/50-server.cnf"
editMySQLConf "innodb_write_io_threads" "$INNODB_WRITE_IO_THREADS" "$MYSQL_CONTAINER"
editMySQLConf "innodb_stats_persistent" "$INNODB_STATS_PERISTENT" "$MYSQL_CONTAINER"
editMySQLConf "innodb_read_io_threads" "$INNODB_READ_IO_THREADS" "$MYSQL_CONTAINER"
editMySQLConf "innodb_log_files_in_group" "$INNODB_LOG_FILES_IN_GROUP" "$MYSQL_CONTAINER"
editMySQLConf "innodb_log_file_size" "$INNODB_LOG_FILE_SIZE" "$MYSQL_CONTAINER"
editMySQLConf "innodb_io_capacity_max" "$INNODB_IO_CAPACITY_MAX" "$MYSQL_CONTAINER"
editMySQLConf "innodb_io_capacity" "$INNODB_IO_CAPACITY" "$MYSQL_CONTAINER"
editMySQLConf "innodb_change_buffering" "$INNODB_CHANGE_BUFFERING" "$MYSQL_CONTAINER"
editMySQLConf "innodb_buffer_pool_size" "$INNODB_BUFFER_POOL_SIZE" "$MYSQL_CONTAINER"
lxc exec $MYSQL_CONTAINER -- sudo systemctl restart mariadb
## secure MySQL installation
lxc exec $MYSQL_CONTAINER -- mariadb-admin -u root password "$MYSQL_ROOT_PASSWORD"
lxc exec $MYSQL_CONTAINER -- mariadb -u root -p"$MYSQL_ROOT_PASSWORD" <<EOF
DELETE FROM mysql.user WHERE User='';
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
DROP DATABASE IF EXISTS test;
FLUSH PRIVILEGES;
EOF
}
configureRedisContainer(){
## Cofigure remote access
lxc exec $REDIS_CONTAINER -- sed -i "s/^bind .*/bind 0.0.0.0/" "/etc/redis/redis.conf"
lxc exec $REDIS_CONTAINER -- sed -i "s/^port .*/port $REDIS_CONTAINER_PORT/" "/etc/redis/redis.conf"
lxc exec $REDIS_CONTAINER -- systemctl restart redis-server
}
configureMISPforRedis(){
# CakeResque redis
${LXC_MISP} -- sed -i "s/'host' => '127.0.0.1'/'host' => '$REDIS_CONTAINER.lxd'/; s/'port' => 6379/'port' => $REDIS_CONTAINER_PORT/" /var/www/MISP/app/Plugin/CakeResque/Config/config.php
}
createRedisSocket(){
local file_path="/etc/redis/redis.conf"
local lines_to_add="# create a unix domain socket to listen on\nunixsocket /var/run/redis/redis.sock\n# set permissions for the socket\nunixsocketperm 775"
${LXC_MISP} -- usermod -g www-data redis
${LXC_MISP} -- mkdir -p /var/run/redis/
${LXC_MISP} -- chown -R redis:www-data /var/run/redis
${LXC_MISP} -- cp "$file_path" "$file_path.bak"
${LXC_MISP} -- bash -c "echo -e \"$lines_to_add\" | cat - \"$file_path\" >tempfile && mv tempfile \"$file_path\""
${LXC_MISP} -- usermod -aG redis www-data
${LXC_MISP} -- service redis-server restart
# Modify php.ini
local php_ini_path="/etc/php/$PHP_VERSION/apache2/php.ini"
local socket_path="/var/run/redis/redis.sock"
${LXC_MISP} -- sed -i "s|;session.save_path = \"/var/lib/php/sessions\"|session.save_path = \"$socket_path\"|; s|session.save_handler = files|session.save_handler = redis|" $php_ini_path
${LXC_MISP} -- sudo service apache2 restart
}
initializeDB(){
## Check connection + import schema to MySQL
table_count=$(${LXC_MISP} -- mysql -u $MYSQL_USER --password="$MYSQL_PASSWORD" -h $MYSQL_CONTAINER.lxd -P 3306 $MYSQL_DATABASE -e "SHOW TABLES;" | wc -l)
if [ $? -eq 0 ]; then
echo -e "${GREEN}Connected to database successfully!${NC}"
if [ $table_count -lt 73 ]; then
echo "Database misp is empty, importing tables from misp container ..."
${LXC_MISP} -- bash -c "mysql -u $MYSQL_USER --password=$MYSQL_PASSWORD $MYSQL_DATABASE -h $MYSQL_CONTAINER.lxd -P 3306 2>&1 < $PATH_TO_MISP/INSTALL/MYSQL.sql"
else
echo "Database misp available"
fi
else
error $table_count
fi
# Update DB
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin runUpdates
}
configureMISPModules(){
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Enrichment_services_enable" true
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Enrichment_hover_enable" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Enrichment_hover_popover_only" false
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Enrichment_timeout" 300
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Enrichment_hover_timeout" 150
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Enrichment_services_url" "$MODULES_CONTAINER.lxd"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Enrichment_services_port" 6666
# Enable Import modules
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Import_services_enable" true
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Import_services_url" "$MODULES_CONTAINER.lxd"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Import_services_port" 6666
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Import_timeout" 300
# Enable export modules
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Export_services_enable" true
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Export_services_url" "$MODULES_CONTAINER.lxd"
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Export_services_port" 6666
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting "Plugin.Export_timeout" 300
# Enable additional module settings
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_bgpranking_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_countrycode_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_cve_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_cve_advanced_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_cpe_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_dns_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_eql_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_btc_steroids_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_ipasn_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_reversedns_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_yara_syntax_validator_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_yara_query_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_wiki_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_threatminer_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_threatcrowd_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_hashdd_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_rbl_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_sigma_syntax_validator_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_stix2_pattern_syntax_validator_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_sigma_queries_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_dbl_spamhaus_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_btc_scam_check_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_macvendors_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_qrcode_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_ocr_enrich_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_pdf_enrich_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_docx_enrich_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_xlsx_enrich_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_pptx_enrich_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_ods_enrich_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_odt_enrich_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_urlhaus_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_malwarebazaar_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_html_to_markdown_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Enrichment_socialscan_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Import_ocr_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Import_mispjson_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Import_openiocimport_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Import_threatanalyzer_import_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Import_csvimport_enabled" true
${LXC_MISP} -- ${SUDO_WWW} ${RUN_PHP} -- ${CAKE} Admin setSetting "Plugin.Export_pdfexport_enabled" true
# Set API_Required modules to false
PLUGS=(Plugin.Enrichment_cuckoo_submit_enabled
Plugin.Enrichment_vmray_submit_enabled
Plugin.Enrichment_circl_passivedns_enabled
Plugin.Enrichment_circl_passivessl_enabled
Plugin.Enrichment_domaintools_enabled
Plugin.Enrichment_eupi_enabled
Plugin.Enrichment_farsight_passivedns_enabled
Plugin.Enrichment_passivetotal_enabled
Plugin.Enrichment_passivetotal_enabled
Plugin.Enrichment_virustotal_enabled
Plugin.Enrichment_whois_enabled
Plugin.Enrichment_shodan_enabled
Plugin.Enrichment_geoip_asn_enabled
Plugin.Enrichment_geoip_city_enabled
Plugin.Enrichment_geoip_country_enabled
Plugin.Enrichment_iprep_enabled
Plugin.Enrichment_otx_enabled
Plugin.Enrichment_vulndb_enabled
Plugin.Enrichment_crowdstrike_falcon_enabled
Plugin.Enrichment_onyphe_enabled
Plugin.Enrichment_xforceexchange_enabled
Plugin.Enrichment_vulners_enabled
Plugin.Enrichment_macaddress_io_enabled
Plugin.Enrichment_intel471_enabled
Plugin.Enrichment_backscatter_io_enabled
Plugin.Enrichment_hibp_enabled
Plugin.Enrichment_greynoise_enabled
Plugin.Enrichment_joesandbox_submit_enabled
Plugin.Enrichment_virustotal_public_enabled
Plugin.Enrichment_apiosintds_enabled
Plugin.Enrichment_urlscan_enabled
Plugin.Enrichment_securitytrails_enabled
Plugin.Enrichment_apivoid_enabled
Plugin.Enrichment_assemblyline_submit_enabled
Plugin.Enrichment_assemblyline_query_enabled
Plugin.Enrichment_ransomcoindb_enabled
Plugin.Enrichment_lastline_query_enabled
Plugin.Enrichment_sophoslabs_intelix_enabled
Plugin.Enrichment_cytomic_orion_enabled
Plugin.Enrichment_censys_enrich_enabled
Plugin.Enrichment_trustar_enrich_enabled
Plugin.Enrichment_recordedfuture_enabled
Plugin.ElasticSearch_logging_enable
Plugin.S3_enable)
for PLUG in "${PLUGS[@]}"; do
${LXC_MISP} -- ${SUDO_WWW} -- ${CAKE} Admin setSetting ${PLUG} false 2> /dev/null
done
}
deleteLXDProject(){
local project="$1"
echo "Starting cleanup ..."
echo "Deleting container in project"
for container in $(lxc query "/1.0/containers?recursion=1&project=${project}" | jq .[].name -r); do
lxc delete --project "${project}" -f "${container}"
done
echo "Deleting images in project"
for image in $(lxc query "/1.0/images?recursion=1&project=${project}" | jq .[].fingerprint -r); do
lxc image delete --project "${project}" "${image}"
done
echo "Deleting profiles in project"
for profile in $(lxc query "/1.0/profiles?recursion=1&project=${project}" | jq .[].name -r); do
if [ "${profile}" = "default" ]; then
printf 'config: {}\ndevices: {}' | lxc profile edit --project "${project}" default
continue
fi
lxc profile delete --project "${project}" "${profile}"
done
echo "Deleting project"
lxc project delete "${project}"
}
err() {
local parent_lineno="$1"
local message="$2"
local code="${3:-1}"
if [[ -n "$message" ]] ; then
error "Line ${parent_lineno}: ${message}: exiting with status ${code}"
else
error "Line ${parent_lineno}: exiting with status ${code}"
fi
deleteLXDProject "$PROJECT_NAME"
lxc storage delete "$APP_STORAGE"
lxc storage delete "$DB_STORAGE"
lxc network delete "$NETWORK_NAME"
exit "${code}"
}
interrupt() {
warn "Script interrupted by user. Delete project and exit ..."
deleteLXDProject "$PROJECT_NAME"
lxc storage delete "$APP_STORAGE"
lxc storage delete "$DB_STORAGE"
lxc network delete "$NETWORK_NAME"
exit 130
}
usage() {
echo "Usage: $0 [OPTIONS]"
echo
echo "Options:"
echo " -i, --interactive Activates an interactive installation process."
echo " -p, --production Set the MISP application to run in production mode."