Created
December 26, 2024 11:10
-
-
Save dimkr/f2a46992b72792d2125e2af82254f48e to your computer and use it in GitHub Desktop.
Poor man's port knocking with iptables
This file contains hidden or 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
for x in iptables ip6tables; do | |
$x -N ssh | |
$x -A INPUT -p tcp --dport 22 -j ssh | |
$x -A ssh -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT | |
$x -A ssh -p tcp --sport 1234 -m recent --name knock1 --set -j DROP | |
$x -A ssh -m conntrack --ctstate NEW -m recent --name knock1 \! --rcheck --seconds 20 -j DROP | |
$x -A ssh -p tcp --sport 2345 -m recent --name knock2 --set -j DROP | |
$x -A ssh -m conntrack --ctstate NEW -m recent --name knock2 \! --rcheck --seconds 20 -j DROP | |
$x -A ssh -p tcp --sport 3456 -m recent --name knock3 --set -j DROP | |
$x -A ssh -m conntrack --ctstate NEW -m recent --name knock3 \! --rcheck --seconds 20 -j DROP | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment