V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 56s
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 56s
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
85
func/cdi_4400_hardening/4470_hardening_ufw.sh
Normal file
85
func/cdi_4400_hardening/4470_hardening_ufw.sh
Normal file
@@ -0,0 +1,85 @@
|
||||
#!/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
|
||||
|
||||
#######################################
|
||||
# OpenSSL library defaults (system-wide), TLSv1.2-, TLSv1.3-, AES-256-only;
|
||||
# Globals:
|
||||
# TARGET
|
||||
# VAR_SETUP_PATH
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# 0: on success
|
||||
#######################################
|
||||
hardening_ufw() {
|
||||
### Declare Arrays, HashMaps, and Variables.
|
||||
declare -r var_logfile="/root/.ciss/cdi/log/4470_hardening_ufw.log"
|
||||
|
||||
chroot_logger "${TARGET}${var_logfile}"
|
||||
|
||||
if [[ ! -f "${TARGET}/var/log/ufw.log" ]]; then
|
||||
touch "${TARGET}/var/log/ufw.log"
|
||||
chmod 640 "${TARGET}/var/log/ufw.log"
|
||||
fi
|
||||
|
||||
chroot_script "${TARGET}" "
|
||||
ufw --force reset
|
||||
ufw logging medium
|
||||
ufw default deny incoming
|
||||
ufw default ${VAR_UFW_OUT} outgoing
|
||||
ufw default deny forward
|
||||
ufw allow in ${VAR_SSH_PORT}/tcp comment 'Incoming SSH'
|
||||
ufw limit ${VAR_SSH_PORT}/tcp comment 'Incoming SSH'
|
||||
"
|
||||
|
||||
### Ensure that a standard set of the most commonly used ports are open if a default-'deny'-outbound policy is selected.
|
||||
if [[ "${VAR_UFW_OUT}" = "deny" ]]; then
|
||||
|
||||
chroot_script "${TARGET}" "
|
||||
ufw allow out 21/tcp comment 'Outgoing FTP'
|
||||
ufw allow out 22/tcp comment 'Outgoing SSH'
|
||||
ufw allow out 25/tcp comment 'Outgoing SMTP'
|
||||
ufw allow out 53/tcp comment 'Outgoing DNS'
|
||||
ufw allow out 80/tcp comment 'Outgoing HTTP'
|
||||
ufw allow out 123/tcp comment 'Outgoing NTP'
|
||||
ufw allow out 143/tcp comment 'Outgoing IMAP'
|
||||
ufw allow out 443/tcp comment 'Outgoing HTTPS'
|
||||
ufw allow out 465/tcp comment 'Outgoing SMTPS'
|
||||
ufw allow out 587/tcp comment 'Outgoing SMTPS'
|
||||
ufw allow out 993/tcp comment 'Outgoing IMAPS'
|
||||
ufw allow out 4460/tcp comment 'Outgoing NTS'
|
||||
ufw allow out ${VAR_SSH_PORT}/tcp comment 'Outgoing SSH'
|
||||
ufw allow out 53/udp comment 'Outgoing DNS'
|
||||
ufw allow out 123/udp comment 'Outgoing NTP'
|
||||
ufw allow out 443/udp comment 'Outgoing QUIC'
|
||||
ufw allow out 853/udp comment 'Outgoing DoQ'
|
||||
"
|
||||
|
||||
fi
|
||||
|
||||
### Allowing ICMP IPv4 outgoing per default.
|
||||
sed -i "/# ok icmp code for FORWARD/i \# ok icmp codes for OUTPUT" "${TARGET}/etc/ufw/before.rules"
|
||||
sed -i "/# ok icmp code for FORWARD/i \-A ufw-before-output -p icmp --icmp-type destination-unreachable -j ACCEPT" "${TARGET}/etc/ufw/before.rules"
|
||||
sed -i "/# ok icmp code for FORWARD/i \-A ufw-before-output -p icmp --icmp-type time-exceeded -j ACCEPT" "${TARGET}/etc/ufw/before.rules"
|
||||
sed -i "/# ok icmp code for FORWARD/i \-A ufw-before-output -p icmp --icmp-type parameter-problem -j ACCEPT" "${TARGET}/etc/ufw/before.rules"
|
||||
sed -i "/# ok icmp code for FORWARD/i \-A ufw-before-output -p icmp --icmp-type echo-request -j ACCEPT" "${TARGET}/etc/ufw/before.rules"
|
||||
|
||||
chroot_script "${TARGET}" "echo 'y' | ufw enable 2>&1"
|
||||
|
||||
chroot_script "${TARGET}" "
|
||||
ufw status verbose >> ${var_logfile}
|
||||
"
|
||||
guard_dir && return 0
|
||||
}
|
||||
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
|
||||
Reference in New Issue
Block a user