Skip to content

Commit 1c3e6fa

Browse files
damien cavagninidamcav35
authored andcommitted
feat: add debian12 scripts
- password_number_changed_chars.sh -> 5.3.3.2.1 - password_dictcheck_enabled.sh -> 5.3.3.2.6 - password_quality_enforced.sh -> 5.3.3.2.7 - password_quality_enforced_for_root.sh -> 5.3.3.2.8 - root_umask.sh -> 5.4.2.6 - nologin_abent_from_etc_shells.sh -> 5.4.3.1
1 parent da3c034 commit 1c3e6fa

12 files changed

+726
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
3+
# run-shellcheck
4+
#
5+
# CIS Debian Hardening
6+
#
7+
8+
#
9+
# Ensure nologin is not listed in /etc/shells (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=2
17+
# shellcheck disable=2034
18+
DESCRIPTION="Ensure nologin is not listed in /etc/shells (Automated)"
19+
20+
FILE='/etc/shells'
21+
# By putting nologin in /etc/shells, any user that has nologin as its shell is considered a full, unrestricted user.
22+
# This is not the expected behavior for nologin.
23+
24+
# This function will be called if the script status is on enabled / audit mode
25+
audit() {
26+
ETC_SHELLS_VALID=0
27+
does_file_exist "$FILE"
28+
if [ "$FNRET" -eq 0 ]; then
29+
if $SUDO_CMD grep "nologin" "$FILE" >/dev/null 2>&1; then
30+
crit "'nologin' is present in $FILE"
31+
ETC_SHELLS_VALID=1
32+
fi
33+
fi
34+
35+
if [ "$ETC_SHELLS_VALID" -eq 0 ]; then
36+
ok "'nologin' is not in $FILE"
37+
fi
38+
}
39+
40+
# This function will be called if the script status is on enabled mode
41+
apply() {
42+
if [ "$ETC_SHELLS_VALID" -ne 0 ]; then
43+
info "Removing 'nologin' from $FILE"
44+
sed -i '/nologin/d' "$FILE"
45+
fi
46+
}
47+
48+
# This function will check config parameters required
49+
check_config() {
50+
:
51+
}
52+
53+
# Source Root Dir Parameter
54+
if [ -r /etc/default/cis-hardening ]; then
55+
# shellcheck source=../../debian/default
56+
. /etc/default/cis-hardening
57+
fi
58+
if [ -z "$CIS_LIB_DIR" ]; then
59+
echo "There is no /etc/default/cis-hardening file nor cis-hardening directory in current environment."
60+
echo "Cannot source CIS_LIB_DIR variable, aborting."
61+
exit 128
62+
fi
63+
64+
# Main function, will call the proper functions given the configuration (audit, enabled, disabled)
65+
if [ -r "${CIS_LIB_DIR}"/main.sh ]; then
66+
# shellcheck source=../../lib/main.sh
67+
. "${CIS_LIB_DIR}"/main.sh
68+
else
69+
echo "Cannot find main.sh, have you correctly defined your root directory? Current value is $CIS_LIB_DIR in /etc/default/cis-hardening"
70+
exit 128
71+
fi
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/bin/bash
2+
3+
# run-shellcheck
4+
#
5+
# CIS Debian Hardening
6+
#
7+
8+
#
9+
# Ensure password dictionary check 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=2
17+
# shellcheck disable=2034
18+
DESCRIPTION="Ensure password dictionary check is enabled"
19+
# 'dictcheck=0' will disable the dictionnary check
20+
EXPECTED_VALUE=1
21+
22+
# This function will be called if the script status is on enabled / audit mode
23+
audit() {
24+
QUALITY_VALID=1
25+
DICTCHECK_IN_PAM=1
26+
27+
# order of override from strongest to latest:
28+
# - /etc/pam.d/*
29+
# - /etc/security/pwquality.conf
30+
# - /etc/security/pwquality.conf.d/*.conf
31+
# "It is recommended that settings be configured in a .conf file in the /etc/security/pwquality.conf.d/ directory for clarity, convenience, and durability."
32+
33+
local dictcheck_value=""
34+
DICTCHECK_FILE="/etc/security/pwquality.conf"
35+
36+
if [ -d /etc/security/pwquality.conf.d ]; then
37+
if grep -E "^[[:space:]]?dictcheck" /etc/security/pwquality.conf.d/*.conf >/dev/null 2>&1; then
38+
# if set in many places, the latest one is the one used
39+
DICTCHECK_FILE=$(grep -lE "^[[:space:]]?dictcheck" | sort -n | tail -n 1)
40+
fi
41+
fi
42+
43+
# maybe absent from /etc/security/pwquality.conf
44+
if grep -E "^[[:space:]]?dictcheck" "$DICTCHECK_FILE" >/dev/null 2>&1; then
45+
dictcheck_value=$(grep -E "^[[:space:]]?dictcheck" "$DICTCHECK_FILE" | awk -F '=' '{print $2}' | sed 's/\ *//g')
46+
info "current 'pwquality dictcheck' value = $dictcheck_value"
47+
48+
if [ "$dictcheck_value" -eq "$EXPECTED_VALUE" ]; then
49+
QUALITY_VALID=0
50+
fi
51+
fi
52+
53+
for file in /usr/share/pam-configs/*; do
54+
if grep -Pl -- '\bpam_pwquality\.so\h+([^#\n\r]+\h+)?dictcheck\b' "$file" >/dev/null 2>&1; then
55+
DICTCHECK_IN_PAM=0
56+
break
57+
fi
58+
done
59+
60+
if [ "$QUALITY_VALID" -eq 0 ]; then
61+
ok "pwquality 'dictcheck' value is correctly configured"
62+
else
63+
crit "pwquality 'dictcheck' value is not correctly configured"
64+
fi
65+
66+
if [ "$DICTCHECK_IN_PAM" -eq 0 ]; then
67+
crit "pwquality 'dictcheck' is overriden in pam configuration"
68+
fi
69+
70+
}
71+
72+
# This function will be called if the script status is on enabled mode
73+
apply() {
74+
if [ "$QUALITY_VALID" -ne 0 ]; then
75+
sed -E -i '/^[[:space:]]?dictcheck/d' "$DICTCHECK_FILE"
76+
echo "dictcheck=$EXPECTED_VALUE" >>"$DICTCHECK_FILE"
77+
fi
78+
79+
if [ "$DICTCHECK_IN_PAM" -eq 0 ]; then
80+
for file in /usr/share/pam-configs/*; do
81+
if grep -Pl -- '\bpam_pwquality\.so\h+([^#\n\r]+\h+)?dictcheck\b' "$file" >/dev/null 2>&1; then
82+
sed -E -i 's/dictcheck[[:space:]]?=[[:space:]]?[0-9]+//g' "$file"
83+
fi
84+
done
85+
fi
86+
87+
}
88+
89+
# This function will check config parameters required
90+
check_config() {
91+
:
92+
}
93+
94+
# Source Root Dir Parameter
95+
if [ -r /etc/default/cis-hardening ]; then
96+
# shellcheck source=../../debian/default
97+
. /etc/default/cis-hardening
98+
fi
99+
if [ -z "$CIS_LIB_DIR" ]; then
100+
echo "There is no /etc/default/cis-hardening file nor cis-hardening directory in current environment."
101+
echo "Cannot source CIS_LIB_DIR variable, aborting."
102+
exit 128
103+
fi
104+
105+
# Main function, will call the proper functions given the configuration (audit, enabled, disabled)
106+
if [ -r "${CIS_LIB_DIR}"/main.sh ]; then
107+
# shellcheck source=../../lib/main.sh
108+
. "${CIS_LIB_DIR}"/main.sh
109+
else
110+
echo "Cannot find main.sh, have you correctly defined your root directory? Current value is $CIS_LIB_DIR in /etc/default/cis-hardening"
111+
exit 128
112+
fi
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
3+
# run-shellcheck
4+
#
5+
# CIS Debian Hardening
6+
#
7+
8+
#
9+
# Ensure password number of changed characters 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=2
17+
# shellcheck disable=2034
18+
DESCRIPTION="Ensure password number of changed characters is configured"
19+
20+
OPTIONS=''
21+
22+
# This function will be called if the script status is on enabled / audit mode
23+
audit() {
24+
QUALITY_VALID=1
25+
DIFOK_IN_PAM=1
26+
27+
# order of override from strongest to latest:
28+
# - /etc/pam.d/*
29+
# - /etc/security/pwquality.conf
30+
# - /etc/security/pwquality.conf.d/*.conf
31+
# "It is recommended that settings be configured in a .conf file in the /etc/security/pwquality.conf.d/ directory for clarity, convenience, and durability."
32+
expected_value=$(awk -F '=' '{print $2}' <<<"$OPTIONS")
33+
34+
local difok_value=""
35+
DIFOK_FILE="/etc/security/pwquality.conf"
36+
37+
if [ -d /etc/security/pwquality.conf.d ]; then
38+
if grep -E "^[[:space:]]?difok" /etc/security/pwquality.conf.d/*.conf >/dev/null 2>&1; then
39+
# if set in many places, the latest one is the one used
40+
DIFOK_FILE=$(grep -lE "^[[:space:]]?difok" | sort -n | tail -n 1)
41+
fi
42+
fi
43+
44+
# maybe absent from /etc/security/pwquality.conf
45+
if grep -E "^[[:space:]]?difok" "$DIFOK_FILE" >/dev/null 2>&1; then
46+
difok_value=$(grep -E "^[[:space:]]?difok" "$DIFOK_FILE" | awk -F '=' '{print $2}' | sed 's/\ *//g')
47+
info "current 'pwquality difok' value = $difok_value"
48+
49+
if [ "$difok_value" -eq "$expected_value" ]; then
50+
QUALITY_VALID=0
51+
fi
52+
fi
53+
54+
for file in /usr/share/pam-configs/*; do
55+
if grep -Pl -- '\bpam_pwquality\.so\h+([^#\n\r]+\h+)?difok\b' "$file" >/dev/null 2>&1; then
56+
DIFOK_IN_PAM=0
57+
break
58+
fi
59+
done
60+
61+
if [ "$QUALITY_VALID" -eq 0 ]; then
62+
ok "pwquality 'difok' value is correctly configured"
63+
else
64+
crit "pwquality 'difok' value is not correctly configured"
65+
fi
66+
67+
if [ "$DIFOK_IN_PAM" -eq 0 ]; then
68+
crit "pwquality 'difok' is overriden in pam configuration"
69+
fi
70+
71+
}
72+
73+
# This function will be called if the script status is on enabled mode
74+
apply() {
75+
if [ "$QUALITY_VALID" -ne 0 ]; then
76+
sed -E -i '/^[[:space:]]?difok/d' "$DIFOK_FILE"
77+
echo "$OPTIONS" >>"$DIFOK_FILE"
78+
fi
79+
80+
if [ "$DIFOK_IN_PAM" -eq 0 ]; then
81+
for file in /usr/share/pam-configs/*; do
82+
if grep -Pl -- '\bpam_pwquality\.so\h+([^#\n\r]+\h+)?difok\b' "$file" >/dev/null 2>&1; then
83+
sed -E -i 's/difok[[:space:]]?=[[:space:]]?[0-9]+//g' "$file"
84+
fi
85+
done
86+
fi
87+
88+
}
89+
90+
# This function will create the config file for this check with default values
91+
create_config() {
92+
cat <<EOF
93+
status=audit
94+
# Put your custom configuration here
95+
OPTIONS="difok=2"
96+
EOF
97+
}
98+
99+
# This function will check config parameters required
100+
check_config() {
101+
:
102+
}
103+
104+
# Source Root Dir Parameter
105+
if [ -r /etc/default/cis-hardening ]; then
106+
# shellcheck source=../../debian/default
107+
. /etc/default/cis-hardening
108+
fi
109+
if [ -z "$CIS_LIB_DIR" ]; then
110+
echo "There is no /etc/default/cis-hardening file nor cis-hardening directory in current environment."
111+
echo "Cannot source CIS_LIB_DIR variable, aborting."
112+
exit 128
113+
fi
114+
115+
# Main function, will call the proper functions given the configuration (audit, enabled, disabled)
116+
if [ -r "${CIS_LIB_DIR}"/main.sh ]; then
117+
# shellcheck source=../../lib/main.sh
118+
. "${CIS_LIB_DIR}"/main.sh
119+
else
120+
echo "Cannot find main.sh, have you correctly defined your root directory? Current value is $CIS_LIB_DIR in /etc/default/cis-hardening"
121+
exit 128
122+
fi
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/bash
2+
3+
# run-shellcheck
4+
#
5+
# CIS Debian Hardening
6+
#
7+
8+
#
9+
# Ensure password quality checking is enforced (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=2
17+
# shellcheck disable=2034
18+
DESCRIPTION="Ensure password quality checking is enforced"
19+
20+
# This function will be called if the script status is on enabled / audit mode
21+
audit() {
22+
QUALITY_VALID=0
23+
DISABLED_IN_PAM=1
24+
25+
for file in /etc/security/pwquality.conf /etc/security/pwquality.conf.d/*.conf; do
26+
if grep -Psi -- '^\h*enforcing\h*=\h*0\b' "$file" >/dev/null 2>&1; then
27+
QUALITY_VALID=1
28+
break
29+
fi
30+
done
31+
32+
if grep -PHsi -- '^\h*password\h+[^#\n\r]+\h+pam_pwquality\.so\h+([^#\n\r]+\h+)?enforcing=0\b' /etc/pam.d/common-password >/dev/null; then
33+
DISABLED_IN_PAM=0
34+
QUALITY_VALID=1
35+
fi
36+
37+
if [ "$QUALITY_VALID" -eq 0 ]; then
38+
ok "password quality is enforced"
39+
else
40+
crit "password quality is not enforced"
41+
fi
42+
43+
}
44+
45+
# This function will be called if the script status is on enabled mode
46+
apply() {
47+
if [ "$QUALITY_VALID" -ne 0 ]; then
48+
for file in /usr/share/pam-configs/* /etc/security/pwquality.conf; do
49+
if grep -Psi -- '^\h*enforcing\h*=\h*0\b' "$file" >/dev/null 2>&1; then
50+
info "Commenting 'enforcing=0' in $file"
51+
sed -ri 's/^\s*enforcing\s*=\s*0/# &/' "$file"
52+
fi
53+
done
54+
fi
55+
56+
if [ "$DISABLED_IN_PAM" -ne 1 ]; then
57+
info "Removing 'enforcing=0' in /etc/pam.d/common-password"
58+
sed -E -i 's/enforcing[[:space:]]?=[[:space:]]?0//g' /etc/pam.d/common-password
59+
fi
60+
61+
}
62+
63+
# This function will check config parameters required
64+
check_config() {
65+
:
66+
}
67+
68+
# Source Root Dir Parameter
69+
if [ -r /etc/default/cis-hardening ]; then
70+
# shellcheck source=../../debian/default
71+
. /etc/default/cis-hardening
72+
fi
73+
if [ -z "$CIS_LIB_DIR" ]; then
74+
echo "There is no /etc/default/cis-hardening file nor cis-hardening directory in current environment."
75+
echo "Cannot source CIS_LIB_DIR variable, aborting."
76+
exit 128
77+
fi
78+
79+
# Main function, will call the proper functions given the configuration (audit, enabled, disabled)
80+
if [ -r "${CIS_LIB_DIR}"/main.sh ]; then
81+
# shellcheck source=../../lib/main.sh
82+
. "${CIS_LIB_DIR}"/main.sh
83+
else
84+
echo "Cannot find main.sh, have you correctly defined your root directory? Current value is $CIS_LIB_DIR in /etc/default/cis-hardening"
85+
exit 128
86+
fi

0 commit comments

Comments
 (0)