-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_que_funciona.sh
More file actions
3628 lines (3045 loc) · 129 KB
/
Copy pathscript_que_funciona.sh
File metadata and controls
3628 lines (3045 loc) · 129 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
echo " ____ _ _ _ ____ _ _
| _ \ __ _ _ __ __ _ ___(_) |_ ___ ___ __| | ___ / ___(_) |__ ___ _ __
| |_) / _\` | '_ \ / _\` |/ __| | __/ _ \/ __| / _\` |/ _ \ | | | | '_ \ / _ \ '__|
| __/ (_| | |_) | (_| | (__| | || (_) \__ \ | (_| | __/ | |___| | |_) | __/ |
|_| \__,_| .__/ \__,_|\___|_|\__\___/|___/ \__,_|\___| \____|_|_.__/ \___|_|
|_| "
#!/usr/bin/env bash
{
l_mname="cramfs" # set module name
l_mtype="fs" # set module type
l_mpath="/lib/modules/**/kernel/$l_mtype"
l_mpname="$(tr '-' '_' <<< "$l_mname")"
l_mndir="$(tr '-' '/' <<< "$l_mname")"
module_loadable_fix()
{
# If the module is currently loadable, add "install {MODULE_NAME} /bin/false" to a file in
"/etc/modprobe.d"
l_loadable="$(modprobe -n -v "$l_mname")"
[ "$(wc -l <<< "$l_loadable")" -gt "1" ] && l_loadable="$(grep -P --
"(^\h*install|\b$l_mname)\b" <<< "$l_loadable")"
if ! grep -Pq -- '^\h*install \/bin\/(true|false)' <<< "$l_loadable"; then
echo -e "\n - setting module: \"$l_mname\" to be not loadable"
echo -e "install $l_mname /bin/false" >> /etc/modprobe.d/"$l_mpname".conf
fi
}
module_loaded_fix()
{
# If the module is currently loaded, unload the module
if lsmod | grep "$l_mname" > /dev/null 2>&1; then
echo -e "\n - unloading module \"$l_mname\""
modprobe -r "$l_mname"
fi
}
module_deny_fix()
{
# If the module isn't deny listed, denylist the module
if ! modprobe --showconfig | grep -Pq -- "^\h*blacklist\h+$l_mpname\b"; then
echo -e "\n - deny listing \"$l_mname\""
echo -e "blacklist $l_mname" >> /etc/modprobe.d/"$l_mpname".conf
fi
}
# Check if the module exists on the system
for l_mdir in $l_mpath; do
if [ -d "$l_mdir/$l_mndir" ] && [ -n "$(ls -A $l_mdir/$l_mndir)" ]; then
echo -e "\n - module: \"$l_mname\" exists in \"$l_mdir\"\n - checking if disabled..."
module_deny_fix
if [ "$l_mdir" = "/lib/modules/$(uname -r)/kernel/$l_mtype" ]; then
module_loadable_fix
module_loaded_fix
fi
else
echo -e "\n - module: \"$l_mname\" doesn't exist in \"$l_mdir\"\n"
fi
done
echo -e "\n - remediation of module: \"$l_mname\" complete\n"
}
{
l_mname="freevxfs" # set module name
l_mtype="fs" # set module type
l_mpath="/lib/modules/**/kernel/$l_mtype"
l_mpname="$(tr '-' '_' <<< "$l_mname")"
l_mndir="$(tr '-' '/' <<< "$l_mname")"
module_loadable_fix()
{
# If the module is currently loadable, add "install {MODULE_NAME} /bin/false" to a file in
"/etc/modprobe.d"
l_loadable="$(modprobe -n -v "$l_mname")"
[ "$(wc -l <<< "$l_loadable")" -gt "1" ] && l_loadable="$(grep -P --
"(^\h*install|\b$l_mname)\b" <<< "$l_loadable")"
if ! grep -Pq -- '^\h*install \/bin\/(true|false)' <<< "$l_loadable"; then
echo -e "\n - setting module: \"$l_mname\" to be not loadable"
echo -e "install $l_mname /bin/false" >> /etc/modprobe.d/"$l_mpname".conf
fi
}
module_loaded_fix()
{
# If the module is currently loaded, unload the module
if lsmod | grep "$l_mname" > /dev/null 2>&1; then
echo -e "\n - unloading module \"$l_mname\""
modprobe -r "$l_mname"
fi
}
module_deny_fix()
{
# If the module isn't deny listed, denylist the module
if ! modprobe --showconfig | grep -Pq -- "^\h*blacklist\h+$l_mpname\b"; then
echo -e "\n - deny listing \"$l_mname\""
echo -e "blacklist $l_mname" >> /etc/modprobe.d/"$l_mpname".conf
fi
}
# Check if the module exists on the system
for l_mdir in $l_mpath; do
if [ -d "$l_mdir/$l_mndir" ] && [ -n "$(ls -A $l_mdir/$l_mndir)" ]; then
echo -e "\n - module: \"$l_mname\" exists in \"$l_mdir\"\n - checking if disabled..."
module_deny_fix
if [ "$l_mdir" = "/lib/modules/$(uname -r)/kernel/$l_mtype" ]; then
module_loadable_fix
module_loaded_fix
fi
else
echo -e "\n - module: \"$l_mname\" doesn't exist in \"$l_mdir\"\n"
fi
done
echo -e "\n - remediation of module: \"$l_mname\" complete\n"
}
{
l_mname="hfs" # set module name
l_mtype="fs" # set module type
l_mpath="/lib/modules/**/kernel/$l_mtype"
l_mpname="$(tr '-' '_' <<< "$l_mname")"
l_mndir="$(tr '-' '/' <<< "$l_mname")"
module_loadable_fix()
{
# If the module is currently loadable, add "install {MODULE_NAME} /bin/false" to a file in
"/etc/modprobe.d"
l_loadable="$(modprobe -n -v "$l_mname")"
[ "$(wc -l <<< "$l_loadable")" -gt "1" ] && l_loadable="$(grep -P --
"(^\h*install|\b$l_mname)\b" <<< "$l_loadable")"
if ! grep -Pq -- '^\h*install \/bin\/(true|false)' <<< "$l_loadable"; then
echo -e "\n - setting module: \"$l_mname\" to be not loadable"
echo -e "install $l_mname /bin/false" >> /etc/modprobe.d/"$l_mpname".conf
fi
}
module_loaded_fix()
{
# If the module is currently loaded, unload the module
if lsmod | grep "$l_mname" > /dev/null 2>&1; then
echo -e "\n - unloading module \"$l_mname\""
modprobe -r "$l_mname"
fi
}
module_deny_fix()
{
# If the module isn't deny listed, denylist the module
if ! modprobe --showconfig | grep -Pq -- "^\h*blacklist\h+$l_mpname\b"; then
echo -e "\n - deny listing \"$l_mname\""
echo -e "blacklist $l_mname" >> /etc/modprobe.d/"$l_mpname".conf
fi
}
# Check if the module exists on the system
for l_mdir in $l_mpath; do
if [ -d "$l_mdir/$l_mndir" ] && [ -n "$(ls -A $l_mdir/$l_mndir)" ]; then
echo -e "\n - module: \"$l_mname\" exists in \"$l_mdir\"\n - checking if disabled..."
module_deny_fix
if [ "$l_mdir" = "/lib/modules/$(uname -r)/kernel/$l_mtype" ]; then
module_loadable_fix
module_loaded_fix
fi
else
echo -e "\n - module: \"$l_mname\" doesn't exist in \"$l_mdir\"\n"
fi
done
echo -e "\n - remediation of module: \"$l_mname\" complete\n"
}
{
l_mname="hfsplus" # set module name
l_mtype="fs" # set module type
l_mpath="/lib/modules/**/kernel/$l_mtype"
l_mpname="$(tr '-' '_' <<< "$l_mname")"
l_mndir="$(tr '-' '/' <<< "$l_mname")"
module_loadable_fix()
{
# If the module is currently loadable, add "install {MODULE_NAME} /bin/false" to a file in
"/etc/modprobe.d"
l_loadable="$(modprobe -n -v "$l_mname")"
[ "$(wc -l <<< "$l_loadable")" -gt "1" ] && l_loadable="$(grep -P --
"(^\h*install|\b$l_mname)\b" <<< "$l_loadable")"
if ! grep -Pq -- '^\h*install \/bin\/(true|false)' <<< "$l_loadable"; then
echo -e "\n - setting module: \"$l_mname\" to be not loadable"
echo -e "install $l_mname /bin/false" >> /etc/modprobe.d/"$l_mpname".conf
fi
}
module_loaded_fix()
{
# If the module is currently loaded, unload the module
if lsmod | grep "$l_mname" > /dev/null 2>&1; then
echo -e "\n - unloading module \"$l_mname\""
modprobe -r "$l_mname"
fi
}
module_deny_fix()
{
# If the module isn't deny listed, denylist the module
if ! modprobe --showconfig | grep -Pq -- "^\h*blacklist\h+$l_mpname\b"; then
echo -e "\n - deny listing \"$l_mname\""
echo -e "blacklist $l_mname" >> /etc/modprobe.d/"$l_mpname".conf
fi
}
# Check if the module exists on the system
for l_mdir in $l_mpath; do
if [ -d "$l_mdir/$l_mndir" ] && [ -n "$(ls -A $l_mdir/$l_mndir)" ]; then
echo -e "\n - module: \"$l_mname\" exists in \"$l_mdir\"\n - checking if disabled..."
module_deny_fix
if [ "$l_mdir" = "/lib/modules/$(uname -r)/kernel/$l_mtype" ]; then
module_loadable_fix
module_loaded_fix
fi
else
echo -e "\n - module: \"$l_mname\" doesn't exist in \"$l_mdir\"\n"
fi
done
echo -e "\n - remediation of module: \"$l_mname\" complete\n"
}
{
l_mname="jffs2" # set module name
l_mtype="fs" # set module type
l_mpath="/lib/modules/**/kernel/$l_mtype"
l_mpname="$(tr '-' '_' <<< "$l_mname")"
l_mndir="$(tr '-' '/' <<< "$l_mname")"
module_loadable_fix()
{
# If the module is currently loadable, add "install {MODULE_NAME} /bin/false" to a file in
"/etc/modprobe.d"
l_loadable="$(modprobe -n -v "$l_mname")"
[ "$(wc -l <<< "$l_loadable")" -gt "1" ] && l_loadable="$(grep -P --
"(^\h*install|\b$l_mname)\b" <<< "$l_loadable")"
if ! grep -Pq -- '^\h*install \/bin\/(true|false)' <<< "$l_loadable"; then
echo -e "\n - setting module: \"$l_mname\" to be not loadable"
echo -e "install $l_mname /bin/false" >> /etc/modprobe.d/"$l_mpname".conf
fi
}
module_loaded_fix()
{
# If the module is currently loaded, unload the module
if lsmod | grep "$l_mname" > /dev/null 2>&1; then
echo -e "\n - unloading module \"$l_mname\""
modprobe -r "$l_mname"
fi
}
module_deny_fix()
{
# If the module isn't deny listed, denylist the module
if ! modprobe --showconfig | grep -Pq -- "^\h*blacklist\h+$l_mpname\b"; then
echo -e "\n - deny listing \"$l_mname\""
echo -e "blacklist $l_mname" >> /etc/modprobe.d/"$l_mpname".conf
fi
}
# Check if the module exists on the system
for l_mdir in $l_mpath; do
if [ -d "$l_mdir/$l_mndir" ] && [ -n "$(ls -A $l_mdir/$l_mndir)" ]; then
echo -e "\n - module: \"$l_mname\" exists in \"$l_mdir\"\n - checking if disabled..."
module_deny_fix
if [ "$l_mdir" = "/lib/modules/$(uname -r)/kernel/$l_mtype" ]; then
module_loadable_fix
module_loaded_fix
fi
else
echo -e "\n - module: \"$l_mname\" doesn't exist in \"$l_mdir\"\n"
fi
done
echo -e "\n - remediation of module: \"$l_mname\" complete\n"
}
{
l_mname="squashfs" # set module name
l_mtype="fs" # set module type
l_mpath="/lib/modules/**/kernel/$l_mtype"
l_mpname="$(tr '-' '_' <<< "$l_mname")"
l_mndir="$(tr '-' '/' <<< "$l_mname")"
module_loadable_fix()
{
# If the module is currently loadable, add "install {MODULE_NAME} /bin/false" to a file in
"/etc/modprobe.d"
l_loadable="$(modprobe -n -v "$l_mname")"
[ "$(wc -l <<< "$l_loadable")" -gt "1" ] && l_loadable="$(grep -P --
"(^\h*install|\b$l_mname)\b" <<< "$l_loadable")"
if ! grep -Pq -- '^\h*install \/bin\/(true|false)' <<< "$l_loadable"; then
echo -e "\n - setting module: \"$l_mname\" to be not loadable"
echo -e "install $l_mname /bin/false" >> /etc/modprobe.d/"$l_mpname".conf
fi
}
module_loaded_fix()
{
# If the module is currently loaded, unload the module
if lsmod | grep "$l_mname" > /dev/null 2>&1; then
echo -e "\n - unloading module \"$l_mname\""
modprobe -r "$l_mname"
fi
}
module_deny_fix()
{
# If the module isn't deny listed, denylist the module
if ! modprobe --showconfig | grep -Pq -- "^\h*blacklist\h+$l_mpname\b"; then
echo -e "\n - deny listing \"$l_mname\""
echo -e "blacklist $l_mname" >> /etc/modprobe.d/"$l_mpname".conf
fi
}
# Check if the module exists on the system
for l_mdir in $l_mpath; do
if [ -d "$l_mdir/$l_mndir" ] && [ -n "$(ls -A $l_mdir/$l_mndir)" ]; then
echo -e "\n - module: \"$l_mname\" exists in \"$l_mdir\"\n - checking if disabled..."
module_deny_fix
if [ "$l_mdir" = "/lib/modules/$(uname -r)/kernel/$l_mtype" ]; then
module_loadable_fix
module_loaded_fix
fi
else
echo -e "\n - module: \"$l_mname\" doesn't exist in \"$l_mdir\"\n"
fi
done
echo -e "\n - remediation of module: \"$l_mname\" complete\n"
}
{
l_mname="udf" # set module name
l_mtype="fs" # set module type
l_mpath="/lib/modules/**/kernel/$l_mtype"
l_mpname="$(tr '-' '_' <<< "$l_mname")"
l_mndir="$(tr '-' '/' <<< "$l_mname")"
module_loadable_fix()
{
# If the module is currently loadable, add "install {MODULE_NAME} /bin/false" to a file in
"/etc/modprobe.d"
l_loadable="$(modprobe -n -v "$l_mname")"
[ "$(wc -l <<< "$l_loadable")" -gt "1" ] && l_loadable="$(grep -P --
"(^\h*install|\b$l_mname)\b" <<< "$l_loadable")"
if ! grep -Pq -- '^\h*install \/bin\/(true|false)' <<< "$l_loadable"; then
echo -e "\n - setting module: \"$l_mname\" to be not loadable"
echo -e "install $l_mname /bin/false" >> /etc/modprobe.d/"$l_mpname".conf
fi
}
module_loaded_fix()
{
# If the module is currently loaded, unload the module
if lsmod | grep "$l_mname" > /dev/null 2>&1; then
echo -e "\n - unloading module \"$l_mname\""
modprobe -r "$l_mname"
fi
}
module_deny_fix()
{
# If the module isn't deny listed, denylist the module
if ! modprobe --showconfig | grep -Pq -- "^\h*blacklist\h+$l_mpname\b"; then
echo -e "\n - deny listing \"$l_mname\""
echo -e "blacklist $l_mname" >> /etc/modprobe.d/"$l_mpname".conf
fi
}
# Check if the module exists on the system
for l_mdir in $l_mpath; do
if [ -d "$l_mdir/$l_mndir" ] && [ -n "$(ls -A $l_mdir/$l_mndir)" ]; then
echo -e "\n - module: \"$l_mname\" exists in \"$l_mdir\"\n - checking if disabled..."
module_deny_fix
if [ "$l_mdir" = "/lib/modules/$(uname -r)/kernel/$l_mtype" ]; then
module_loadable_fix
module_loaded_fix
fi
else
echo -e "\n - module: \"$l_mname\" doesn't exist in \"$l_mdir\"\n"
fi
done
echo -e "\n - remediation of module: \"$l_mname\" complete\n"
}
{
l_mname="usb-storage" # set module name
l_mtype="drivers" # set module type
l_mpath="/lib/modules/**/kernel/$l_mtype"
l_mpname="$(tr '-' '_' <<< "$l_mname")"
l_mndir="$(tr '-' '/' <<< "$l_mname")"
module_loadable_fix()
{
# If the module is currently loadable, add "install {MODULE_NAME} /bin/false" to a file in
"/etc/modprobe.d"
l_loadable="$(modprobe -n -v "$l_mname")"
[ "$(wc -l <<< "$l_loadable")" -gt "1" ] && l_loadable="$(grep -P --
"(^\h*install|\b$l_mname)\b" <<< "$l_loadable")"
if ! grep -Pq -- '^\h*install \/bin\/(true|false)' <<< "$l_loadable"; then
echo -e "\n - setting module: \"$l_mname\" to be not loadable"
echo -e "install $l_mname /bin/false" >> /etc/modprobe.d/"$l_mpname".conf
fi
}
module_loaded_fix()
{
# If the module is currently loaded, unload the module
if lsmod | grep "$l_mname" > /dev/null 2>&1; then
echo -e "\n - unloading module \"$l_mname\""
modprobe -r "$l_mname"
fi
}
module_deny_fix()
{
# If the module isn't deny listed, denylist the module
if ! modprobe --showconfig | grep -Pq -- "^\h*blacklist\h+$l_mpname\b"; then
echo -e "\n - deny listing \"$l_mname\""
echo -e "blacklist $l_mname" >> /etc/modprobe.d/"$l_mpname".conf
fi
}
# Check if the module exists on the system
for l_mdir in $l_mpath; do
if [ -d "$l_mdir/$l_mndir" ] && [ -n "$(ls -A $l_mdir/$l_mndir)" ]; then
echo -e "\n - module: \"$l_mname\" exists in \"$l_mdir\"\n - checking if disabled..."
module_deny_fix
if [ "$l_mdir" = "/lib/modules/$(uname -r)/kernel/$l_mtype" ]; then
module_loadable_fix
module_loaded_fix
fi
else
echo -e "\n - module: \"$l_mname\" doesn't exist in \"$l_mdir\"\n"
fi
done
echo -e "\n - remediation of module: \"$l_mname\" complete\n"
}
audit_tmp_mount() {
echo "Auditing /tmp mount..."
findmnt -kn /tmp
}
# Function to check if systemd is correctly configured
audit_systemd_tmp_mount() {
echo "Checking systemd tmp.mount status..."
systemctl is-enabled tmp.mount
}
# Function to unmask and enable tmp.mount if needed
remediate_systemd_tmp_mount() {
echo "Ensuring systemd is configured to mount /tmp at boot time..."
# Unmask tmp.mount if it's masked
if systemctl is-enabled tmp.mount | grep -q "masked"; then
echo "tmp.mount is masked, unmasking..."
sudo systemctl unmask tmp.mount
fi
# Enable tmp.mount
echo "Enabling tmp.mount..."
sudo systemctl enable tmp.mount
}
# Main function to perform the audit and remediation
audit_noexec_option
echo "Audit and remediation complete."
#!/bin/bash
# Function to check if AppArmor is installed
check_apparmor_installed() {
echo "Checking if AppArmor is installed..."
# Check if AppArmor package is installed
if dpkg-query -s apparmor &>/dev/null; then
echo "AppArmor is already installed."
else
echo "AppArmor is not installed."
install_apparmor
fi
# Check if apparmor-utils package is installed
if dpkg-query -s apparmor-utils &>/dev/null; then
echo "AppArmor-utils is already installed."
else
echo "AppArmor-utils is not installed."
install_apparmor_utils
fi
}
# Function to install AppArmor
install_apparmor() {
echo "Installing AppArmor..."
sudo apt-get update
sudo apt-get install -y apparmor
}
# Function to install apparmor-utils
install_apparmor_utils() {
echo "Installing apparmor-utils..."
sudo apt-get install -y apparmor-utils
}
# Main function to perform the audit and remediation
check_apparmor_installed
echo "Audit and remediation complete."
#!/bin/bash
# Function to check if AppArmor boot parameters are set in grub.cfg
check_apparmor_enabled_in_bootloader() {
echo "Checking if AppArmor is enabled in bootloader configuration..."
# Check if apparmor=1 is present in the bootloader configuration
if grep -q "^\s*linux" /boot/grub/grub.cfg | grep -v "apparmor=1"; then
echo "AppArmor boot parameter 'apparmor=1' is missing."
enable_apparmor_in_bootloader
else
echo "AppArmor boot parameter 'apparmor=1' is correctly set."
fi
# Check if security=apparmor is present in the bootloader configuration
if grep -q "^\s*linux" /boot/grub/grub.cfg | grep -v "security=apparmor"; then
echo "AppArmor boot parameter 'security=apparmor' is missing."
enable_apparmor_in_bootloader
else
echo "AppArmor boot parameter 'security=apparmor' is correctly set."
fi
}
# Function to enable AppArmor in the bootloader configuration
enable_apparmor_in_bootloader() {
echo "Enabling AppArmor in the bootloader configuration..."
# Edit the GRUB_CMDLINE_LINUX line in /etc/default/grub to include apparmor=1 and security=apparmor
sudo sed -i 's/GRUB_CMDLINE_LINUX="\(.*\)"/GRUB_CMDLINE_LINUX="\1 apparmor=1 security=apparmor"/' /etc/default/grub
# Update GRUB configuration
sudo update-grub
echo "AppArmor parameters have been added to the bootloader configuration and GRUB has been updated."
}
# Main function to check and ensure AppArmor is enabled at boot time
check_apparmor_enabled_in_bootloader
echo "Audit and remediation complete."
#!/bin/bash
# Function to audit AppArmor profiles status
audit_apparmor_profiles() {
echo "Auditing AppArmor profiles..."
# Check if AppArmor profiles are loaded and in enforce or complain mode
profiles_status=$(apparmor_status | grep -i 'profiles')
# Ensure profiles are in either enforce or complain mode
enforce_count=$(echo "$profiles_status" | grep -o "enforce" | wc -l)
complain_count=$(echo "$profiles_status" | grep -o "complain" | wc -l)
# Check for unconfined processes
unconfined_processes=$(apparmor_status | grep "unconfined" | wc -l)
# Output profile status for auditing
echo "Profiles in enforce mode: $enforce_count"
echo "Profiles in complain mode: $complain_count"
echo "Unconfined processes: $unconfined_processes"
# If there are unconfined processes, print a message to take action
if [ "$unconfined_processes" -gt 0 ]; then
echo "Warning: There are unconfined processes that need attention."
fi
# Ensure there are no unconfined profiles (if any, need to create or activate)
if [ "$unconfined_processes" -gt 0 ]; then
echo "Please ensure that any unconfined processes have an AppArmor profile activated and restart them."
fi
# If all profiles are in enforce or complain mode and no unconfined processes, proceed with remediation
if [ "$unconfined_processes" -eq 0 ]; then
echo "All profiles are loaded and in enforce or complain mode."
else
echo "There are unconfined processes that require remediation."
fi
}
# Function to remediate by setting all profiles to enforce mode
remediate_apparmor_profiles() {
echo "Remediating AppArmor profiles..."
# Set all AppArmor profiles to enforce mode
echo "Setting all AppArmor profiles to enforce mode..."
sudo aa-enforce /etc/apparmor.d/*
# Verify after remediation
echo "Verifying AppArmor profiles status..."
apparmor_status | grep -i 'profiles'
}
# Function to remediate by setting all profiles to complain mode
set_profiles_to_complain() {
echo "Setting all AppArmor profiles to complain mode..."
# Set all AppArmor profiles to complain mode
sudo aa-complain /etc/apparmor.d/*
# Verify after remediation
echo "Verifying AppArmor profiles status..."
apparmor_status | grep -i 'profiles'
}
# Main function to perform audit and remediation
audit_apparmor_profiles
# Optionally remediate by setting profiles to enforce mode
remediate_apparmor_profiles
# Or set all profiles to complain mode instead (comment the above line to use this)
# set_profiles_to_complain
echo "Audit and remediation complete."
#!/bin/bash
# Function to audit AppArmor profiles status
audit_apparmor_profiles() {
echo "Auditing AppArmor profiles..."
# Check if AppArmor profiles are loaded and verify they are in enforce mode
profiles_status=$(apparmor_status | grep -i 'profiles')
# Count profiles in enforce mode and complain mode
enforce_count=$(echo "$profiles_status" | grep -o "enforce" | wc -l)
complain_count=$(echo "$profiles_status" | grep -o "complain" | wc -l)
# Check for unconfined processes
unconfined_processes=$(apparmor_status | grep "unconfined" | wc -l)
# Output profile status for auditing
echo "Profiles in enforce mode: $enforce_count"
echo "Profiles in complain mode: $complain_count"
echo "Unconfined processes: $unconfined_processes"
# If there are unconfined processes, print a message to take action
if [ "$unconfined_processes" -gt 0 ]; then
echo "Warning: There are unconfined processes that need attention."
fi
# Ensure there are no unconfined processes (if any, need to create or activate profiles)
if [ "$unconfined_processes" -gt 0 ]; then
echo "Please ensure that any unconfined processes have an AppArmor profile activated and restart them."
fi
# Check if all profiles are in enforce mode
if [ "$complain_count" -gt 0 ]; then
echo "Warning: There are profiles in complain mode. These should be set to enforce mode."
else
echo "All profiles are in enforce mode."
fi
}
# Function to remediate by setting all profiles to enforce mode
remediate_apparmor_profiles() {
echo "Remediating AppArmor profiles..."
# Set all AppArmor profiles to enforce mode
echo "Setting all AppArmor profiles to enforce mode..."
sudo aa-enforce /etc/apparmor.d/*
# Verify after remediation
echo "Verifying AppArmor profiles status..."
apparmor_status | grep -i 'profiles'
}
# Function to verify no unconfined processes are running
verify_no_unconfined_processes() {
echo "Verifying there are no unconfined processes..."
unconfined_processes=$(apparmor_status | grep "unconfined" | wc -l)
if [ "$unconfined_processes" -gt 0 ]; then
echo "There are unconfined processes that need to be addressed."
else
echo "No unconfined processes found."
fi
}
# Main function to perform audit and remediation
audit_apparmor_profiles
# Remediate by setting all profiles to enforce mode if needed
remediate_apparmor_profiles
# Verify there are no unconfined processes
verify_no_unconfined_processes
echo "Audit and remediation complete."
#!/bin/bash
#!/bin/bash
# Define the GRUB configuration file path
GRUB_CFG="/boot/grub/grub.cfg"
# Check if the GRUB configuration file exists
if [ ! -f "$GRUB_CFG" ]; then
echo "ERROR: GRUB configuration file '$GRUB_CFG' not found!"
fi
# Audit the current ownership and permissions of the GRUB configuration file
current_permissions=$(stat -c "%a" "$GRUB_CFG")
current_owner=$(stat -c "%U" "$GRUB_CFG")
current_group=$(stat -c "%G" "$GRUB_CFG")
echo "Current permissions of '$GRUB_CFG': $current_permissions"
echo "Current owner: $current_owner"
echo "Current group: $current_group"
# Check if the ownership is correct (root:root)
if [ "$current_owner" != "root" ] || [ "$current_group" != "root" ]; then
echo "Setting ownership to root:root for '$GRUB_CFG'..."
sudo chown root:root "$GRUB_CFG"
else
echo "Ownership is already correct."
fi
# Check if the permissions are correct (0600)
if [ "$current_permissions" != "600" ]; then
echo "Setting permissions to 0600 for '$GRUB_CFG'..."
sudo chmod 600 "$GRUB_CFG"
else
echo "Permissions are already set to 0600."
fi
# Verify the changes
echo "Updated permissions and ownership of '$GRUB_CFG':"
stat -c "Access: (%a) Uid: (%u/%U) Gid: (%g/%G)" "$GRUB_CFG"
#!/bin/bash
# Define the sysctl configuration file
SYSCTL_FILE="/etc/sysctl.d/60-kernel_sysctl.conf"
# Check if the configuration already exists
if ! grep -q "kernel.randomize_va_space = 2" "$SYSCTL_FILE"; then
echo "Setting kernel.randomize_va_space = 2 in $SYSCTL_FILE"
printf "%s\n" "kernel.randomize_va_space = 2" | sudo tee -a "$SYSCTL_FILE"
else
echo "kernel.randomize_va_space = 2 is already set in $SYSCTL_FILE"
fi
# Apply the setting immediately
echo "Applying kernel.randomize_va_space = 2"
sudo sysctl -w kernel.randomize_va_space=2
# Verify the setting
echo "Verifying kernel.randomize_va_space"
sysctl kernel.randomize_va_space
#!/bin/bash
# Define the sysctl configuration file
SYSCTL_FILE="/etc/sysctl.d/60-kernel_sysctl.conf"
# Check if the configuration already exists
if ! grep -q "kernel.yama.ptrace_scope = 1" "$SYSCTL_FILE"; then
echo "Setting kernel.yama.ptrace_scope = 1 in $SYSCTL_FILE"
printf "%s\n" "kernel.yama.ptrace_scope = 1" | sudo tee -a "$SYSCTL_FILE"
else
echo "kernel.yama.ptrace_scope = 1 is already set in $SYSCTL_FILE"
fi
# Apply the setting immediately
echo "Applying kernel.yama.ptrace_scope = 1"
sudo sysctl -w kernel.yama.ptrace_scope=1
# Verify the setting
echo "Verifying kernel.yama.ptrace_scope"
sysctl kernel.yama.ptrace_scope
#!/bin/bash
# Step 1: Set hard limit for core dumps
echo "Setting hard limit for core dumps..."
echo "* hard core 0" | sudo tee -a /etc/security/limits.d/60-security.conf
# Step 2: Set fs.suid_dumpable to 0
echo "Setting fs.suid_dumpable to 0..."
echo "fs.suid_dumpable = 0" | sudo tee -a /etc/sysctl.d/60-fs_sysctl.conf
sudo sysctl -w fs.suid_dumpable=0
# Step 3: Verify the system limits
echo "Verifying core dump limits..."
grep -Ps -- '^\h*\*\h+hard\h+core\h+0\b' /etc/security/limits.conf /etc/security/limits.d/*
# Step 4: Check if systemd-coredump is installed and disable if necessary
echo "Checking if systemd-coredump is installed..."
if systemctl list-unit-files | grep -q coredump; then
echo "Disabling systemd-coredump..."
echo -e "[Coredump]\nStorage=none\nProcessSizeMax=0" | sudo tee -a /etc/systemd/coredump.conf
sudo systemctl daemon-reload
else
echo "systemd-coredump is not installed or not enabled."
fi
# Final verification
echo "Final verification of kernel parameter fs.suid_dumpable..."
sysctl fs.suid_dumpable
#!/bin/bash
# Check if prelink is installed
if dpkg-query -s prelink &>/dev/null; then
echo "Prelink is installed, proceeding with remediation..."
# Restore binaries to their normal state
echo "Restoring binaries to normal state..."
sudo prelink -ua
# Uninstall prelink
echo "Uninstalling prelink..."
sudo apt purge -y prelink
# Verify prelink is no longer installed
if ! dpkg-query -s prelink &>/dev/null; then
echo "Prelink has been successfully removed from the system."
else
echo "Failed to remove prelink."
fi
else
echo "Prelink is not installed on this system."
fi
#!/bin/bash
# Check if Apport is installed and enabled
if dpkg-query -s apport &>/dev/null; then
echo "Apport is installed, checking if it is enabled..."
# Check if Apport is enabled
if grep -Pqi '^\h*enabled\h*=\h*[^0]\b' /etc/default/apport; then
echo "Apport is enabled, proceeding to disable it..."
# Disable Apport by modifying the /etc/default/apport file
sudo sed -i 's/^enabled=.*$/enabled=0/' /etc/default/apport
echo "Set 'enabled=0' in /etc/default/apport"
# Stop the Apport service
sudo systemctl stop apport.service
echo "Stopped Apport service"
# Mask the Apport service to prevent it from starting on boot
sudo systemctl mask apport.service
echo "Masked Apport service"
# Verify that Apport is now disabled
if ! systemctl is-active --quiet apport.service; then
echo "Apport service is successfully disabled."
else
echo "Failed to disable Apport service."
fi
else
echo "Apport is already disabled in /etc/default/apport."
fi
# Optionally, remove the Apport package (uncomment to use)
# sudo apt purge -y apport
# echo "Removed Apport package from the system."
else
echo "Apport is not installed on this system."
fi
#!/bin/bash
# Check if gdm3 is installed
if dpkg-query -s gdm3 &>/dev/null; then
echo "Removing gdm3..."
# Uninstall gdm3
sudo apt purge -y gdm3
# Remove unused dependencies
sudo apt autoremove -y
echo "gdm3 and unused dependencies have been removed."
else
echo "gdm3 is not installed, nothing to remove."
fi
# Optionally, prevent future installation of gdm3
# sudo apt-mark hold gdm3
#!/usr/bin/env bash
{
l_pkgoutput=""
if command -v dpkg-query &> /dev/null; then
l_pq="dpkg-query -s"
elif command -v rpm &> /dev/null; then
l_pq="rpm -q"
fi
l_pcl="gdm gdm3" # Space-separated list of packages to check
for l_pn in $l_pcl; do
$l_pq "$l_pn" &> /dev/null && l_pkgoutput="$l_pkgoutput\n - Package: \"$l_pn\" exists on the system\n - checking configuration"
done
if [ -n "$l_pkgoutput" ]; then
l_gdmprofile="gdm" # Set this to desired profile name
l_bmessage="'Authorized uses only. All activity may be monitored and reported.'" # Set desired banner message
# Create profile if it doesn't exist
if [ ! -f "/etc/dconf/profile/$l_gdmprofile" ]; then
echo "Creating profile \"$l_gdmprofile\""
echo -e "user-db:user\nsystem-db:$l_gdmprofile\nfiledb:/usr/share/$l_gdmprofile/greeter-dconf-defaults" > /etc/dconf/profile/$l_gdmprofile
fi
# Create dconf database directory if it doesn't exist
if [ ! -d "/etc/dconf/db/$l_gdmprofile.d/" ]; then
echo "Creating dconf database directory \"/etc/dconf/db/$l_gdmprofile.d/\""
mkdir /etc/dconf/db/$l_gdmprofile.d/
fi
# Enable the banner message
if ! grep -Piq '^\h*banner-message-enable\h*=\h*true\b' /etc/dconf/db/$l_gdmprofile.d/*; then
echo "Creating gdm keyfile for machine-wide settings"
l_kfile="/etc/dconf/db/$l_gdmprofile.d/01-banner-message"
echo -e "\n[org/gnome/login-screen]\nbanner-message-enable=true" >> "$l_kfile"
fi
# Set the banner message text
if ! grep -Piq "^\h*banner-message-text=[\'\"]+\S+" "$l_kfile"; then
sed -ri "/^\s*banner-message-enable/ a\banner-message-text=$l_bmessage" "$l_kfile"
fi
# Update the dconf database
dconf update
else
echo -e "\n\n - GNOME Desktop Manager isn't installed\n - Recommendation is Not Applicable\n - No remediation required\n"
fi
}
#!/usr/bin/env bash
{
l_gdmprofile="gdm" # Change this profile name if desired (according to local policy)
# Create the profile if it doesn't exist
if [ ! -f "/etc/dconf/profile/$l_gdmprofile" ]; then
echo "Creating profile \"$l_gdmprofile\""
echo -e "user-db:user\nsystem-db:$l_gdmprofile\nfiledb:/usr/share/$l_gdmprofile/greeter-dconf-defaults" > /etc/dconf/profile/$l_gdmprofile
fi
# Create the dconf database directory if it doesn't exist
if [ ! -d "/etc/dconf/db/$l_gdmprofile.d/" ]; then
echo "Creating dconf database directory \"/etc/dconf/db/$l_gdmprofile.d/\""
mkdir /etc/dconf/db/$l_gdmprofile.d/
fi
# Check if the 'disable-user-list' setting is already in place, otherwise add it
if ! grep -Piq '^\h*disable-user-list\h*=\h*true\b' /etc/dconf/db/$l_gdmprofile.d/*; then
echo "Creating gdm keyfile for machine-wide settings"
if ! grep -Piq -- '^\h*\[org/gnome/login-screen\]' /etc/dconf/db/$l_gdmprofile.d/*; then
echo -e "\n[org/gnome/login-screen]\n# Do not show the user list\ndisable-user-list=true" >> /etc/dconf/db/$l_gdmprofile.d/00-loginscreen
else
# Append the setting if the section exists
sed -ri '/^\s*\[org/gnome/login-screen\]/ a\# Do not show the user list\ndisable-user-list=true' $(grep -Pil -- '^\h*\[org/gnome/login-screen\]' /etc/dconf/db/$l_gdmprofile.d/*)
fi
fi
# Update the dconf database to apply changes
dconf update
}
#!/usr/bin/env bash
{
# Set lock-delay to 5 seconds and idle-delay to 900 seconds
gsettings set org.gnome.desktop.screensaver lock-delay 5
gsettings set org.gnome.desktop.session idle-delay 900
# Create or edit the user profile in /etc/dconf/profile/
l_dconf_profile="local" # Replace with appropriate profile name if different
if [ ! -f "/etc/dconf/profile/$l_dconf_profile" ]; then
echo "Creating profile \"$l_dconf_profile\""
echo -e "user-db:user\nsystem-db:$l_dconf_profile" > /etc/dconf/profile/$l_dconf_profile
fi
# Create the dconf database directory if it doesn't exist
if [ ! -d "/etc/dconf/db/$l_dconf_profile.d/" ]; then
echo "Creating dconf database directory \"/etc/dconf/db/$l_dconf_profile.d/\""
mkdir -p /etc/dconf/db/$l_dconf_profile.d/
fi
# Create the key file /etc/dconf/db/local.d/00-screensaver
if [ ! -f "/etc/dconf/db/$l_dconf_profile.d/00-screensaver" ]; then
echo "Creating screensaver key file"
echo -e "[org/gnome/desktop/session]\n# Number of seconds of inactivity before the screen goes blank\nidle-delay=uint32 180" > /etc/dconf/db/$l_dconf_profile.d/00-screensaver
echo -e "[org/gnome/desktop/screensaver]\n# Number of seconds after the screen is blank before locking the screen\nlock-delay=uint32 5" >> /etc/dconf/db/$l_dconf_profile.d/00-screensaver
fi
# Update dconf settings
dconf update
}
#!/usr/bin/env bash
{
# Create the locks directory if it doesn't exist
if [ ! -d "/etc/dconf/db/local.d/locks" ]; then
mkdir -p /etc/dconf/db/local.d/locks
fi
# Create the screensaver lockdown file
echo -e "# Lock desktop screensaver settings\n/org/gnome/desktop/session/idle-delay\n/org/gnome/desktop/screensaver/lock-delay" > /etc/dconf/db/local.d/locks/screensaver
# Update the system databases
dconf update
}
#!/usr/bin/env bash
{
l_pkgoutput=""
l_gpname="local" # Set to desired dconf profile name (default is local)
# Check if GNOME Desktop Manager is installed. If package isn't installed, recommendation is Not Applicable
if command -v dpkg-query > /dev/null 2>&1; then
l_pq="dpkg-query -s"
elif command -v rpm > /dev/null 2>&1; then
l_pq="rpm -q"
fi
# Check if GDM is installed
l_pcl="gdm gdm3" # Space-separated list of packages to check
for l_pn in $l_pcl; do
$l_pq "$l_pn" > /dev/null 2>&1 && l_pkgoutput="$l_pkgoutput\n - Package: \"$l_pn\" exists on the system\n - checking configuration"
done
# Check configuration (If applicable)
if [ -n "$l_pkgoutput" ]; then
echo -e "$l_pkgoutput"
# Look for existing settings and set variables if they exist
l_kfile="$(grep -Prils -- '^\h*automount\b' /etc/dconf/db/*.d)"
l_kfile2="$(grep -Prils -- '^\h*automount-open\b' /etc/dconf/db/*.d)"
# Set profile name based on dconf db directory ({PROFILE_NAME}.d)
if [ -f "$l_kfile" ]; then