-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathlunar.sh
executable file
·1646 lines (1535 loc) · 38 KB
/
lunar.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/sh -eu
# shellcheck disable=SC2034
# shellcheck disable=SC1090
# Name: lunar (Lockdown UNix Auditing and Reporting)
# Version: 10.0.8
# Release: 1
# License: CC-BA (Creative Commons By Attribution)
# http://creativecommons.org/licenses/by/4.0/legalcode
# Group: System
# Source: N/A
# URL: http://lateralblast.com.au/
# Distribution: Solaris, Red Hat Linux, SuSE Linux, Debian Linux,
# Ubuntu Linux, Mac OS X, AIX, FreeBSD, ESXi
# Vendor: UNIX
# Packager: Richard Spindler <[email protected]>
# Description: Audit script based on various benchmarks
# Addition improvements added
# Written in bourne shell so it can be run on different releases
# No warranty is implied or given with this script
# It is based on numerous security guidelines
# As with any system changes, the script should be vetted and
# changed to suit the environment in which it is being used
# Unless your organization is specifically using the service, disable it.
# The best defense against a service being exploited is to disable it.
# Even if a service is set to off the script will audit the configuration
# file so that if a service is re-enabled the configuration is secure
# Where possible checks are made to make sure the package is installed
# if the package is not installed the checks will not be run
# To do:
#
# - nosuid,noexec for Linux
# - Disable user mounted removable filesystems for Linux
# - Disable USB devices for Linux
# - Grub password
# - Restrict NFS client requests to privileged ports Linux
# Solaris Release Information
# 1/06 U1
# 6/06 U2
# 11/06 U3
# 8/07 U4
# 5/08 U5
# 10/08 U6
# 5/09 U7
# 10/09 U8
# 9/10 U9
# 8/11 U10
# 1/13 U11
# audit_mode = 1 : Audit Mode
# audit_mode = 0 : Lockdown Mode
# audit_mode = 2 : Restore Mode
# Defaults for AWS
aws_iam_master_role="iam-master"
aws_iam_manager_role="iam-manager"
aws_cloud_trail_name="aws-audit-log"
sns_protocol="email"
sns_endpoint="[email protected]"
valid_tag_string="(ue1|uw1|uw2|ew1|ec1|an1|an2|as1|as2|se1)-(d|t|s|p)-([a-z0-9\-]+)$"
strict_valid_names="y"
check_volattach="y"
check_voltype="y"
check_snapage="y"
aws_region=""
aws_rds_min_retention="7"
aws_ec2_min_retention="7"
aws_ec2_max_retention="30"
aws_days_to_key_deletion="7"
# Defaults for MacOS
keychain_sync="1"
disable_airdrop="1"
asset_cache="false"
wifi_status="2"
touchid_timeout="86400"
# Set up some global variables/defaults
app_dir=$( dirname "$0" )
args="*@"
secure=0
insecure=0
total=0
syslog_server=""
syslog_logdir=""
pkg_suffix="lunar"
base_dir="/var/log/$pkg_suffix"
temp_dir="$base_dir/tmp"
date_suffix=$( date +%d_%m_%Y_%H_%M_%S )
temp_file="$temp_dir/$pkg_suffix.tmp"
work_dir="$base_dir/$date_suffix"
wheel_group="wheel"
docker_group="docker"
reboot=0
verbose=0
ansible=0
functions_dir="$app_dir/functions"
modules_dir="$app_dir/modules"
private_dir="$app_dir/private"
package_uninstall="no"
country_suffix="au"
language_suffix="en_US"
osx_mdns_enable="yes"
max_super_user_id="100"
use_expr="no"
use_finger="yes"
test_os="none"
test_tag="none"
action="none"
do_compose=0
do_multipass=0
do_shell=0
do_remote=0
my_id=$(id -u)
tcpd_allow="sshd"
ssh_protocol="2"
ssh_key_size="4096"
do_audit=0
do_fs=0
audit_mode=1
audit_type="local"
git_url="https://github.com/lateralblast/lunar.git"
password_hashing="sha512"
anacron_enable="no"
ssh_sandbox="yes"
do_debug=0
do_select=0
function=""
no_cat=0
# Disable daemons
nfsd_disable="yes"
snmpd_disable="yes"
dhcpcd_disable="yes"
dhcprd_disable="yes"
dhcpsd_disable="yes"
sendmail_disable="yes"
ipv6_disable="yes"
routed_disable="yes"
named_disable="yes"
# verbose_message
#
# Print a message if verbose mode enabled
#.
verbose_message () {
text="$1"
style="$2"
if [ "$verbose" = 1 ] && [ "$style" = "fix" ]; then
if [ "$text" = "" ]; then
echo ""
else
echo "[ Fix ] $text"
fi
else
case $style in
audit|auditing)
echo "Auditing: $text"
;;
load|loading)
echo "Loading: $text"
;;
exec|execute|executing)
echo "Executing: $text"
;;
notice)
echo "Notice: $text"
;;
delete|deleting)
echo "Deleting: $text"
;;
install|installing)
echo "Installing: $text"
;;
backup)
echo "Backup: $text"
;;
save|saving)
echo "Saving: $text"
;;
set|setting)
echo "Setting: $text"
;;
run|running)
echo "Running: $text"
;;
restore|restoring)
echo "Restoring: $text"
;;
remove|removing)
echo "Removing: $text"
;;
check|checking)
echo "Checking: $text"
;;
create|creating)
echo "Creating: $text"
;;
warn|warning)
echo "Warning: $text"
;;
secure)
echo "Secure: $text"
;;
esac
fi
}
# Get our ID
os_name=$( uname )
if [ "$os_name" != "VMkernel" ]; then
if [ "$os_name" = "SunOS" ]; then
id_check=$( id | cut -c5 )
else
id_check=$( id -u )
fi
arg_test=$(echo "$args" | grep -E "help|version" | wc -l | sed "s/ //g" )
if [ "$arg_test" = "1" ]; then
if [ "$id_check" != "0" ]; then
verbose_message "$0 may need root" "warn"
fi
fi
fi
# Reset base dirs if not running as root
if [ ! "$id_check" = 0 ]; then
base_dir="$HOME/.$pkg_suffix"
temp_dir="$base_dir/tmp"
temp_file="$temp_dir/$pkg_suffix.tmp"
work_dir="$base_dir/$date_suffix"
fi
# Install packages
install_rsyslog="no"
# This is the company name that will go into the security message
# Change it as required
company_name="Insert Company Name Here"
# cidr_to_mask
#
# Convert CIDR to netmask
#.
cidr_to_mask () {
set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
if [ "$1" -gt 1 ]; then
shift "$1"
else
shift
fi
echo "${1-0}"."${2-0}"."${3-0}"."${4-0}"
}
# mask_to_cidr
#
# Convert netmask to CIDR
#.
mask_to_cidr () {
x="${1##*255.}"
set -- 0^^^128^192^224^240^248^252^254^ $(( (${#1} - ${#x})*2 )) "${x%%.*}"
x=${1%%"$3"*}
echo $(( $2 + (${#x}/4) ))
}
# check_virtual_platform
#
# Check if we are running on a virtual platform
#.
check_virtual_platform () {
virtual="Unknown"
if [ -f "/.dockerenv" ]; then
virtual="Docker"
else
dmi_check=$( command -v dmidecode | grep dmidecode | grep -v no | wc -l | sed "s/ //g" )
if [ "$dmi_check" = "1" ] && [ "$my_id" = "0" ]; then
virtual=$( dmidecode | grep Manufacturer |head -1 | awk '{print $2}' | sed "s/,//g" )
else
virtual=$( uname -p )
fi
fi
echo "Platform: $virtual"
}
# get_ubuntu_codename
#
# Get Ubuntu Codename
#.
get_ubuntu_codename () {
case "$1" in
"20.04")
ubuntu_codename="focal"
;;
"22.04")
ubuntu_codename="focal"
;;
"24.04")
ubuntu_codename="noble"
;;
*)
ubuntu_codename="lts"
;;
esac
}
# check_os_release
#
# Get OS release information
#.
check_os_release () {
echo ""
echo "# SYSTEM INFORMATION:"
echo ""
os_codename=""
os_minorrev=""
os_name=$( uname )
if [ "$os_name" = "Darwin" ]; then
os_release=$( sw_vers |grep ProductVersion |awk '{print $2}' )
os_version=$( echo "$os_release" |cut -f1 -d. )
os_update=$( echo "$os_release" |cut -f2 -d. )
os_vendor="Apple"
if [ "$os_update" = "" ]; then
os_update=$( sw_vers |grep ^BuildVersion |awk '{print $2}' )
fi
fi
if [ "$os_name" = "Linux" ]; then
os_release=$(lsb_release -r 2> /dev/null |awk '{print $2}')
if [ -f "/etc/redhat-release" ]; then
os_version=$( awk '{print $3}' < /etc/redhat-release | cut -f1 -d. )
if [ "$os_version" = "Enterprise" ]; then
os_version=$( awk '{print $7}' < /etc/redhat-release | cut -f1 -d. )
if [ "$os_version" = "Beta" ]; then
os_version=$( awk '{print $6}' < /etc/redhat-release | cut -f1 -d. )
os_update=$( awk '{print $6}' < /etc/redhat-release | cut -f2 -d. )
else
os_update=$( awk '{print $7}' < /etc/redhat-release | cut -f2 -d. )
fi
else
if [ "$os_version" = "release" ]; then
os_version=$( awk '{print $4}' < /etc/redhat-release | cut -f1 -d. )
os_update=$( awk '{print $4}' < /etc/redhat-release | cut -f2 -d. )
else
os_update=$( awk '{print $3}' < /etc/redhat-release | cut -f2 -d. )
fi
fi
os_vendor=$( awk '{print $1}' < /etc/redhat-release )
linux_dist="redhat"
else
if [ -f "/etc/debian_version" ]; then
if [ -f "/etc/lsb-release" ]; then
os_version=$( grep "DISTRIB_RELEASE" /etc/lsb-release | cut -f2 -d= | cut -f1 -d. )
os_update=$( grep "DISTRIB_RELEASE" /etc/lsb-release | cut -f2 -d= | cut -f2 -d. )
os_vendor=$( grep "DISTRIB_ID" /etc/lsb-release | cut -f2 -d= )
os_codename=$( grep "DISTRIB_CODENAME" /etc/lsb-release | cut -f2 -d= )
os_minorrev=$(lsb_release -d |awk '{print $3}' |cut -f3 -d. )
else
if [ -f "/etc/debian_version" ]; then
os_version=$( cut -f1 -d. /etc/debian_version )
os_update=$( cut -f2 -d. /etc/debian_version )
os_vendor="Debian"
else
os_version=$( lsb_release -r | awk '{print $2}' | cut -f1 -d. )
os_update=$( lsb_release -r | awk '{print $2}' | cut -f2 -d. )
os_vendor=$( lsb_release -i | awk '{print $3}' )
fi
fi
linux_dist="debian"
os_test=$( echo "$os_version" | grep "[0-9]" )
if [ -n "$os_test" ]; then
if [ ! -f "/usr/sbin/sysv-rc-conf" ] && [ "$os_version" -lt 16 ]; then
echo "Notice: The sysv-rc-conf package may be required by this script but is not present"
fi
fi
if [ ! -f "/usr/bin/bc" ]; then
use_expr="yes"
fi
if [ ! -f "/usr/bin/finger" ]; then
use_finger="no"
fi
else
if [ -f "/etc/SuSE-release" ]; then
os_version=$( grep '^VERSION' /etc/SuSe-release | awk '{print $3}' | cut -f1 -d. )
os_update=$( grep '^VERSION' /etc/SuSe-release | awk '{print $3}' | cut -f2 -d. )
os_vendor="SuSE"
linux_dist="suse"
else
if [ -f "/etc/os-release" ]; then
os_vendor="Amazon"
os_version=$( grep 'CPE_NAME' /etc/os-release | cut -f2 -d: | cut -f1 -d. )
os_update=$( grep 'CPE_NAME' /etc/os-release | cut -f2 -d: | cut -f2 -d. )
fi
fi
fi
fi
fi
if [ "$os_name" = "SunOS" ]; then
os_vendor="Oracle Solaris"
os_version=$( uname -r |cut -f2 -d"." )
if [ "$os_version" = "11" ]; then
os_update=$( grep Solaris /etc/release | awk '{print $3}' | cut -f2 -d. )
fi
if [ "$os_version" = "10" ]; then
os_update=$( grep Solaris /etc/release | awk '{print $5}' | cut -f2 -d_ | sed 's/[A-z]//g' )
fi
if [ "$os_version" = "9" ]; then
os_update=$( grep Solaris /etc/release | awk '{print $4}' | cut -f2 -d_ | sed 's/[A-z]//g' )
fi
fi
if [ "$os_name" = "FreeBSD" ]; then
os_version=$( uname -r | cut -f1 -d. )
os_update=$( uname -r | cut -f2 -d. )
os_vendor=$os_name
fi
if [ "$os_name" = "AIX" ]; then
os_vendor="IBM"
os_version=$( oslevel | cut -f1 -d. )
os_update=$( oslevel | cut -f2 -d. )
fi
if [ "$os_name" = "VMkernel" ]; then
os_version=$( uname -r )
os_update=$( uname -v | awk '{print $4}' )
os_vendor="VMware"
fi
if [ "$os_name" != "Linux" ] && [ "$os_name" != "SunOS" ] && [ "$os_name" != "Darwin" ] && [ "$os_name" != "FreeBSD" ] && [ "$os_name" != "AIX" ] && [ "$os_name" != "VMkernel" ]; then
echo "OS not supported"
exit
fi
if [ "$os_name" = "Linux" ]; then
os_platform=$( grep model < /proc/cpuinfo |tail -1 |cut -f2 -d: |sed "s/^ //g" )
else
if [ "$os_name" = "Darwin" ]; then
os_platform=$( system_profiler SPHardwareDataType |grep Chip |cut -f2 -d: |sed "s/^ //g" )
else
os_platform=$( uname -p )
fi
fi
os_machine=$( uname -m )
check_virtual_platform
if [ "$os_platform" = "" ]; then
os_platform=$( uname -p )
fi
echo "Processor: $os_platform"
echo "Machine: $os_machine"
echo "Vendor: $os_vendor"
echo "Name: $os_name"
if [ ! "$os_release" = "" ]; then
echo "Release: $os_release"
fi
echo "Version: $os_version"
echo "Update: $os_update"
if [ ! "$os_minorrev" = "" ]; then
echo "Minor Rev: $os_minorrev"
fi
if [ ! "$os_codename" = "" ]; then
echo "Codename: $os_codename"
fi
if [ "$os_name" = "Darwin" ]; then
if [ "$os_update" -lt 10 ]; then
long_update="0$os_update"
else
long_update="$os_update"
fi
long_os_version="$os_version$long_update"
#echo "XRelease: $long_os_version"
fi
}
# check_environment
#
# Do some environment checks
# Create base and temporary directory
#.
check_environment () {
check_os_release
if [ "$os_name" = "Darwin" ]; then
verbose_message "" ""
verbose_message "If node is managed" "check"
managed_node=$( sudo pwpolicy -n -getglobalpolicy 2>&1 |cut -f1 -d: )
if [ "$managed_node" = "Error" ]; then
verbose_message "Node is not managed" "notice"
else
verbose_message "Node is managed" "notice"
fi
verbose_message "" ""
fi
# Load functions from functions directory
if [ -d "$functions_dir" ]; then
if [ "$verbose" = "1" ]; then
echo ""
echo "Loading Functions"
echo ""
fi
file_list=$( ls "$functions_dir"/*.sh )
for file_name in $file_list; do
if [ "$os_name" = "SunOS" ] || [ "$os_name" = "AIX" ] || [ "$os_vendor" = "Debian" ] || [ "$os_vendor" = "Ubuntu" ]; then
. "$file_name"
else
source "$file_name"
fi
if [ "$verbose" = "1" ]; then
verbose_message "\"$file_name\"" "load"
fi
done
fi
# Load modules for modules directory
if [ -d "$modules_dir" ]; then
if [ "$verbose" = "1" ]; then
echo ""
echo "Loading Modules"
echo ""
fi
file_list=$( ls "$modules_dir"/*.sh )
for file_name in $file_list; do
if [ "$os_name" = "SunOS" ] || [ "$os_name" = "AIX" ] || [ "$os_vendor" = "Debian" ] || [ "$os_vendor" = "Ubuntu" ]; then
. "$file_name"
else
if [ "$file_name" = "modules/audit_ftp_users.sh" ]; then
if [ "$os_name" != "VMkernel" ]; then
source "$file_name"
fi
else
source "$file_name"
fi
fi
if [ "$verbose" = "1" ]; then
verbose_message "\"$file_name\"" "load"
fi
done
fi
# Private modules for customers
if [ -d "$private_dir" ]; then
echo ""
echo "Loading Customised Modules"
echo ""
if [ "$verbose" = "1" ]; then
echo ""
fi
file_list=$( ls "$private_dir"/*.sh )
for file_name in $file_list; do
if [ "$os_name" = "SunOS" ] || [ "$os_name" = "AIX" ] || [ "$os_vendor" = "Debian" ] || [ "$os_vendor" = "Ubuntu" ]; then
. "$file_name"
else
source "$file_name"
fi
done
if [ "$verbose" = "1" ]; then
echo "Loading: $file_name"
fi
fi
if [ ! -d "$base_dir" ]; then
mkdir -p "$base_dir"
chmod 700 "$base_dir"
fi
if [ ! -d "$temp_dir" ]; then
mkdir -p "$temp_dir"
fi
if [ "$audit_mode" = 0 ]; then
if [ ! -d "$work_dir" ]; then
mkdir -p "$work_dir"
fi
fi
}
# lockdown_command
#
# Run a lockdown command
# Check that we are in lockdown mode
# If not in lockdown mode output a verbose message
#.
lockdown_command () {
command="$1"
message="$2"
if [ "$audit_mode" = 0 ]; then
if [ "$message" ]; then
verbose_message "$message" "set"
fi
verbose_message "$command" "execute"
eval "$command"
else
verbose_message "$command" "fix"
fi
}
# restore_command
#
# Restore command
# Check we are running in restore mode run a command
#.
restore_command () {
command="$1"
message="$2"
if [ "$audit_mode" = 0 ]; then
if [ "$message" ]; then
verbose_message "$message" "restore"
fi
verbose_message "$command" "execute"
eval "$command"
else
verbose_message "$command" "fix"
fi
}
#
# backup_state
#
# Backup state to a log file for later restoration
#.
backup_state () {
if [ "$audit_mode" = 0 ]; then
backup_name="$1"
backup_value="$1"
backup_file="$work_dir/$backup_name.log"
echo "$backup_value" > "$backup_file"
fi
}
#
# restore_state
#
# Restore state from a log file
#.
restore_state () {
if [ "$audit_mode" = 2 ]; then
restore_name="$1"
current_value="$2"
restore_command="$3"
restore_file="$restore_dir/$restore_name"
if [ -f "$restore_file" ]; then
restore_value=$( cat "$restore_file" )
if [ "$current_value" != "$restore_value" ]; then
echo "Executing: $command"
$( $restore_command )
fi
fi
fi
}
# increment_total
#
# Increment total count
#.
increment_total () {
if [ "$audit_mode" != 2 ]; then
total=$((total+1))
fi
}
# increment_secure
#
# Increment secure count
#.
increment_secure () {
if [ "$audit_mode" != 2 ]; then
message="$1"
total=$((total+1))
secure=$((insecure+1))
echo "Secure: $message [$secure Passes]"
fi
}
# increment_insecure
#
# Increment insecure count
#.
increment_insecure () {
if [ "$audit_mode" != 2 ]; then
message="$1"
total=$((total+1))
insecure=$((insecure+1))
verbose_message "$message [$insecure Warnings]" "warn"
fi
}
# print_previous
#
# Print previous changes
#.
print_previous () {
if [ -d "$base_dir" ]; then
echo ""
echo "Printing previous settings:"
echo ""
if [ -d "$base_dir" ]; then
find "$base_dir" -type f -print -exec cat -n {} \;
fi
fi
}
# handle_output
#
# Handle output
#.
handle_output () {
text="$1"
echo "$1"
}
# checking_message
#
# Checking message
#.
checking_message () {
verbose_message "$1" "check"
}
# setting_message
#
# Setting message
#.
setting_message () {
verbose_message "$1" "set"
}
# print_changes
#
# Do a diff between previous file (saved) and existing file
#.
print_changes () {
if [ -f "$base_dir" ]; then
echo ""
echo "Printing changes:"
echo ""
file_list=$( find "$base_dir" -type f -print )
for saved_file in $file_list; do
check_file=$( echo "$saved_file" | cut -f 5- -d"/" )
top_dir=$( echo "$saved_file" | cut -f 1-4 -d"/" )
echo "Directory: \"$top_dir\""
log_test=$( echo "$check_file" |grep "log$" )
if [ -n "$log_test" ]; then
echo "Original system parameters:"
sed "s/,/ /g" < "$saved_file"
else
echo "Changes to \"/$check_file\":"
diff "$saved_file" "/$check_file"
fi
done
else
echo "No changes made recently"
fi
}
# check_aws
#
# Check AWS CLI etc is installed
#.
check_aws () {
aws_bin=$( command -v aws 2> /dev/null )
if [ -f "$aws_bin" ]; then
aws_creds="$HOME/.aws/credentials"
if [ -f "$aws_creds" ]; then
if [ "$os_name" = "Darwin" ]; then
base64_d="base64 -D"
else
base64_d="base64 -d"
fi
else
echo "AWS credentials file does not exit"
exit
fi
else
echo "AWS CLI is not installed"
exit
fi
if [ ! "$aws_region" ]; then
aws_region=$( aws configure get region )
fi
}
# funct_audit_kubernetes
#
# Audit Kubernetes
#.
funct_audit_kubernetes () {
audit_mode=$1
check_environment
audit_kubernetes_all
print_results
}
# funct_audit_aws
#
# Audit AWS
#.
funct_audit_docker () {
audit_mode=$1
check_environment
audit_docker_all
print_results
}
# funct_audit_aws
#
# Audit AWS
#.
funct_audit_aws () {
audit_mode=$1
check_environment
check_aws
audit_aws_all
print_results
}
# funct_audit_aws
#
# Audit AWS
#.
funct_audit_aws_rec () {
audit_mode=$1
check_environment
check_aws
audit_aws_rec_all
print_results
}
# funct_audit_system
#
# Audit System
#.
funct_audit_system () {
audit_mode=$1
check_environment
if [ "$audit_mode" = 0 ]; then
if [ ! -d "$work_dir" ]; then
mkdir -p "$work_dir"
if [ "$os_name" = "SunOS" ]; then
echo "Creating: Alternate Boot Environment $date_suffix"
if [ "$os_version" = "11" ]; then
beadm create "audit_$date_suffix"
fi
if [ "$os_version" = "8" ] || [ "$os_version" = "9" ] || [ "$os_version" = "10" ]; then
if [ "$os_platform" != "i386" ]; then
lucreate -n "audit_$date_suffix"
fi
fi
else
:
# Add code to do LVM snapshot
fi
fi
fi
if [ "$audit_mode" = 2 ]; then
restore_dir="$base_dir/$restore_date"
if [ ! -d "$restore_dir" ]; then
echo "Restore directory \"$restore_dir\" does not exit"
exit
else
verbose_message "Restore directory to \"$restore_dir\"" "set"
fi
fi
audit_system_all
if [ "$do_fs" = 1 ]; then
audit_search_fs
fi
#audit_test_subset
sparc_test=$( echo "$os_platform" |grep "sparc" | wc -l | sed "s/ //g" )
if [ "$sparc_test" = "0" ]; then
audit_system_x86
else
audit_system_sparc
fi
print_results
}
# funct_audit_select
#
# Selective Audit
#.
funct_audit_select () {
audit_mode=$1
function=$2
check_environment
module_test=$(echo "$function" |grep aws |wc -l | sed "s/ //g" )
if [ "$module_test" = "1" ]; then
check_aws
fi
suffix_test=$( echo "$function" |grep "\\.sh" | wc -l | sed "s/ //g" )
if [ "$suffix_test" = "1" ]; then
function=$( echo "$function" |cut -f1 -d. )
fi
module_test=$(echo "$function" | grep "full" | wc -l | sed "s/ //g" )
if [ "$module_test" = "0" ]; then
function_test=$(echo "$function" | grep "audit_" | wc -l | sed "s/ //g" )
if [ "$function_test" = "0" ]; then
function="audit_$function"
fi
fi
module_test=$(echo "$function" | grep "audit" )
if [ -n "$module_test" ]; then
if [ -f "$modules_dir/$function.sh" ]; then
print_audit_info "$function"
eval "$function"
else
verbose_message "Audit function \"$function\" does not exist" "warn"
verbose_message "" ""
exit
fi
print_results
else
verbose_message "Audit function \"$function\" does not exist" "warn"
verbose_message "" ""
fi
}
# Get the path the script starts from
start_path=$( pwd )
# Get the version of the script from the script itself
script_version=$( cd "$start_path" || exit ; grep '^# Version' < "$0"| awk '{print $3}' )
# apply_latest_patches
#
# Code to apply patches
# Nothing done with this yet
#.
apply_latest_patches () {
:
}
# secure_baseline
#
# Establish a Secure Baseline
# This uses the Solaris 10 svcadm baseline
# Don't really need this so haven't coded anything for it yet
#.
secure_baseline () {
:
}
# print_results
#
# Print Results
#.
print_results () {
echo ""
if [ "$reboot" = 1 ]; then
reboot="Required"
else
reboot="Not Required"
fi
if [ ! "$audit_mode" = 2 ]; then
if [ "$no_cat" = "1" ]; then
echo "Tests: $total"
echo "Passes: $secure"
echo "Warnings: $insecure"
else
echo " \ /\ Tests: $total"
echo " ) ( ') Passes: $secure"
echo " ( / ) Warnings: $insecure"
echo " \(__)| Reboot: $reboot"
fi
fi
if [ "$audit_mode" != 1 ]; then
echo "Reboot: $reboot"
fi
if [ "$audit_mode" = 0 ]; then
echo "Backup: $work_dir"