From 396b18a36a8ee72d347de9af5383f2a8a91c8e67 Mon Sep 17 00:00:00 2001 From: Maria Lisina Date: Thu, 20 Aug 2026 21:01:58 +0500 Subject: Add old scripts Signed-off-by: Maria Lisina --- nft/accept-filter.sh | 31 ++++++++++++++++++++++++++++++ nft/asn-filter.sh | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100755 nft/accept-filter.sh create mode 100755 nft/asn-filter.sh (limited to 'nft') diff --git a/nft/accept-filter.sh b/nft/accept-filter.sh new file mode 100755 index 0000000..5dfe5dc --- /dev/null +++ b/nft/accept-filter.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# +# Copyright (C) 2025-2026 Maria Lisina +# SPDX-License-Identifier: Apache-2.0 +# +# nftables accept filter + +set -e + +cat << EOF > /etc/nftables.nft +#!/usr/sbin/nft -f + +flush ruleset + +table inet filter { + chain input { + type filter hook input priority 0; policy accept; + } + + chain forward { + type filter hook forward priority 0; policy accept; + } + + chain output { + type filter hook output priority 0; policy accept; + } +} + +include "/var/lib/nftables/*.nft" +include "/etc/nftables.d/*.nft" +EOF diff --git a/nft/asn-filter.sh b/nft/asn-filter.sh new file mode 100755 index 0000000..2880d30 --- /dev/null +++ b/nft/asn-filter.sh @@ -0,0 +1,53 @@ +#!/bin/sh +# +# Copyright (C) 2025-2026 Maria Lisina +# SPDX-License-Identifier: Apache-2.0 +# +# nftables ASN filter + +set -e + +if [ ${#} -eq 0 ] +then + echo "No ASNs specified!" + exit 1 +fi + +__blocked_asns="${@}" +shift ${#} + +for __asn in ${__blocked_asns} +do + __asn_ips="$(curl --get --silent "https://2ip.io/as/${__asn}.json" | jq -r '.prefixes[].ipv4Prefix')" + set -- ${@} ${__asn_ips} +done + +while [ ${#} -gt 0 ] +do + _asn_ips="$(printf "%s%s" "${_asn_ips}" "${1}")" + + if [ ${#} -gt 1 ] + then + _asn_ips="$(printf "%s%c" "${_asn_ips}" ",")" + fi + + shift +done + +cat << EOF > /etc/nftables.d/asn_filter.nft +#!/usr/sbin/nft -f + +table inet asn_filter { + set blocked_addresses { + typeof ip saddr + flags interval + auto-merge + elements = { ${_asn_ips} } + } + + chain input { + type filter hook input priority 0; + ip saddr @blocked_addresses drop + } +} +EOF -- cgit v1.2.3