Skip to content

Commit 6079b16

Browse files
authored
fix: invalid behavior on sid/alternative in 5.3.4/99.5.4.5.1 (#237)
1 parent f7cdf43 commit 6079b16

File tree

4 files changed

+84
-8
lines changed

4 files changed

+84
-8
lines changed

Diff for: bin/hardening/5.3.4_acc_pam_sha512.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ apply() {
4949
ok "$CONF_LINE is present in $CONF_FILE"
5050
else
5151
warn "$CONF_LINE is not present in $CONF_FILE"
52-
if [ "$DEB_MAJ_VER" -ge "11" ]; then
52+
if [ "$DEB_MAJ_VER" = "sid" ] || [ "$DEB_MAJ_VER" -ge "11" ]; then
5353
add_line_file_before_pattern "$CONF_FILE" "password [success=1 default=ignore] pam_unix.so yescrypt" "# pam-auth-update(8) for details."
5454
else
5555
add_line_file_before_pattern "$CONF_FILE" "password [success=1 default=ignore] pam_unix.so sha512" "# pam-auth-update(8) for details."
@@ -67,12 +67,11 @@ check_config() {
6767
# We need to call this in the subs called by main.sh when it is sourced, otherwise it would
6868
# either be too soon (DEB_MAJ_VER not defined) or too late (test has already been run)
6969
_set_vars_jit() {
70-
if [ "$DEB_MAJ_VER" -ge "11" ]; then
70+
if [ "$DEB_MAJ_VER" = "sid" ] || [ "$DEB_MAJ_VER" -ge "11" ]; then
7171
CONF_LINE="^\s*password\s.+\s+pam_unix\.so\s+.*(sha512|yescrypt)" # https://github.com/ovh/debian-cis/issues/158
7272
else
7373
CONF_LINE="^\s*password\s.+\s+pam_unix\.so\s+.*sha512"
7474
fi
75-
unset -f _set_vars_jit
7675
}
7776

7877
# Source Root Dir Parameter

Diff for: bin/hardening/99.5.4.5.1_acc_logindefs_sha512.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ apply() {
4848
if [ "$FNRET" != 0 ]; then
4949
add_end_of_file "$CONF_FILE" "$CONF_LINE"
5050
else
51-
info "Parameter $SSH_PARAM is present but with the wrong value -- Fixing"
51+
info "Parameter $CONF_LINE is present but with the wrong value -- Fixing"
5252
replace_in_file "$CONF_FILE" "^$(echo "$CONF_LINE" | cut -d ' ' -f1)[[:space:]]*.*" "$CONF_LINE"
5353
fi
5454
fi
@@ -63,14 +63,13 @@ check_config() {
6363
# We need to call this in the subs called by main.sh when it is sourced, otherwise it would
6464
# either be too soon (DEB_MAJ_VER not defined) or too late (test has already been run)
6565
_set_vars_jit() {
66-
if [ "$DEB_MAJ_VER" -ge "11" ]; then
66+
if [ "$DEB_MAJ_VER" = "sid" ] || [ "$DEB_MAJ_VER" -ge "11" ]; then
6767
CONF_LINE_REGEX="ENCRYPT_METHOD (SHA512|yescrypt|YESCRYPT)"
6868
CONF_LINE="ENCRYPT_METHOD YESCRYPT"
6969
else
7070
CONF_LINE_REGEX="ENCRYPT_METHOD SHA512"
7171
CONF_LINE="ENCRYPT_METHOD SHA512"
7272
fi
73-
unset -f _set_vars_jit
7473
}
7574

7675
# Source Root Dir Parameter

Diff for: tests/hardening/5.3.4_acc_pam_sha512.sh

+46
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,50 @@ test_audit() {
66
register_test contain "is present in /etc/pam.d/common-password"
77
# shellcheck disable=2154
88
run blank "${CIS_CHECKS_DIR}/${script}.sh" --audit-all
9+
10+
describe Tests purposely failing
11+
sed -i '/pam_unix.so/ s/sha512/sha256/' "/etc/pam.d/common-password" # Debian 10
12+
sed -i '/pam_unix.so/ s/yescrypt/sha256/' "/etc/pam.d/common-password" # Debian 11+
13+
register_test retvalshouldbe 1
14+
register_test contain "is not present"
15+
run noncompliant "${CIS_CHECKS_DIR}/${script}.sh" --audit-all
16+
17+
describe correcting situation
18+
sed -i 's/audit/enabled/' "${CIS_CONF_DIR}/conf.d/${script}.cfg"
19+
"${CIS_CHECKS_DIR}/${script}.sh" --apply || true
20+
21+
describe Checking resolved state
22+
register_test retvalshouldbe 0
23+
register_test contain "is present in /etc/pam.d/common-password"
24+
run solvedsid "${CIS_CHECKS_DIR}/${script}.sh" --audit-all
25+
26+
# DEB_MAJ_VER cannot be overwritten here;
27+
# therefore we need to trick get_debian_major_version
28+
ORIGINAL_DEB_VER="$(cat /etc/debian_version)"
29+
echo "sid" >/etc/debian_version
30+
31+
describe Running on blank host as sid
32+
register_test retvalshouldbe 0
33+
register_test contain "(sha512|yescrypt)"
34+
run blanksid "${CIS_CHECKS_DIR}/${script}.sh" --audit-all
35+
36+
describe Tests purposely failing as sid
37+
sed -i '/pam_unix.so/ s/sha512/sha256/' "/etc/pam.d/common-password" # Debian 10
38+
sed -i '/pam_unix.so/ s/yescrypt/sha256/' "/etc/pam.d/common-password" # Debian 11+
39+
register_test retvalshouldbe 1
40+
register_test contain "is not present"
41+
run noncompliantsid "${CIS_CHECKS_DIR}/${script}.sh" --audit-all
42+
43+
describe correcting situation as sid
44+
sed -i 's/audit/enabled/' "${CIS_CONF_DIR}/conf.d/${script}.cfg"
45+
"${CIS_CHECKS_DIR}/${script}.sh" --apply || true
46+
47+
describe Checking resolved state as sid
48+
register_test retvalshouldbe 0
49+
register_test contain "is present in /etc/pam.d/common-password"
50+
run solvedsid "${CIS_CHECKS_DIR}/${script}.sh" --audit-all
51+
52+
# Cleanup
53+
echo -n "$ORIGINAL_DEB_VER" >/etc/debian_version
54+
unset ORIGINAL_DEB_VER
955
}

Diff for: tests/hardening/99.5.4.5.1_acc_logindefs_sha512.sh

+34-2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,43 @@ test_audit() {
2828
run wrongconf "${CIS_CHECKS_DIR}/${script}.sh" --audit-all
2929

3030
describe Correcting situation
31-
sed -i 's/disabled/enabled/' "${CIS_CONF_DIR}/conf.d/${script}.cfg"
31+
sed -i 's/audit/enabled/' "${CIS_CONF_DIR}/conf.d/${script}.cfg"
3232
"${CIS_CHECKS_DIR}/${script}.sh" || true
3333

3434
describe Checking resolved state
35-
mv /tmp/login.defs.bak /etc/login.defs
3635
register_test retvalshouldbe 0
36+
register_test contain "is present in /etc/login.defs"
3737
run sha512pass "${CIS_CHECKS_DIR}/${script}.sh" --audit-all
38+
39+
# DEB_MAJ_VER cannot be overwritten here;
40+
# therefore we need to trick get_debian_major_version
41+
ORIGINAL_DEB_VER="$(cat /etc/debian_version)"
42+
echo "sid" >/etc/debian_version
43+
44+
describe Running on blank host as sid
45+
register_test retvalshouldbe 0
46+
register_test contain "(SHA512|yescrypt|YESCRYPT)"
47+
# shellcheck disable=2154
48+
run blanksid "${CIS_CHECKS_DIR}/${script}.sh" --audit-all
49+
50+
cp /etc/login.defs /tmp/login.defs.bak
51+
sed -ir 's/ENCRYPT_METHOD[[:space:]]\+.*/ENCRYPT_METHOD MD5/' /etc/login.defs
52+
53+
describe Fail: wrong hash function configuration as sid
54+
register_test retvalshouldbe 1
55+
register_test contain "(SHA512|yescrypt|YESCRYPT)"
56+
run wrongconfsid "${CIS_CHECKS_DIR}/${script}.sh" --audit-all
57+
58+
describe Correcting situation as sid
59+
sed -i 's/audit/enabled/' "${CIS_CONF_DIR}/conf.d/${script}.cfg"
60+
"${CIS_CHECKS_DIR}/${script}.sh" || true
61+
62+
describe Checking resolved state as sid
63+
register_test retvalshouldbe 0
64+
register_test contain "(SHA512|yescrypt|YESCRYPT)"
65+
run sha512passsid "${CIS_CHECKS_DIR}/${script}.sh" --audit-all
66+
67+
# Cleanup
68+
echo -n "$ORIGINAL_DEB_VER" >/etc/debian_version
69+
unset ORIGINAL_DEB_VER
3870
}

0 commit comments

Comments
 (0)