SSH blocklist

IPs that tried to log in to this box over SSH and failed. Nobody but the owner logs in here, so every failed login is an unsolicited attempt. Plain text, one address per line, refreshed hourly, CC0.

https://box.pretzelassassin.com/blocklist.txt

Also mirrored daily, with history, at github.com/jessegonzalez/small-box-blocklist.

What's in it

Before you block anything

Make sure you can't lock yourself out: check that your own address isn't on the list, and keep a console (VNC, IPMI, provider panel) handy the first time. Every recipe below keeps the old list if the download fails or looks wrong, so an outage here never empties or breaks your firewall.

To check an address, put it in place of YOUR.IP.HERE. If the download fails, you get curl's error, not "not listed":

list=$(curl -fsS https://box.pretzelassassin.com/blocklist.txt) && {
  printf '%s\n' "$list" | grep -Fxq 'YOUR.IP.HERE' &&
    echo "you're listed" || echo "not listed"; }

The scripts below start by setting PATH, because cron's PATH lacks /usr/sbin, where nft, ipset and iptables live.

nftables (Debian 10+, Ubuntu 20.04+, recent RHEL)

Setup script, saved as /usr/local/sbin/smallbox-setup (chmod 755) and run once as root. It uses its own table, so it doesn't touch your existing rules. It's one atomic transaction, so it's safe to rerun and never leaves half a table behind; rerunning empties the sets until the next refresh.

#!/bin/sh
set -eu
export PATH="/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
# create-then-delete makes the delete safe on a first run
nft -f - <<'EOF'
table inet smallbox
delete table inet smallbox
table inet smallbox {
  set v4 {
    type ipv4_addr
    flags interval
  }
  set v6 {
    type ipv6_addr
    flags interval
  }
  chain input {
    type filter hook input priority -5; policy accept;
    ip saddr @v4 drop
    ip6 saddr @v6 drop
  }
}
EOF

Refresh script, saved as /usr/local/sbin/smallbox-blocklist (chmod 755). The flush and reload happen in one atomic nft -f transaction:

#!/bin/sh
set -eu
export PATH="/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
url=https://box.pretzelassassin.com/blocklist.txt
tmp=$(mktemp); trap 'rm -f "$tmp"' EXIT
# a reboot wipes the table; recreate it if missing
nft list table inet smallbox >/dev/null 2>&1 ||
  /usr/local/sbin/smallbox-setup
# keep the old list on failure
curl -fsS --max-time 30 "$url" -o "$tmp" || exit 0
v4=$(grep -E '^[0-9]{1,3}(\.[0-9]{1,3}){3}$' "$tmp" |
  paste -sd, -)
v6=$(grep -E '^[0-9a-fA-F:]+:[0-9a-fA-F:]*$' "$tmp" |
  paste -sd, -)
# empty or garbled: change nothing
[ -n "$v4$v6" ] || exit 0
{
  echo "flush set inet smallbox v4"
  echo "flush set inet smallbox v6"
  [ -z "$v4" ] ||
    echo "add element inet smallbox v4 { $v4 }"
  [ -z "$v6" ] ||
    echo "add element inet smallbox v6 { $v6 }"
} | nft -f -

The table doesn't survive a reboot on its own, so the refresh script runs the setup script whenever the table is missing.

ipset + iptables (older systems)

One-time setup (the refresh script below also recreates this after a reboot):

ipset create smallbox hash:ip -exist
iptables -I INPUT -m set --match-set smallbox src -j DROP

Refresh script, IPv4 only, saved as /usr/local/sbin/smallbox-blocklist (chmod 755). It builds a new set and swaps it in, so there's no moment without protection:

#!/bin/sh
set -eu
export PATH="/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
url=https://box.pretzelassassin.com/blocklist.txt
ip4='^[0-9]{1,3}(\.[0-9]{1,3}){3}$'
tmp=$(mktemp); trap 'rm -f "$tmp"' EXIT
# a reboot wipes the set and the rule; recreate them
ipset create smallbox hash:ip -exist
if ! iptables -C INPUT -m set --match-set smallbox \
    src -j DROP 2>/dev/null; then
  iptables -I INPUT -m set --match-set smallbox \
    src -j DROP
fi
# keep the old list on failure
curl -fsS --max-time 30 "$url" -o "$tmp" || exit 0
grep -qE "$ip4" "$tmp" || exit 0
ipset create smallbox-new hash:ip -exist
ipset flush smallbox-new
grep -E "$ip4" "$tmp" |
  sed 's/^/add smallbox-new /' |
  ipset restore -exist
ipset swap smallbox-new smallbox
ipset destroy smallbox-new

Run it hourly

Save this as /etc/cron.d/smallbox-blocklist. It's the same for both recipes, since each refresh script recreates what a reboot wipes. Change 23 to any minute you like, so not everyone fetches at once. The @reboot line covers the gap until the first hourly run. The file must end with a newline (the Copy button adds one).

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
23 * * * * root /usr/local/sbin/smallbox-blocklist
@reboot root sleep 30; /usr/local/sbin/smallbox-blocklist

Just looking

curl -s https://box.pretzelassassin.com/blocklist.txt | grep -Ev '^(#|$)' | wc -l