-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraspberry_security_audit.py
More file actions
3184 lines (2840 loc) · 140 KB
/
raspberry_security_audit.py
File metadata and controls
3184 lines (2840 loc) · 140 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
#!/usr/bin/env python3
"""
Raspberry Pi Security Audit Script v1.0.0-PI - Multi-Framework Edition
COMPREHENSIVE security audit tool for Raspberry Pi OS
✓ 35+ Categories, 150+ Security Checks
- 136 standard Linux checks (SSH, firewall, users, files, kernel, etc.)
- 15+ Raspberry Pi-specific checks (default user, GPIO, VNC, Wi-Fi, etc.)
✓ Multi-Framework Compliance: CIS, NIST 800-53, DISA STIG, NSA, CISA, DoD
✓ 95%+ Automated Remediation with Interactive Fix Application
✓ Raspberry Pi Hardware Detection (auto-skips Pi checks on non-Pi systems)
✓ IoT Security Focus (wireless, remote access, interfaces)
✓ Framework Filtering & Per-Framework Compliance Scoring
✓ Professional Reports: Text, HTML, JSON, CSV
Raspberry Pi-Specific Features:
- Auto-detects Raspberry Pi hardware and model
- Checks default 'pi' user security (CAT I critical)
- GPIO/I2C/SPI/Camera interface security
- Wi-Fi/Bluetooth/VNC security (CAT I critical)
- Boot configuration hardening
- Serial console security
- Firmware update checks
- SD card optimizations
Supported Systems:
- Raspberry Pi 5, 4, 3, 2, Zero 2 W (all models)
- Raspberry Pi OS (32-bit and 64-bit)
- Debian-based distributions on Raspberry Pi
Framework Coverage:
- CIS Benchmark (42 scored + unscored checks)
- NIST 800-53 (40+ control mappings)
- DISA STIG (42+ finding IDs, CAT I/II/III - adapted for Pi)
- NSA Hardening Guide (41+ requirements)
- CISA Best Practices (33+ priority checks)
- Raspberry Pi Security Best Practices (15+ Pi-specific)
For: Raspberry Pi OS (Bookworm, Bullseye), compatible with all Pi models
Version: 1.0.0-PI
License: MIT
Based on: linux_security_audit.py (https://github.com/Sandler73/Linux-Security-Audit-and-Remediation-Script)
"""
import os
import sys
import subprocess
import pwd
import grp
import re
from datetime import datetime
from pathlib import Path
import json
import tempfile
import shutil
import time
import argparse
from io import StringIO
import csv
VERSION = "1.0.0-PI"
# ============================================================================
# COMPREHENSIVE MULTI-FRAMEWORK COMPLIANCE MAPPING
# Every check mapped to: CIS ID, NIST controls, DISA STIG ID, NSA flag, CISA flag, STIG category
# ============================================================================
FRAMEWORK_MAP = {
# ========== FILE PERMISSIONS (CIS 6.1.x, NIST AC-6, STIG CAT I/II) ==========
"/etc/passwd permissions": {
"cis": "6.1.2", "nist": ["AC-6", "CM-6"], "stig": "RHEL-07-020010",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"/etc/shadow permissions": {
"cis": "6.1.3", "nist": ["AC-6", "MP-2"], "stig": "RHEL-07-020020",
"nsa": True, "cisa": True, "cat": "CAT I", "level": 1, "scored": True
},
"/etc/group permissions": {
"cis": "6.1.4", "nist": ["AC-6"], "stig": "RHEL-07-020030",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"/etc/gshadow permissions": {
"cis": "6.1.5", "nist": ["AC-6"], "stig": "RHEL-07-020040",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"/etc/ssh/sshd_config permissions": {
"cis": "5.2.1", "nist": ["AC-6", "CM-6"], "stig": "RHEL-07-040420",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"/etc/passwd- permissions": {
"cis": "6.1.6", "nist": ["AC-6"], "stig": "RHEL-07-020010",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"/etc/shadow- permissions": {
"cis": "6.1.7", "nist": ["AC-6"], "stig": "RHEL-07-020020",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"/etc/group- permissions": {
"cis": "6.1.8", "nist": ["AC-6"], "stig": "RHEL-07-020030",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
# ========== USER ACCOUNTS - CRITICAL (CIS 6.2.x, NIST IA-x, STIG CAT I) ==========
"Empty Password Accounts": {
"cis": "6.2.1", "nist": ["IA-5"], "stig": "RHEL-07-010290",
"nsa": True, "cisa": True, "cat": "CAT I", "level": 1, "scored": True
},
"UID 0 Accounts": {
"cis": "6.2.5", "nist": ["AC-6", "IA-2"], "stig": "RHEL-07-020310",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"Password Max Days": {
"cis": "5.4.1.1", "nist": ["IA-5"], "stig": "RHEL-07-010250",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"Password Min Days": {
"cis": "5.4.1.2", "nist": ["IA-5"], "stig": "RHEL-07-010260",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"Password Warn Age": {
"cis": "5.4.1.3", "nist": ["IA-5"], "stig": "RHEL-07-010270",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 1, "scored": True
},
"Inactive Password Lock": {
"cis": "5.4.1.4", "nist": ["IA-5"], "stig": "RHEL-07-010310",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"Default UMASK": {
"cis": "5.4.4", "nist": ["AC-6"], "stig": "RHEL-07-020240",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"Root PATH Integrity": {
"cis": "6.2.6", "nist": ["CM-6"], "stig": "RHEL-07-020720",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
# ========== SSH CONFIGURATION - CRITICAL (CIS 5.2.x, STIG CAT I/II) ==========
"SSH Protocol": {
"cis": "5.2.1", "nist": ["SC-8"], "stig": "RHEL-07-040390",
"nsa": True, "cisa": True, "cat": "CAT I", "level": 1, "scored": True
},
"SSH LogLevel": {
"cis": "5.2.2", "nist": ["AU-3", "AU-12"], "stig": "RHEL-07-040460",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 1, "scored": True
},
"SSH X11Forwarding": {
"cis": "5.2.3", "nist": ["CM-7"], "stig": "RHEL-07-040710",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"SSH MaxAuthTries": {
"cis": "5.2.4", "nist": ["AC-7"], "stig": "RHEL-07-010430",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"SSH IgnoreRhosts": {
"cis": "5.2.5", "nist": ["AC-17", "CM-6"], "stig": "RHEL-07-040660",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"SSH HostbasedAuthentication": {
"cis": "5.2.6", "nist": ["IA-2", "AC-17"], "stig": "RHEL-07-010470",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"SSH PermitRootLogin": {
"cis": "5.2.7", "nist": ["AC-6", "IA-2"], "stig": "RHEL-07-040370",
"nsa": True, "cisa": True, "cat": "CAT I", "level": 1, "scored": True
},
"SSH PermitEmptyPasswords": {
"cis": "5.2.8", "nist": ["IA-5"], "stig": "RHEL-07-010290",
"nsa": True, "cisa": True, "cat": "CAT I", "level": 1, "scored": True
},
"SSH PermitUserEnvironment": {
"cis": "5.2.9", "nist": ["CM-6"], "stig": "RHEL-07-010460",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"SSH Ciphers": {
"cis": "5.2.11", "nist": ["SC-8", "SC-13"], "stig": "RHEL-07-040110",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"SSH MACs": {
"cis": "5.2.12", "nist": ["SC-8", "SC-13"], "stig": "RHEL-07-040400",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"SSH KexAlgorithms": {
"cis": "5.2.13", "nist": ["SC-8", "SC-13"], "stig": "RHEL-07-040440",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"SSH ClientAliveInterval": {
"cis": "5.2.14", "nist": ["AC-11", "SC-10"], "stig": "RHEL-07-040320",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"SSH LoginGraceTime": {
"cis": "5.2.15", "nist": ["AC-12"], "stig": "RHEL-07-040340",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 1, "scored": True
},
"SSH Banner": {
"cis": "5.2.16", "nist": ["AC-8"], "stig": "RHEL-07-040170",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
# ========== FIREWALL - CRITICAL (CIS 3.5.x, NIST SC-7, STIG CAT I) ==========
"UFW Status": {
"cis": "3.5.1.1", "nist": ["SC-7"], "stig": "RHEL-07-040520",
"nsa": True, "cisa": True, "cat": "CAT I", "level": 1, "scored": True
},
"UFW Enabled": {
"cis": "3.5.1.2", "nist": ["SC-7", "AC-4"], "stig": "RHEL-07-040520",
"nsa": True, "cisa": True, "cat": "CAT I", "level": 1, "scored": True
},
"UFW Default Deny": {
"cis": "3.5.1.7", "nist": ["SC-7"], "stig": "RHEL-07-040520",
"nsa": True, "cisa": True, "cat": "CAT I", "level": 1, "scored": True
},
# ========== KERNEL PARAMETERS (CIS 3.x, NIST SC-x, STIG CAT II) ==========
"IP Forwarding": {
"cis": "3.1.1", "nist": ["SC-7", "CM-6"], "stig": "RHEL-07-040740",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"Send Packet Redirects": {
"cis": "3.1.2", "nist": ["SC-7"], "stig": "RHEL-07-040660",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"ICMP Redirects": {
"cis": "3.2.2", "nist": ["SC-7"], "stig": "RHEL-07-040641",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"Secure ICMP Redirects": {
"cis": "3.2.3", "nist": ["SC-7"], "stig": "RHEL-07-040630",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"Log Suspicious Packets": {
"cis": "3.2.4", "nist": ["AU-12", "SI-4"], "stig": "RHEL-07-040680",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 1, "scored": True
},
"Ignore Broadcast Requests": {
"cis": "3.2.5", "nist": ["SC-5"], "stig": "RHEL-07-040630",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 1, "scored": True
},
"TCP SYN Cookies": {
"cis": "3.2.8", "nist": ["SC-5"], "stig": "RHEL-07-040820",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"IPv6 Router Advertisements": {
"cis": "3.2.9", "nist": ["CM-7"], "stig": "RHEL-07-040830",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"Randomize VA Space": {
"cis": "1.5.1", "nist": ["SI-16"], "stig": "RHEL-07-040201",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
# ========== FILESYSTEM (CIS 1.1.x, NIST CM-6, STIG CAT II) ==========
"/tmp nodev": {
"cis": "1.1.3", "nist": ["CM-6"], "stig": "RHEL-07-021020",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"/tmp nosuid": {
"cis": "1.1.4", "nist": ["CM-6"], "stig": "RHEL-07-021030",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"/tmp noexec": {
"cis": "1.1.5", "nist": ["CM-6"], "stig": "RHEL-07-021040",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"/tmp Mount Options": {
"cis": "1.1.3-5", "nist": ["CM-6"], "stig": "RHEL-07-021020",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"/tmp Sticky Bit": {
"cis": "1.1.21", "nist": ["AC-6"], "stig": "RHEL-07-021030",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"Separate /home Partition": {
"cis": "1.1.14", "nist": ["CM-6"], "stig": "N/A",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 2, "scored": True
},
"Separate /var Partition": {
"cis": "1.1.10", "nist": ["CM-6"], "stig": "N/A",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 2, "scored": True
},
# ========== LOGGING & AUDITING (CIS 4.x, NIST AU-x, STIG CAT II) ==========
"auditd Installation": {
"cis": "4.1.1.1", "nist": ["AU-2", "AU-12"], "stig": "RHEL-07-030000",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 2, "scored": True
},
"auditd Service Enabled": {
"cis": "4.1.1.2", "nist": ["AU-12"], "stig": "RHEL-07-030010",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 2, "scored": True
},
"auditd Service Running": {
"cis": "4.1.1.3", "nist": ["AU-12"], "stig": "RHEL-07-030010",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 2, "scored": True
},
"rsyslog Service": {
"cis": "4.2.1.1", "nist": ["AU-4", "AU-9"], "stig": "RHEL-07-031000",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"rsyslog Enabled": {
"cis": "4.2.1.2", "nist": ["AU-4"], "stig": "RHEL-07-031010",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
# ========== SYSTEM HARDENING (CIS 1.x, NIST AC-6/SI-x, STIG CAT II) ==========
"AppArmor Status": {
"cis": "1.6.1.1", "nist": ["AC-6", "CM-6"], "stig": "RHEL-07-020210",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"AppArmor Enabled": {
"cis": "1.6.1.2", "nist": ["AC-6"], "stig": "RHEL-07-020220",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"Core Dumps Restricted": {
"cis": "1.5.1", "nist": ["SI-11"], "stig": "RHEL-07-010480",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"SUID Core Dumps": {
"cis": "1.5.1", "nist": ["SI-11"], "stig": "RHEL-07-010480",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"AIDE Installed": {
"cis": "1.3.1", "nist": ["CM-3", "CM-6", "SI-7"], "stig": "RHEL-07-020030",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"AIDE Initialized": {
"cis": "1.3.2", "nist": ["SI-7"], "stig": "RHEL-07-020040",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
# ========== NETWORK HARDENING (CIS 3.x, NIST SC-7, STIG CAT III) ==========
"TCP Wrappers Installed": {
"cis": "3.4.1", "nist": ["SC-7"], "stig": "RHEL-07-040810",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 1, "scored": True
},
"/etc/hosts.allow configured": {
"cis": "3.4.2", "nist": ["SC-7"], "stig": "RHEL-07-040810",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 1, "scored": True
},
"/etc/hosts.deny configured": {
"cis": "3.4.3", "nist": ["SC-7"], "stig": "RHEL-07-040810",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 1, "scored": True
},
# ========== CRON & ACCESS CONTROL (CIS 5.1.x, NIST AC-6, STIG CAT II/III) ==========
"Cron Daemon Enabled": {
"cis": "5.1.1", "nist": ["CM-6"], "stig": "RHEL-07-021100",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 1, "scored": True
},
"Cron Access Control": {
"cis": "5.1.8", "nist": ["AC-6", "CM-6"], "stig": "RHEL-07-021110",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
# ========== BOOTLOADER (CIS 1.4.x, NIST AC-3, STIG CAT II) ==========
"GRUB Password Protection": {
"cis": "1.4.2", "nist": ["AC-3"], "stig": "RHEL-07-010480",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"/boot/grub/grub.cfg permissions": {
"cis": "1.4.1", "nist": ["AC-6"], "stig": "RHEL-07-010480",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
# ========== SYSTEM MAINTENANCE (CIS 1.x/6.x, NIST SI-2, STIG CAT II) ==========
"Available System Updates": {
"cis": "1.9", "nist": ["SI-2"], "stig": "RHEL-07-020260",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": False
},
"Automatic Security Updates": {
"cis": "1.9", "nist": ["SI-2"], "stig": "RHEL-07-020260",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"World Writable Files": {
"cis": "6.1.10", "nist": ["AC-6"], "stig": "RHEL-07-020270",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"Unowned Files": {
"cis": "6.1.11", "nist": ["AC-6"], "stig": "RHEL-07-020280",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"Ungrouped Files": {
"cis": "6.1.12", "nist": ["AC-6"], "stig": "RHEL-07-020290",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"SUID System Executables": {
"cis": "6.1.13", "nist": ["CM-6"], "stig": "RHEL-07-020240",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": False
},
"SGID System Executables": {
"cis": "6.1.14", "nist": ["CM-6"], "stig": "RHEL-07-020250",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": False
},
# ========== SUDO CONFIGURATION (CIS 5.3.x, NIST AU-3/CM-6, STIG CAT III) ==========
"Sudo Log File": {
"cis": "5.3.3", "nist": ["AU-3"], "stig": "RHEL-07-030670",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 1, "scored": True
},
"Sudo use_pty": {
"cis": "5.3.2", "nist": ["CM-6"], "stig": "RHEL-07-030680",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 1, "scored": True
},
# ========== BANNERS (CIS 1.7.x, NIST AC-8, STIG CAT III) ==========
"/etc/issue": {
"cis": "1.7.1.1", "nist": ["AC-8"], "stig": "RHEL-07-010030",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 1, "scored": True
},
"/etc/issue.net": {
"cis": "1.7.1.2", "nist": ["AC-8"], "stig": "RHEL-07-010040",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 1, "scored": True
},
# ========== EXTENDED AUDIT - PASSWORD COMPLEXITY (CIS 5.3.1, NIST IA-5(1), STIG CAT II) ==========
"Password Minimum Length": {
"cis": "5.3.1", "nist": ["IA-5(1)"], "stig": "RHEL-07-010280",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"Password Complexity - Digits": {
"cis": "5.3.1", "nist": ["IA-5(1)"], "stig": "RHEL-07-010170",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"Password Complexity - Uppercase": {
"cis": "5.3.1", "nist": ["IA-5(1)"], "stig": "RHEL-07-010180",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"Password Complexity - Lowercase": {
"cis": "5.3.1", "nist": ["IA-5(1)"], "stig": "RHEL-07-010190",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"Password Complexity - Special": {
"cis": "5.3.1", "nist": ["IA-5(1)"], "stig": "RHEL-07-010200",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
# ========== EXTENDED AUDIT - ACCOUNT LOCKOUT (CIS 5.3.2, NIST AC-7, STIG CAT II) ==========
"Account Lockout - Deny": {
"cis": "5.3.2", "nist": ["AC-7"], "stig": "RHEL-07-010320",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"Account Lockout - Unlock Time": {
"cis": "5.3.2", "nist": ["AC-7"], "stig": "RHEL-07-010320",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
# ========== EXTENDED AUDIT - TIME SYNC (CIS 2.2.1.1, NIST AU-8, STIG CAT II) ==========
"Time Synchronization Service": {
"cis": "2.2.1.1", "nist": ["AU-8"], "stig": "RHEL-07-040500",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"Time Synchronization Running": {
"cis": "2.2.1.2", "nist": ["AU-8"], "stig": "RHEL-07-040500",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
# ========== EXTENDED AUDIT - USB/HARDWARE (NIST MP-7, STIG CAT II) ==========
"USB Storage Disabled": {
"cis": "N/A", "nist": ["MP-7"], "stig": "RHEL-07-021700",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
# ========== EXTENDED AUDIT - SSH KEYS (CIS 5.2.x, NIST SC-13, STIG CAT II) ==========
"SSH Private Key Permissions": {
"cis": "N/A", "nist": ["SC-13"], "stig": "RHEL-07-040270",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"SSH authorized_keys Permissions": {
"cis": "N/A", "nist": ["SC-13"], "stig": "RHEL-07-040280",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
# ========== HOME DIRECTORY SECURITY (CIS 6.2.x, NIST AC-6, STIG CAT II) ==========
"Home Directory Permissions": {
"cis": "6.2.7", "nist": ["AC-6"], "stig": "RHEL-07-020630",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"Home Directory Ownership": {
"cis": "6.2.8", "nist": ["AC-6"], "stig": "RHEL-07-020640",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
".forward Files": {
"cis": "6.2.10", "nist": ["CM-6"], "stig": "RHEL-07-020710",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
".netrc Files": {
"cis": "6.2.11", "nist": ["CM-6"], "stig": "RHEL-07-020700",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
".rhosts Files": {
"cis": "6.2.12", "nist": ["CM-6"], "stig": "RHEL-07-020690",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
# ========== RASPBERRY PI SPECIFIC CHECKS ==========
"Default Pi User Security": {
"cis": "5.4.2", "nist": ["IA-5", "AC-6"], "stig": "N/A",
"nsa": True, "cisa": True, "cat": "CAT I", "level": 1, "scored": True
},
"Pi Boot Config Permissions": {
"cis": "1.4.1", "nist": ["AC-6"], "stig": "N/A",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"Pi Boot Cmdline Permissions": {
"cis": "1.4.1", "nist": ["AC-6"], "stig": "N/A",
"nsa": True, "cisa": False, "cat": "CAT II", "level": 1, "scored": True
},
"GPIO Permissions": {
"cis": "N/A", "nist": ["AC-6"], "stig": "N/A",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 2, "scored": False
},
"Camera Interface Security": {
"cis": "N/A", "nist": ["AC-6", "CM-7"], "stig": "N/A",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 2, "scored": False
},
"I2C Interface Security": {
"cis": "N/A", "nist": ["CM-7"], "stig": "N/A",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 2, "scored": False
},
"SPI Interface Security": {
"cis": "N/A", "nist": ["CM-7"], "stig": "N/A",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 2, "scored": False
},
"Serial Console Security": {
"cis": "N/A", "nist": ["AC-17"], "stig": "N/A",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"Wi-Fi Security Configuration": {
"cis": "N/A", "nist": ["SC-8", "SC-13"], "stig": "N/A",
"nsa": True, "cisa": True, "cat": "CAT I", "level": 1, "scored": True
},
"Bluetooth Security": {
"cis": "N/A", "nist": ["CM-7", "AC-18"], "stig": "N/A",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"VNC Server Security": {
"cis": "N/A", "nist": ["SC-8", "IA-5", "AC-17"], "stig": "N/A",
"nsa": True, "cisa": True, "cat": "CAT I", "level": 1, "scored": True
},
"Avahi/mDNS Service": {
"cis": "2.2.x", "nist": ["CM-7"], "stig": "N/A",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 2, "scored": False
},
"Default Hostname Changed": {
"cis": "N/A", "nist": ["IA-4"], "stig": "N/A",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 2, "scored": False
},
"Raspberry Pi Firmware Updates": {
"cis": "1.9", "nist": ["SI-2"], "stig": "N/A",
"nsa": True, "cisa": True, "cat": "CAT II", "level": 1, "scored": True
},
"SD Card Security": {
"cis": "N/A", "nist": ["MP-2"], "stig": "N/A",
"nsa": True, "cisa": False, "cat": "CAT III", "level": 2, "scored": False
},
}
def get_framework_info(check_name):
"""Get comprehensive framework information for a check"""
return FRAMEWORK_MAP.get(check_name, {
"cis": "N/A", "nist": [], "stig": "N/A",
"nsa": False, "cisa": False, "cat": "CAT III",
"level": 1, "scored": False
})
def format_framework_ids(info):
"""Format framework IDs for display"""
ids = []
if info["cis"] != "N/A":
ids.append(f"CIS {info['cis']}")
if info["nist"]:
nist_str = ','.join(info['nist'])
ids.append(f"NIST {nist_str}")
if info["stig"] != "N/A":
ids.append(f"STIG {info['stig']}")
if info["nsa"]:
ids.append("NSA ✓")
if info["cisa"]:
ids.append("CISA ✓")
return " | ".join(ids) if ids else "N/A"
class SecurityAudit:
def __init__(self):
self.results = []
self.timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
self.timestamp_file = datetime.now().strftime("%Y%m%d_%H%M%S")
self.hostname = subprocess.run(['hostname'], capture_output=True, text=True).stdout.strip()
self.is_root = os.geteuid() == 0
self.filter_args = None
def check_root(self):
"""Verify script is running with appropriate privileges"""
if not self.is_root:
print("WARNING: This script should be run as root for complete results.")
print("Some checks will be skipped without root privileges.\n")
return False
return True
def add_result(self, category, check_name, status, current_value, expected_value,
recommendation, severity="Medium", fix_commands=None, special_fix_data=None):
"""Add a check result with comprehensive multi-framework information"""
info = get_framework_info(check_name)
self.results.append({
'Category': category,
'Check': check_name,
'CIS_ID': info["cis"],
'NIST_Controls': info["nist"],
'STIG_ID': info["stig"],
'NSA': info["nsa"],
'CISA': info["cisa"],
'STIG_Cat': info["cat"],
'CIS_Level': info["level"],
'CIS_Scored': 'Scored' if info["scored"] else 'Not Scored',
'Status': status,
'Current Value': str(current_value),
'Expected Value': str(expected_value),
'Recommendation': recommendation,
'Severity': severity,
'FrameworkIDs': format_framework_ids(info),
'FixCommands': fix_commands or [],
'SpecialFixData': special_fix_data
})
def run_command(self, command, shell=False):
"""Execute a system command and return output"""
try:
if isinstance(command, str) and not shell:
command = command.split()
result = subprocess.run(command, capture_output=True, text=True, shell=shell, timeout=10)
return result.stdout.strip(), result.returncode
except subprocess.TimeoutExpired:
return "", -1
except Exception as e:
return str(e), -1
def file_exists(self, filepath):
"""Check if file exists"""
return os.path.exists(filepath)
def get_file_permissions(self, filepath):
"""Get file permissions in octal format (last 3 digits only)"""
try:
return oct(os.stat(filepath).st_mode)[-3:]
except:
return None
def fix_tmp_mount_options(self, missing_opts):
"""Fix /tmp mount options - called during interactive remediation"""
print(f" Applying fix for /tmp mount options...")
# Determine which approach to use
fstab_check, _ = self.run_command("grep -E '^[^#].*[[:space:]]/tmp[[:space:]]' /etc/fstab", shell=True)
systemd_check, _ = self.run_command("systemctl status tmp.mount 2>/dev/null", shell=True)
if 'tmp.mount' in systemd_check:
# Use systemd approach
print(f" Detected systemd-managed /tmp, creating override...")
try:
# Create directory
os.makedirs('/etc/systemd/system/tmp.mount.d', exist_ok=True)
# Write configuration file
config_file = '/etc/systemd/system/tmp.mount.d/options.conf'
with open(config_file, 'w') as f:
f.write('[Mount]\n')
f.write('Options=mode=1777,strictatime,nodev,nosuid,noexec\n')
print(f" Created {config_file}")
# Reload systemd
print(f" Reloading systemd...")
_, rc = self.run_command("systemctl daemon-reload")
if rc != 0:
print(f" ⚠ Warning: systemctl daemon-reload returned {rc}")
return False
# Restart tmp.mount
print(f" Restarting tmp.mount...")
_, rc = self.run_command("systemctl restart tmp.mount")
if rc != 0:
print(f" ⚠ Warning: systemctl restart tmp.mount returned {rc}")
return False
# Verify
output, _ = self.run_command("mount | grep '/tmp'")
if all(opt in output for opt in ['nodev', 'nosuid', 'noexec']):
print(f" ✓ All mount options applied successfully")
return True
else:
print(f" ⚠ Warning: Some options may not have been applied")
print(f" Current mount: {output}")
return False
except Exception as e:
print(f" ✗ Error: {e}")
return False
elif fstab_check:
# Manual edit required for fstab
print(f" /tmp is configured in /etc/fstab")
print(f" Current line: {fstab_check}")
print(f" ")
print(f" MANUAL ACTION REQUIRED:")
print(f" 1. Edit /etc/fstab: sudo nano /etc/fstab")
print(f" 2. Find the /tmp line and add: nodev,nosuid,noexec to options")
print(f" 3. Save and run: sudo mount -o remount /tmp")
print(f" ")
return False # Manual action required
else:
# No existing /tmp mount, add to fstab
print(f" No existing /tmp mount found, adding to /etc/fstab...")
try:
# Backup fstab
import shutil
from datetime import datetime
backup_file = f"/etc/fstab.backup.{datetime.now().strftime('%Y%m%d_%H%M%S')}"
shutil.copy2('/etc/fstab', backup_file)
print(f" Backed up /etc/fstab to {backup_file}")
# Add tmpfs entry
with open('/etc/fstab', 'a') as f:
f.write('\n# Secure /tmp mount added by security audit\n')
f.write('tmpfs /tmp tmpfs defaults,nodev,nosuid,noexec,mode=1777 0 0\n')
print(f" Added tmpfs entry to /etc/fstab")
# Remount
print(f" Remounting /tmp...")
_, rc = self.run_command("mount -o remount /tmp")
if rc != 0:
print(f" ⚠ Warning: Remount may have failed, try: sudo mount -a")
return False
# Verify
output, _ = self.run_command("mount | grep '/tmp'")
if all(opt in output for opt in ['nodev', 'nosuid', 'noexec']):
print(f" ✓ All mount options applied successfully")
return True
else:
print(f" ⚠ Warning: Options may require reboot to take effect")
return False
except Exception as e:
print(f" ✗ Error: {e}")
return False
def get_file_permissions_full(self, filepath):
"""Get full file permissions in octal format (including sticky/setuid/setgid bits)"""
try:
return oct(os.stat(filepath).st_mode)[-4:]
except:
return None
def get_file_owner(self, filepath):
"""Get file owner"""
try:
stat_info = os.stat(filepath)
return pwd.getpwuid(stat_info.st_uid).pw_name
except:
return None
def get_file_group(self, filepath):
"""Get file group"""
try:
stat_info = os.stat(filepath)
return grp.getgrgid(stat_info.st_gid).gr_name
except:
return None
# ============================================================================
# CATEGORY 1: FILE PERMISSIONS AND OWNERSHIP
# ============================================================================
def check_file_permissions(self):
"""Check permissions on critical system files"""
category = "File Permissions"
critical_files = {
'/etc/passwd': {'perms': '644', 'owner': 'root', 'group': 'root'},
'/etc/shadow': {'perms': '640', 'owner': 'root', 'group': 'shadow'},
'/etc/group': {'perms': '644', 'owner': 'root', 'group': 'root'},
'/etc/gshadow': {'perms': '640', 'owner': 'root', 'group': 'shadow'},
'/etc/ssh/sshd_config': {'perms': '600', 'owner': 'root', 'group': 'root'},
'/boot/grub/grub.cfg': {'perms': '600', 'owner': 'root', 'group': 'root'},
}
for filepath, expected in critical_files.items():
if not self.file_exists(filepath):
self.add_result(category, f"File Exists: {filepath}", "INFO",
"Not Found", "Should Exist",
f"File {filepath} not found on this system", "Low")
continue
# Check permissions
current_perms = self.get_file_permissions(filepath)
if current_perms != expected['perms']:
self.add_result(category, f"Permissions: {filepath}", "FAIL",
current_perms, expected['perms'],
f"chmod {expected['perms']} {filepath}", "High",
fix_commands=[f"chmod {expected['perms']} {filepath}"])
else:
self.add_result(category, f"Permissions: {filepath}", "PASS",
current_perms, expected['perms'], "No action needed", "High")
# Check ownership
current_owner = self.get_file_owner(filepath)
if current_owner != expected['owner']:
self.add_result(category, f"Owner: {filepath}", "FAIL",
current_owner, expected['owner'],
f"chown {expected['owner']} {filepath}", "High",
fix_commands=[f"chown {expected['owner']} {filepath}"])
else:
self.add_result(category, f"Owner: {filepath}", "PASS",
current_owner, expected['owner'], "No action needed", "High")
# Check group
current_group = self.get_file_group(filepath)
if current_group != expected['group']:
self.add_result(category, f"Group: {filepath}", "FAIL",
current_group, expected['group'],
f"chgrp {expected['group']} {filepath}", "High",
fix_commands=[f"chgrp {expected['group']} {filepath}"])
else:
self.add_result(category, f"Group: {filepath}", "PASS",
current_group, expected['group'], "No action needed", "High")
# ============================================================================
# CATEGORY 2: USER ACCOUNTS AND PASSWORD POLICIES
# ============================================================================
def check_user_accounts(self):
"""Check user account configurations"""
category = "User Accounts"
# Check for users with UID 0 (should only be root)
output, _ = self.run_command("awk -F: '($3 == 0) {print $1}' /etc/passwd", shell=True)
uid_zero_users = output.split('\n') if output else []
if len(uid_zero_users) > 1 or (len(uid_zero_users) == 1 and uid_zero_users[0] != 'root'):
self.add_result(category, "UID 0 Accounts", "FAIL",
', '.join(uid_zero_users), "root only",
"Remove UID 0 from non-root accounts", "Critical")
else:
self.add_result(category, "UID 0 Accounts", "PASS",
"root only", "root only", "No action needed", "Critical")
# Check for accounts with empty passwords
if self.is_root:
output, _ = self.run_command("awk -F: '($2 == \"\") {print $1}' /etc/shadow", shell=True)
empty_pass_users = [u for u in output.split('\n') if u]
if empty_pass_users:
fix_cmds = [f"passwd -l {user}" for user in empty_pass_users]
self.add_result(category, "Empty Password Accounts", "FAIL",
', '.join(empty_pass_users), "None",
"Lock or set passwords for these accounts", "Critical",
fix_commands=fix_cmds)
else:
self.add_result(category, "Empty Password Accounts", "PASS",
"None found", "None", "No action needed", "Critical")
# Check password aging in login.defs
if self.file_exists('/etc/login.defs'):
output, _ = self.run_command("grep '^PASS_MAX_DAYS' /etc/login.defs", shell=True)
if output:
max_days = output.split()[-1]
if int(max_days) > 90:
self.add_result(category, "Password Max Age", "FAIL",
max_days, "90 or less",
"Edit /etc/login.defs and set PASS_MAX_DAYS to 90", "Medium",
fix_commands=["sed -i 's/^PASS_MAX_DAYS.*/PASS_MAX_DAYS 90/' /etc/login.defs"])
else:
self.add_result(category, "Password Max Age", "PASS",
max_days, "90 or less", "No action needed", "Medium")
output, _ = self.run_command("grep '^PASS_MIN_DAYS' /etc/login.defs", shell=True)
if output:
min_days = output.split()[-1]
if int(min_days) < 1:
self.add_result(category, "Password Min Age", "FAIL",
min_days, "1 or more",
"Edit /etc/login.defs and set PASS_MIN_DAYS to 1", "Medium",
fix_commands=["sed -i 's/^PASS_MIN_DAYS.*/PASS_MIN_DAYS 1/' /etc/login.defs"])
else:
self.add_result(category, "Password Min Age", "PASS",
min_days, "1 or more", "No action needed", "Medium")
# Check UMASK
output, _ = self.run_command("grep '^UMASK' /etc/login.defs", shell=True)
if output:
umask = output.split()[-1]
if umask != '027':
self.add_result(category, "Default UMASK", "FAIL",
umask, "027",
"Set UMASK to 027 in /etc/login.defs", "Medium",
fix_commands=["sed -i 's/^UMASK.*/UMASK 027/' /etc/login.defs"])
else:
self.add_result(category, "Default UMASK", "PASS",
umask, "027", "No action needed", "Medium")
# ============================================================================
# CATEGORY 3: SSH CONFIGURATION
# ============================================================================
def check_ssh_config(self):
"""Check SSH daemon configuration"""
category = "SSH Configuration"
ssh_config = "/etc/ssh/sshd_config"
if not self.file_exists(ssh_config):
self.add_result(category, "SSH Config File", "INFO",
"Not Found", "Should Exist",
"SSH server may not be installed", "Low")
return
ssh_checks = {
'PermitRootLogin': {'expected': 'no', 'severity': 'Critical'},
'PasswordAuthentication': {'expected': 'no', 'severity': 'High'},
'PermitEmptyPasswords': {'expected': 'no', 'severity': 'Critical'},
'X11Forwarding': {'expected': 'no', 'severity': 'Medium'},
'MaxAuthTries': {'expected': '4', 'severity': 'Medium'},
'Protocol': {'expected': '2', 'severity': 'High'},
}
for setting, config in ssh_checks.items():
# Try to find the setting (uncommented)
output, _ = self.run_command(f"grep -E '^{setting}' {ssh_config}", shell=True)
if not output:
# Setting not found - use sed to add it at the end
fix_cmds = [
f"sed -i '$ a\\{setting} {config['expected']}' {ssh_config}",
"systemctl restart sshd"
]
self.add_result(category, f"SSH {setting}", "FAIL",
"Not explicitly set (using default)",
config['expected'],
f"Add '{setting} {config['expected']}' to {ssh_config}",
config['severity'],
fix_commands=fix_cmds)
else:
current_value = output.split()[-1].lower()
expected_value = config['expected'].lower()
if current_value == expected_value:
self.add_result(category, f"SSH {setting}", "PASS",
current_value, expected_value,
"No action needed", config['severity'])
else:
fix_cmd = f"sed -i 's/^{setting}.*/{setting} {config['expected']}/' {ssh_config}"
self.add_result(category, f"SSH {setting}", "FAIL",
current_value, expected_value,
f"Change {setting} to {config['expected']} in {ssh_config}",
config['severity'],
fix_commands=[fix_cmd, "systemctl restart sshd"])
# ============================================================================
# CATEGORY 4: FIREWALL CONFIGURATION
# ============================================================================
def check_firewall(self):
"""Check firewall configuration"""
category = "Firewall"
# Check if UFW is installed and active
output, returncode = self.run_command("which ufw")
if returncode == 0:
output, _ = self.run_command("ufw status")
if "Status: active" in output:
self.add_result(category, "UFW Status", "PASS",
"Active", "Active",
"No action needed", "High")
else:
self.add_result(category, "UFW Status", "FAIL",
"Inactive", "Active",
"Enable UFW: sudo ufw enable", "High",
fix_commands=["ufw --force enable"])
else:
# Check iptables
output, returncode = self.run_command("iptables -L -n")
if returncode == 0:
rules_count = len([l for l in output.split('\n') if l and not l.startswith('Chain') and not l.startswith('target')])
if rules_count > 0:
self.add_result(category, "Firewall (iptables)", "PASS",
f"{rules_count} rules configured", "Rules present",
"Review iptables rules for correctness", "High")
else:
self.add_result(category, "Firewall (iptables)", "FAIL",
"No rules configured", "Rules should be configured",
"Configure iptables or install UFW", "High",
fix_commands=["apt-get install -y ufw", "ufw --force enable"])
# ============================================================================
# CATEGORY 5: KERNEL PARAMETERS (sysctl)
# ============================================================================
def check_kernel_parameters(self):
"""Check kernel security parameters"""
category = "Kernel Parameters"