Last active
November 30, 2023 06:11
-
-
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`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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