Skip to content

Commit 65edce9

Browse files
author
damien cavagnini
committed
feat: add debian12 scripts
- sudo_re_authenticate.sh -> 5.2.5 - pam_pwhistory_enabled.sh -> 5.3.2.4 - pam_faillock_enabled.sh -> 5.3.2.2 This is an updated version of enable_lockout_failed_password.sh (renamed) - pam_unix_enabled.sh -> 5.3.2.1 - password_failed_lockout.sh -> 5.3.3.1.1 - password_unlock_time.sh -> 5.3.3.1.2 - password_root_unlock.sh -> 5.3.3.1.3
1 parent 06067b0 commit 65edce9

17 files changed

+814
-116
lines changed

bin/hardening/enable_lockout_failed_password.sh

Lines changed: 0 additions & 96 deletions
This file was deleted.

bin/hardening/pam_faillock_enabled.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
3+
# run-shellcheck
4+
#
5+
# CIS Debian Hardening
6+
#
7+
8+
#
9+
# Ensure pam_faillock module is enabled (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 pam_faillock module is enabled"
19+
20+
PAM_FILES="/etc/pam.d/common-auth /etc/pam.d/common-account"
21+
PAM_PATTERN="^[^#].*pam_faillock.so"
22+
23+
# This function will be called if the script status is on enabled / audit mode
24+
audit() {
25+
PAM_VALID=0
26+
27+
for PAM_FILE in $PAM_FILES; do
28+
if grep "$PAM_PATTERN" "$PAM_FILE" >/dev/null 2>&1; then
29+
info "pam_faillock found in $PAM_FILE"
30+
else
31+
crit "pam_faillock not found in $PAM_FILE"
32+
PAM_VALID=1
33+
fi
34+
done
35+
36+
if [ "$PAM_VALID" -eq 0 ]; then
37+
ok "pam_faillock is enabled"
38+
fi
39+
}
40+
41+
# This function will be called if the script status is on enabled mode
42+
apply() {
43+
if [ "$PAM_VALID" -ne 0 ]; then
44+
# check if already present in an pam-auth-update profile
45+
# if not
46+
# - add in a profile
47+
# then in all cases : pam-auth-update --enable {PROFILE_NAME}
48+
if ! grep "$PAM_PATTERN" /usr/share/pam-configs/*; then
49+
pam_update_profile="faillock faillock_notify"
50+
arr=('Name: Enable pam_faillock to deny access' 'Default: yes' 'Priority: 0' 'Auth-Type: Primary' 'Auth:' ' [default=die] pam_faillock.so authfail')
51+
printf '%s\n' "${arr[@]}" >/usr/share/pam-configs/failock
52+
53+
arr=('Name: Notify of failed login attempts and reset count upon success' 'Default: yes' 'Priority: 1024' 'Auth-Type: Primary' 'Auth:' ' requisite pam_faillock.so preauth' 'Account-Type: Primary' 'Account:' ' required pam_faillock.so')
54+
printf '%s\n' "${arr[@]}" >/usr/share/pam-configs/faillock_notify
55+
56+
else
57+
pam_update_profile="$(grep -l "$PAM_PATTERN" /usr/share/pam-configs/* | paste -s)"
58+
fi
59+
60+
info "Applying 'pam-auth-update' to enable pam_faillock.so"
61+
for profile in $pam_update_profile; do
62+
DEBIAN_FRONTEND='noninteractive' pam-auth-update --force --enable "$profile"
63+
done
64+
fi
65+
}
66+
67+
# This function will check config parameters required
68+
check_config() {
69+
:
70+
}
71+
72+
# Source Root Dir Parameter
73+
if [ -r /etc/default/cis-hardening ]; then
74+
# shellcheck source=../../debian/default
75+
. /etc/default/cis-hardening
76+
fi
77+
if [ -z "$CIS_LIB_DIR" ]; then
78+
echo "There is no /etc/default/cis-hardening file nor cis-hardening directory in current environment."
79+
echo "Cannot source CIS_LIB_DIR variable, aborting."
80+
exit 128
81+
fi
82+
83+
# Main function, will call the proper functions given the configuration (audit, enabled, disabled)
84+
if [ -r "${CIS_LIB_DIR}"/main.sh ]; then
85+
# shellcheck source=../../lib/main.sh
86+
. "${CIS_LIB_DIR}"/main.sh
87+
else
88+
echo "Cannot find main.sh, have you correctly defined your root directory? Current value is $CIS_LIB_DIR in /etc/default/cis-hardening"
89+
exit 128
90+
fi
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
# run-shellcheck
4+
#
5+
# CIS Debian Hardening
6+
#
7+
8+
#
9+
# Ensure pam_pwhistory module is enabled (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 pam_pwhistory module is enabled "
19+
20+
PAM_FILE="/etc/pam.d/common-password"
21+
PAM_PATTERN="^[^#].*pam_pwhistory.so"
22+
23+
# This function will be called if the script status is on enabled / audit mode
24+
audit() {
25+
PAM_VALID=1
26+
27+
if grep "$PAM_PATTERN" "$PAM_FILE" >/dev/null 2>&1; then
28+
ok "pam_pwhistory is enabled"
29+
PAM_VALID=0
30+
else
31+
crit "pam_pwhistory is not enabled"
32+
fi
33+
}
34+
35+
# This function will be called if the script status is on enabled mode
36+
apply() {
37+
if [ "$PAM_VALID" -ne 0 ]; then
38+
# check if already present in an pam-auth-update profile
39+
# if not
40+
# - add in a profile
41+
# then in all cases : pam-auth-update --enable {PROFILE_NAME}
42+
if ! grep "$PAM_PATTERN" /usr/share/pam-configs/*; then
43+
pam_update_profile=pwhistory
44+
arr=('Name: pwhistory password history checking' 'Default: yes' 'Priority: 1024' 'Password-Type: Primary' 'Password:' ' requisite pam_pwhistory.so remember=24 enforce_for_root try_first_pass use_authtok')
45+
printf '%s\n' "${arr[@]}" >/usr/share/pam-configs/"$pam_update_profile"
46+
else
47+
pam_update_profile="$(grep -l "$PAM_PATTERN" /usr/share/pam-configs/* | head -n1)"
48+
fi
49+
info "Applying 'pam-auth-update' to enable pw_history.so"
50+
DEBIAN_FRONTEND='noninteractive' pam-auth-update --force --enable "$pam_update_profile"
51+
fi
52+
}
53+
54+
# This function will check config parameters required
55+
check_config() {
56+
:
57+
}
58+
59+
# Source Root Dir Parameter
60+
if [ -r /etc/default/cis-hardening ]; then
61+
# shellcheck source=../../debian/default
62+
. /etc/default/cis-hardening
63+
fi
64+
if [ -z "$CIS_LIB_DIR" ]; then
65+
echo "There is no /etc/default/cis-hardening file nor cis-hardening directory in current environment."
66+
echo "Cannot source CIS_LIB_DIR variable, aborting."
67+
exit 128
68+
fi
69+
70+
# Main function, will call the proper functions given the configuration (audit, enabled, disabled)
71+
if [ -r "${CIS_LIB_DIR}"/main.sh ]; then
72+
# shellcheck source=../../lib/main.sh
73+
. "${CIS_LIB_DIR}"/main.sh
74+
else
75+
echo "Cannot find main.sh, have you correctly defined your root directory? Current value is $CIS_LIB_DIR in /etc/default/cis-hardening"
76+
exit 128
77+
fi

bin/hardening/pam_unix_enabled.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
# run-shellcheck
4+
#
5+
# CIS Debian Hardening
6+
#
7+
8+
#
9+
# Ensure pam_unix module is enabled (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 pam_unix module is enabled"
19+
20+
PAM_FILES="/etc/pam.d/common-auth /etc/pam.d/common-account /etc/pam.d/common-session /etc/pam.d/common-password"
21+
PAM_PATTERN="^[^#].*pam_unix.so"
22+
23+
# This function will be called if the script status is on enabled / audit mode
24+
audit() {
25+
PAM_VALID=0
26+
27+
for PAM_FILE in $PAM_FILES; do
28+
if grep "$PAM_PATTERN" "$PAM_FILE" >/dev/null 2>&1; then
29+
info "pam_unix found in $PAM_FILE"
30+
else
31+
crit "pam_unix not found in $PAM_FILE"
32+
PAM_VALID=1
33+
fi
34+
done
35+
36+
if [ "$PAM_VALID" -eq 0 ]; then
37+
ok "pam_unix is enabled"
38+
fi
39+
}
40+
41+
# This function will be called if the script status is on enabled mode
42+
apply() {
43+
if [ "$PAM_VALID" -ne 0 ]; then
44+
info "Applying 'pam-auth-update' to enable pam_unix.so"
45+
DEBIAN_FRONTEND='noninteractive' pam-auth-update --force --enable unix
46+
fi
47+
}
48+
49+
# This function will check config parameters required
50+
check_config() {
51+
:
52+
}
53+
54+
# Source Root Dir Parameter
55+
if [ -r /etc/default/cis-hardening ]; then
56+
# shellcheck source=../../debian/default
57+
. /etc/default/cis-hardening
58+
fi
59+
if [ -z "$CIS_LIB_DIR" ]; then
60+
echo "There is no /etc/default/cis-hardening file nor cis-hardening directory in current environment."
61+
echo "Cannot source CIS_LIB_DIR variable, aborting."
62+
exit 128
63+
fi
64+
65+
# Main function, will call the proper functions given the configuration (audit, enabled, disabled)
66+
if [ -r "${CIS_LIB_DIR}"/main.sh ]; then
67+
# shellcheck source=../../lib/main.sh
68+
. "${CIS_LIB_DIR}"/main.sh
69+
else
70+
echo "Cannot find main.sh, have you correctly defined your root directory? Current value is $CIS_LIB_DIR in /etc/default/cis-hardening"
71+
exit 128
72+
fi

0 commit comments

Comments
 (0)