|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# run-shellcheck |
| 4 | +# |
| 5 | +# CIS Debian Hardening |
| 6 | +# |
| 7 | + |
| 8 | +# |
| 9 | +# Ensure audit tools mode is configured (Automated) |
| 10 | +# |
| 11 | + |
| 12 | +set -e # One error, it's over |
| 13 | +set -u # One variable unset, it's over |
| 14 | + |
| 15 | +# shellcheck disable=2034 |
| 16 | +HARDENING_LEVEL=3 |
| 17 | +# shellcheck disable=2034 |
| 18 | +DESCRIPTION="Ensure audit tools mode is configured" |
| 19 | + |
| 20 | +AUDITD_TOOLS="/sbin/auditctl /sbin/aureport /sbin/ausearch /sbin/autrace /sbin/auditd /sbin/augenrules" |
| 21 | + |
| 22 | +# This function will be called if the script status is on enabled / audit mode |
| 23 | +audit() { |
| 24 | + AUDIT_INVALID_FILES="" |
| 25 | + local result |
| 26 | + |
| 27 | + for file in $AUDITD_TOOLS; do |
| 28 | + |
| 29 | + does_file_exist "$file" |
| 30 | + if [ "$FNRET" -eq 0 ]; then |
| 31 | + result=$(stat -Lc "%n %a" "$file" | grep -Pv -- '^\h*\H+\h+([0-7][0,1,4,5][0,1,4,5])\h*$') |
| 32 | + if [ -n "$result" ]; then |
| 33 | + crit "wrong permission $result" |
| 34 | + AUDIT_INVALID_FILES="$AUDIT_INVALID_FILES $(awk '{print $1}' <<<"$result")" |
| 35 | + fi |
| 36 | + |
| 37 | + else |
| 38 | + info "$file missing" |
| 39 | + fi |
| 40 | + |
| 41 | + done |
| 42 | + |
| 43 | +} |
| 44 | + |
| 45 | +# This function will be called if the script status is on enabled mode |
| 46 | +apply() { |
| 47 | + if [ -n "$AUDIT_INVALID_FILES" ]; then |
| 48 | + for file in $AUDIT_INVALID_FILES; do |
| 49 | + info "changing permission to 755 for $file" |
| 50 | + chmod 755 "$file" |
| 51 | + done |
| 52 | + fi |
| 53 | +} |
| 54 | + |
| 55 | +# This function will check config parameters required |
| 56 | +check_config() { |
| 57 | + : |
| 58 | +} |
| 59 | + |
| 60 | +# Source Root Dir Parameter |
| 61 | +if [ -r /etc/default/cis-hardening ]; then |
| 62 | + # shellcheck source=../../debian/default |
| 63 | + . /etc/default/cis-hardening |
| 64 | +fi |
| 65 | +if [ -z "$CIS_LIB_DIR" ]; then |
| 66 | + echo "There is no /etc/default/cis-hardening file nor cis-hardening directory in current environment." |
| 67 | + echo "Cannot source CIS_LIB_DIR variable, aborting." |
| 68 | + exit 128 |
| 69 | +fi |
| 70 | + |
| 71 | +# Main function, will call the proper functions given the configuration (audit, enabled, disabled) |
| 72 | +if [ -r "${CIS_LIB_DIR}"/main.sh ]; then |
| 73 | + # shellcheck source=../../lib/main.sh |
| 74 | + . "${CIS_LIB_DIR}"/main.sh |
| 75 | +else |
| 76 | + echo "Cannot find main.sh, have you correctly defined your root directory? Current value is $CIS_LIB_DIR in /etc/default/cis-hardening" |
| 77 | + exit 128 |
| 78 | +fi |
0 commit comments