104 lines
4.3 KiB
Bash
104 lines
4.3 KiB
Bash
#!/bin/bash
|
|
# SPDX-Version: 3.0
|
|
# SPDX-CreationInfo: 2025-06-17; WEIDNER, Marc S.; <msw@coresecret.dev>
|
|
# SPDX-ExternalRef: GIT https://git.coresecret.dev/msw/CISS.debian.installer.git
|
|
# SPDX-FileContributor: WEIDNER, Marc S.; Centurion Intelligence Consulting Agency
|
|
# SPDX-FileCopyrightText: 2024-2025; WEIDNER, Marc S.; <msw@coresecret.dev>
|
|
# SPDX-FileType: SOURCE
|
|
# SPDX-License-Identifier: EUPL-1.2 OR LicenseRef-CCLA-1.0
|
|
# SPDX-LicenseComment: This file is part of the CISS.debian.installer.secure framework.
|
|
# SPDX-PackageName: CISS.debian.installer
|
|
# SPDX-Security-Contact: security@coresecret.eu
|
|
|
|
guard_sourcing
|
|
|
|
#######################################
|
|
# Hardening accounts: Google TOTP, Wordlists, masking ttys, expiration of accounts.
|
|
# Globals:
|
|
# TARGET
|
|
# VAR_SETUP_PATH
|
|
# Arguments:
|
|
# None
|
|
# Returns:
|
|
# 0: on success
|
|
#######################################
|
|
accounts_hardening() {
|
|
### Declare Arrays, HashMaps, and Variables.
|
|
declare -a ary_security_pkgs=()
|
|
declare -r var_logfile="/root/.ciss/cdi/log/4510_accounts_hardening.log"
|
|
|
|
chroot_logger "${TARGET}${var_logfile}"
|
|
|
|
### Installing Google TOTP, Wordlists.
|
|
ary_security_pkgs=( "libpam-google-authenticator" "wamerican" "wbritish" "wfrench" "wngerman" )
|
|
chroot_script "${TARGET}" "
|
|
export INITRD=No
|
|
apt-get install -y --no-install-recommends --no-install-suggests ${ary_security_pkgs[*]} 2>&1 | tee -a ${var_logfile}
|
|
echo ExitCode of PIPESTATUS[0]: [\${PIPESTATUS[0]}] >> ${var_logfile}
|
|
"
|
|
|
|
### Preparing 2fa hardening.
|
|
install -d -m 0755 -o root -g root "${TARGET}/etc/ciss"
|
|
touch "${TARGET}/etc/ciss/2fa.users"
|
|
chmod 0640 "${TARGET}/etc/ciss/2fa.users"
|
|
|
|
### Keep 'tty1' active, disable the rest.
|
|
# shellcheck disable=SC2016
|
|
chroot_script "${TARGET}" '
|
|
systemctl unmask getty@tty1.service
|
|
systemctl enable getty@tty1.service
|
|
for t in tty2 tty3 tty4 tty5 tty6; do
|
|
systemctl mask getty@${t}.service
|
|
done
|
|
systemctl mask serial-getty@.service
|
|
'
|
|
|
|
chroot_script "${TARGET}" "
|
|
if [[ ! -f /etc/securetty ]]; then
|
|
touch /etc/securetty
|
|
chmod 0600 /etc/securetty
|
|
chown root:root /etc/securetty
|
|
fi
|
|
"
|
|
|
|
### Hardening file permissions.
|
|
chown root:root "${TARGET}/etc/passwd" "${TARGET}/etc/group"
|
|
chown root:shadow "${TARGET}/etc/shadow" "${TARGET}/etc/gshadow"
|
|
chmod 0644 "${TARGET}/etc/passwd" "${TARGET}/etc/group"
|
|
chmod 0640 "${TARGET}/etc/shadow" "${TARGET}/etc/gshadow"
|
|
chmod 0600 "${TARGET}/etc/security/access.conf"
|
|
|
|
### Hardening '/etc/login.defs'.
|
|
mkdir -p "${TARGET}/root/.ciss/cdi/backup/etc"
|
|
mv "${TARGET}/etc/login.defs" "${TARGET}/root/.ciss/cdi/backup/etc/login.defs.bak"
|
|
insert_header "${TARGET}/etc/login.defs"
|
|
insert_comments "${TARGET}/etc/login.defs"
|
|
cat "${VAR_SETUP_PATH}/includes/target/etc/login.defs" >> "${TARGET}/etc/login.defs"
|
|
|
|
### Hardening '/etc/security/pwquality.conf'.
|
|
mkdir -p "${TARGET}/root/.ciss/cdi/backup/etc/security"
|
|
mv "${TARGET}/etc/security/pwquality.conf" "${TARGET}/root/.ciss/cdi/backup/etc/security/pwquality.conf.bak"
|
|
insert_header "${TARGET}/etc/security/pwquality.conf"
|
|
insert_comments "${TARGET}/etc/security/pwquality.conf"
|
|
cat "${VAR_SETUP_PATH}/includes/target/etc/security/pwquality.cnf" >> "${TARGET}/etc/security/pwquality.conf"
|
|
|
|
### Hardening '/etc/security/access.conf'.
|
|
mv "${TARGET}/etc/security/access.conf" "${TARGET}/root/.ciss/cdi/backup/etc/security/access.conf.bak"
|
|
insert_header "${TARGET}/etc/security/access.conf"
|
|
insert_comments "${TARGET}/etc/security/access.conf"
|
|
cat "${VAR_SETUP_PATH}/includes/target/etc/security/access.cnf" >> "${TARGET}/etc/security/access.conf"
|
|
|
|
### Hardening password expiration; defaults to 16,384 days.
|
|
install -m 0700 -o root -g root "${VAR_SETUP_PATH}/includes/chroot/hooks/4510_password_expiration.hooks.sh" \
|
|
"${TARGET}/root/.ciss/cdi/hooks/4510_password_expiration.hooks.sh"
|
|
|
|
if ! chroot_script "${TARGET}" "/root/.ciss/cdi/hooks/4510_password_expiration.hooks.sh" "emergency"; then
|
|
do_log "warn" "file_only" "4510() Command: [chroot_script ${TARGET} /root/.ciss/cdi/hooks/4510_password_expiration.hooks.sh emergency] failed."
|
|
else
|
|
do_log "debug" "file_only" "4510() Command: [chroot_script ${TARGET} /root/.ciss/cdi/hooks/4510_password_expiration.hooks.sh emergency] successful."
|
|
fi
|
|
|
|
guard_dir && return 0
|
|
}
|
|
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
|