Install-Skript by CODEX
This commit is contained in:
1 parent
65a84206a5
commit
b404cfbdf3
4 files changed
+158
-30
No files matched your search
Regular → Executable
+86
-18
@@ -1,19 +1,87 @@
|
||||
# Chain anlegen falls sie nicht existiert
|
||||
iptables -L permanent-bans -n >/dev/null 2>&1 || iptables -N permanent-bans
|
||||
echo "Flushing sets..."
|
||||
iptables -F permanent-bans
|
||||
iptables -C INPUT -j permanent-bans 2>/dev/null || \
|
||||
iptables -I INPUT 1 -j permanent-bans
|
||||
ipset destroy ci-badguys
|
||||
ipset create ci-badguys hash:ip
|
||||
ipset destroy bca-badguys
|
||||
ipset create bca-badguys hash:net
|
||||
echo "Making sets..."
|
||||
/etc/scripts/make_badguys_set.sh
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# ci-badboys Set:
|
||||
echo "Setting up ci-badguys"
|
||||
iptables -A permanent-bans -m set --match-set ci-badguys src -j DROP
|
||||
# bca-badboys Set:
|
||||
echo "Setting up bca-badguys"
|
||||
iptables -A permanent-bans -m set --match-set bca-badguys src -j DROP
|
||||
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
if (( EUID != 0 )); then
|
||||
echo 'Die Sperrlisten-Synchronisierung benötigt Root-Rechte.' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exec 9>/run/bca-blocked-ips.lock
|
||||
flock --exclusive 9
|
||||
|
||||
workdir=$(mktemp -d)
|
||||
trap 'rm -rf -- "$workdir"' EXIT
|
||||
chain=permanent-bans
|
||||
|
||||
update_set() (
|
||||
set_name=$1
|
||||
set_type=$2
|
||||
url=$3
|
||||
staging="${set_name}-staging"
|
||||
|
||||
curl --disable --fail --silent --show-error --location \
|
||||
--proto '=https' --proto-redir '=https' --connect-timeout 10 \
|
||||
--max-time 45 --max-filesize 4194304 --output "$workdir/list" "$url" || exit 1
|
||||
|
||||
python3 - "$workdir/list" "$staging" "$set_type" >"$workdir/restore" <<'PY' || exit 1
|
||||
import ipaddress
|
||||
import sys
|
||||
|
||||
path, staging, set_type = sys.argv[1:]
|
||||
entries = set()
|
||||
with open(path, encoding="utf-8") as source:
|
||||
for number, line in enumerate(source, 1):
|
||||
value = line.partition("#")[0].strip()
|
||||
if not value:
|
||||
continue
|
||||
try:
|
||||
if set_type == "hash:net" and "/" in value:
|
||||
address, prefix = value.split("/", 1)
|
||||
if not prefix.isascii() or not prefix.isdecimal() or int(prefix) == 0:
|
||||
raise ValueError
|
||||
entry = ipaddress.IPv4Network(f"{address}/{prefix}", strict=False)
|
||||
else:
|
||||
entry = ipaddress.IPv4Address(value)
|
||||
except ValueError:
|
||||
sys.exit(f"Ungültiger IPv4-Eintrag in Zeile {number}.")
|
||||
entries.add(str(entry))
|
||||
|
||||
if not entries:
|
||||
sys.exit("Die Sperrliste enthält keine Einträge.")
|
||||
|
||||
for entry in sorted(entries):
|
||||
print(f"add {staging} {entry}")
|
||||
PY
|
||||
|
||||
# Reste eines abgebrochenen Laufs entfernen, bevor das Set befüllt wird.
|
||||
ipset destroy "$staging" 2>/dev/null || true
|
||||
ipset create "$staging" "$set_type" family inet || exit 1
|
||||
trap 'ipset destroy "$staging"' EXIT
|
||||
ipset restore <"$workdir/restore" || exit 1
|
||||
ipset swap "$staging" "$set_name" || exit 1
|
||||
)
|
||||
|
||||
ipset -exist create bca-badguys hash:net family inet
|
||||
ipset -exist create ci-badguys hash:ip family inet
|
||||
iptables -w 10 -n -L "$chain" >/dev/null 2>&1 || iptables -w 10 -N "$chain"
|
||||
|
||||
for set_name in bca-badguys ci-badguys; do
|
||||
iptables -w 10 -C "$chain" -m set --match-set "$set_name" src -j DROP 2>/dev/null ||
|
||||
iptables -w 10 -A "$chain" -m set --match-set "$set_name" src -j DROP
|
||||
done
|
||||
iptables -w 10 -C INPUT -j "$chain" 2>/dev/null ||
|
||||
iptables -w 10 -I INPUT 1 -j "$chain"
|
||||
|
||||
status=0
|
||||
if ! update_set bca-badguys hash:net \
|
||||
https://git.bcanet.tech/Lukas/BCA-Blocked-IPs/raw/branch/main/bca-banned-ips.txt; then
|
||||
echo 'Die BCA-Sperrliste konnte nicht aktualisiert werden.' >&2
|
||||
status=1
|
||||
fi
|
||||
if ! update_set ci-badguys hash:ip https://cinsscore.com/list/ci-badguys.txt; then
|
||||
echo 'Die CINS-Sperrliste konnte nicht aktualisiert werden.' >&2
|
||||
status=1
|
||||
fi
|
||||
exit "$status"
|
||||
Reference in new issue
Block a user