V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 2m7s

Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
2025-10-21 14:29:32 +01:00
parent 13b5f09e24
commit aa49722611
6 changed files with 219 additions and 96 deletions

View File

@@ -62,14 +62,13 @@ EOF
### fail2ban ufw aggressive mode, one attempt for jumphost configuration.
cat << EOF >> "${var_target}/etc/fail2ban/jail.d/ciss-default.conf"
[DEFAULT]
usedns = yes
# 127.0.0.1/8 IPv4 loopback range (local host)
# ::1/128 IPv6 loopback
# fe80::/10 IPv6 link-local (on-link only; NDP/RA/DAD)
# fc00::/7 IPv6 ULA (private LAN addresses)
# ff00::/8 IPv6 multicast (not an unicast host)
# ::/128 IPv6 unspecified (all zeros; never a real peer)
ignoreip = 127.0.0.1/8 ::1/128 fe80::/10 fc00::/7 ff00::/8 ::/128
dbpurgeage = 384d
# 127.0.0.1/8 - IPv4 loopback range (local host)
# ::1/128 - IPv6 loopback
# fe80::/10 - IPv6 link-local (on-link only; NDP/RA/DAD)
# ff00::/8 - IPv6 multicast (not an unicast host)
# ::/128 - IPv6 unspecified (all zeros; never a real peer)
ignoreip = 127.0.0.1/8 ::1/128 fe80::/10 ff00::/8 ::/128
# ${VAR_FINAL_FQDN}
${VAR_FINAL_IPV4}
EOF
@@ -94,53 +93,74 @@ EOF
fi
cat << EOF >> "${var_target}/etc/fail2ban/jail.d/ciss-default.conf"
maxretry = 3
findtime = 1d
bantime = 1h
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 16d
bantime.overalljails = true
bantime.rndtime = 877s
usedns = yes
[recidive]
enabled = true
filter = recidive
logpath = /var/log/fail2ban/fail2ban.log*
banaction = iptables-allports
maxretry = 3
findtime = 16d
banaction = ufw[blocktype=deny]
bantime = 8d
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 96d
bantime.multipliers = 1, 2, 4, 8
bantime.maxtime = 128d
bantime.multipliers = 1 2 4 8 16
bantime.overalljails = true
bantime.rndtime = 877s
filter = recidive
findtime = 16d
logpath = /var/log/fail2ban/fail2ban.log*
maxretry = 3
[sshd]
enabled = true
backend = systemd
bantime = 1h
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 16d
bantime.multipliers = 1 2 4 8 16 32 64 128 256 384
bantime.overalljails = true
bantime.rndtime = 877s
filter = sshd
mode = normal
findtime = 16m
mode = aggressive
port = ${VAR_SSH_PORT}
protocol = tcp
logpath = /var/log/auth.log
maxretry = 4
#
# ufw aggressive approach:
# CISS aggressive approach:
# Any valid client communicating with our server should be going directly to the service ports opened in ufw (ssh, 80, ...).
# Any client touching other ports is treated as malicious and therefore should be blocked access to ALL ports after 1 attempt.
# There is no necessity to ping our servers excessively. Any client pinging us more than 1 times will be blocked.
#
[icmp]
enabled = true
banaction = ufw[blocktype=deny]
bantime = 1h
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 16d
bantime.multipliers = 1 2 4 8 16 32 64 128 256 384
bantime.overalljails = true
bantime.rndtime = 877s
filter = ciss.icmp
findtime = 16m
logpath = /var/log/ufw.log
maxretry = 1
[ufw]
enabled = true
banaction = ufw[blocktype=deny]
bantime = 1h
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 16d
bantime.multipliers = 1 2 4 8 16 32 64 128 256 384
bantime.overalljails = true
bantime.rndtime = 877s
filter = ciss.ufw
action = iptables-allports
findtime = 16m
logpath = /var/log/ufw.log
maxretry = 1
@@ -152,14 +172,13 @@ EOF
### fail2ban ufw aggressive mode, 32 attempts for NO jumphost configuration.
cat << EOF >> "${var_target}/etc/fail2ban/jail.d/ciss-default.conf"
[DEFAULT]
usedns = yes
# 127.0.0.1/8 IPv4 loopback range (local host)
# ::1/128 IPv6 loopback
# fe80::/10 IPv6 link-local (on-link only; NDP/RA/DAD)
# fc00::/7 IPv6 ULA (private LAN addresses)
# ff00::/8 IPv6 multicast (not an unicast host)
# ::/128 IPv6 unspecified (all zeros; never a real peer)
ignoreip = 127.0.0.1/8 ::1/128 fe80::/10 fc00::/7 ff00::/8 ::/128
dbpurgeage = 384d
# 127.0.0.1/8 - IPv4 loopback range (local host)
# ::1/128 - IPv6 loopback
# fe80::/10 - IPv6 link-local (on-link only; NDP/RA/DAD)
# ff00::/8 - IPv6 multicast (not an unicast host)
# ::/128 - IPv6 unspecified (all zeros; never a real peer)
ignoreip = 127.0.0.1/8 ::1/128 fe80::/10 ff00::/8 ::/128
# ${VAR_FINAL_FQDN}
${VAR_FINAL_IPV4}
EOF
@@ -172,55 +191,76 @@ EOF
fi
cat << EOF >> "${var_target}/etc/fail2ban/jail.d/ciss-default.conf"
maxretry = 3
findtime = 1d
bantime = 1h
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 16d
bantime.overalljails = true
bantime.rndtime = 877s
usedns = yes
[recidive]
enabled = true
filter = recidive
logpath = /var/log/fail2ban/fail2ban.log*
banaction = iptables-allports
maxretry = 3
findtime = 16d
banaction = ufw[blocktype=deny]
bantime = 8d
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 96d
bantime.multipliers = 1, 2, 4, 8
bantime.maxtime = 128d
bantime.multipliers = 1 2 4 8 16
bantime.overalljails = true
bantime.rndtime = 877s
filter = recidive
findtime = 16d
logpath = /var/log/fail2ban/fail2ban.log*
maxretry = 3
[sshd]
enabled = true
backend = systemd
bantime = 1h
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 16d
bantime.multipliers = 1 2 4 8 16 32 64 128 256 384
bantime.overalljails = true
bantime.rndtime = 877s
filter = sshd
mode = normal
findtime = 16m
mode = aggressive
port = ${VAR_SSH_PORT}
protocol = tcp
logpath = /var/log/auth.log
maxretry = 4
#
# ufw aggressive approach:
# CISS aggressive approach:
# Any valid client communicating with our server should be going directly to the service ports opened in ufw (ssh, 80, ...).
# Any client touching other ports is treated as malicious and therefore should be blocked access to ALL ports after 8 attempts.
# Any client touching other ports is treated as malicious and therefore should be blocked access to ALL ports after 3 attempts.
# There is no necessity to ping our servers excessively. Any client pinging us more than 3 times will be blocked.
#
[icmp]
enabled = true
banaction = ufw[blocktype=deny]
bantime = 1h
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 16d
bantime.multipliers = 1 2 4 8 16 32 64 128 256 384
bantime.overalljails = true
bantime.rndtime = 877s
filter = ciss.icmp
findtime = 16m
logpath = /var/log/ufw.log
maxretry = 3
[ufw]
enabled = true
banaction = ufw[blocktype=deny]
bantime = 1h
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 16d
bantime.multipliers = 1 2 4 8 16 32 64 128 256 384
bantime.overalljails = true
bantime.rndtime = 877s
filter = ciss.ufw
action = iptables-allports
findtime = 16m
logpath = /var/log/ufw.log
maxretry = 4
maxretry = 3
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=conf
EOF
@@ -234,13 +274,24 @@ EOF
fi
insert_header "${var_target}/etc/fail2ban/filter.d/ciss.icmp.conf"
insert_comments "${var_target}/etc/fail2ban/filter.d/ciss.icmp.conf"
cat << EOF >> "${var_target}/etc/fail2ban/filter.d/ciss.icmp.conf"
[Definition]
# Generic ICMP/ICMPv6 blocks
failregex = ^.*UFW (?:BLOCK|REJECT).*?\bSRC=<HOST>\b.*?\bPROTO=ICMP\b.*$
^.*UFW (?:BLOCK|REJECT).*?\bSRC=<HOST>\b.*?\bPROTO=ICMPv6\b.*$
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=conf
EOF
insert_header "${var_target}/etc/fail2ban/filter.d/ciss.ufw.conf"
insert_comments "${var_target}/etc/fail2ban/filter.d/ciss.ufw.conf"
cat << EOF >> "${var_target}/etc/fail2ban/filter.d/ciss.ufw.conf"
[Definition]
failregex = \[UFW BLOCK\].+SRC=<HOST> DST
ignoreregex =
# Match UFW BLOCK/REJECT with a source IP and *any* port field (SPT or DPT), protocol may be missing.
failregex = ^.*UFW (?:BLOCK|REJECT).*?\bSRC=<HOST>\b.*?(?:\bDPT=\d+\b|\bSPT=\d+\b).*$
ignoreregex =
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=conf
EOF
@@ -273,11 +324,11 @@ EOF
cat << 'EOF' >> "${var_target}/etc/fail2ban/fail2ban.local"
[Definition]
logtarget = /var/log/fail2ban/fail2ban.log
logtarget = /var/log/fail2ban/fail2ban.log
[Database]
# Keep entries for at least 384 days to cover recidive findtime.
dbpurgeage = 384d
dbpurgeage = 384d
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=conf
EOF
@@ -287,19 +338,23 @@ EOF
cp "${var_target}/etc/logrotate.d/fail2ban" "${var_target}/root/.ciss/cdi/backup/etc/logrotate.d/fail2ban.bak"
cat << EOF >| "${var_target}/etc/logrotate.d/fail2ban"
/var/log/fail2ban/fail2ban.log {
daily
rotate 384
compress
# Do not rotate if empty
maxage 384
notifempty
dateext
dateyesterday
compress
compresscmd /usr/bin/zstd
compressext .zst
compressoptions -20
uncompresscmd /usr/bin/unzstd
delaycompress
shred
missingok
postrotate
fail2ban-client flushlogs 1>/dev/null
endscript
# If fail2ban runs as non-root it still needs to have write access
# to logfiles.
# create 640 fail2ban adm

View File

@@ -36,27 +36,49 @@ hardening_logrotate() {
cat << EOF >> "${var_target}/etc/logrotate.conf"
# See "man logrotate" for details. Global options do not affect preceding include directives.
# rotate log files daily
# Rotate log files daily
daily
# keep 384 daily worth of backlogs
# Keep 384 daily worth of backlogs.
rotate 384
# hard cap: delete rotated logs older than 384 days
# Hard cap: delete rotated logs older than 384 days.
maxage 384
# create new (empty) log files after rotating old ones
# Do not rotate the log if it is empty (this overrides the ifempty option).
notifempty
# Create new (empty) log files after rotating old ones.
create
# use date as a suffix of the rotated file
# Use date as a suffix of the rotated file.
dateext
# gzip older rotations
# Use yesterday's instead of today's date to create the dateext extension, so that the rotated log file has a date in its name
# that is the same as the timestamps within it.
dateyesterday
# Enable compression
compress
# keep the most recent rotation uncompressed for one cycle
# Use zstd instead of gzip.
compresscmd /usr/bin/zstd
# File extension for compressed logs.
compressext .zst
# Set zstd level 3 (default).
compressoptions -20
# How to decompress for 'logrotate -d' or similar.
uncompresscmd /usr/bin/unzstd
# Keep the most recent rotation uncompressed for one cycle.
delaycompress
# Delete log files using shred -u instead of unlink().
shred
# packages drop log rotation information into this directory
include /etc/logrotate.d