Skip to content

Instantly share code, notes, and snippets.

@winguse
Last active November 30, 2023 06:11
Show Gist options
  • Save winguse/f604752c83060b49eae1af14e29b1867 to your computer and use it in GitHub Desktop.
Save winguse/f604752c83060b49eae1af14e29b1867 to your computer and use it in GitHub Desktop.
open your ssh door by send a UDP package `echo zhi-ma-kai-men | nc -u server-ip 54321`
#!/usr/bin/env bash
OPEN_DOOR_UDP_PORT=54321
OPEN_DOOR_TOKEN=zhi-ma-kai-men
SSH_ALLOW_TIMEOUT=10
IP_SET_MAX=8
SSH_IP_SET=ssh-ip-set
ipset create $SSH_IP_SET hash:ip \
timeout $SSH_ALLOW_TIMEOUT \
maxelem $IP_SET_MAX \
counters
iptables \
-A INPUT \
-p udp --dport $OPEN_DOOR_UDP_PORT \
-m string --algo kmp --string $OPEN_DOOR_TOKEN \
-j SET \
--add-set $SSH_IP_SET src
iptables \
-A INPUT \
-p tcp --dport 22 \
-m set --match-set $SSH_IP_SET src \
-j ACCEPT
iptables \
-A INPUT \
-p tcp --dport 22 \
-j DROP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment