The command that gets run when the (correct) knock comes in is an ipfw command:
/sbin/ipfw add 01021 allow tcp from %IP% to 10.0.0.10 22,443 setup
... so now the knocking IP can see TCP 22 and 443 (and nothing else).I then have a cron job that runs every night at midnight that deletes those rules:
0 0 * * * /sbin/ipfw delete 01021
... so I am required to knock daily.The following is a little lame, but I want to see who has knocked so far today (should just be me and my own IPs) so I do this every minute:
* * * * * /sbin/ipfw show|/usr/bin/grep ^01021 | awk '{print $7}' > /tmp/.knock_list
... and then cat that list to myself every time I log in ...Knocking a poet is bound to get you into trouble. Poets fight back, and hard. Just don't do it.
* Does not bind to sockets
* Is not written in C
* Prevents replay attacks
* The only code that runs as root is just tailing kern.log and is like 15 lines
It probably needs to roll from SHA1 to SHA256 and Python2 to Python3, but otherwise seems sound.
Edit: It appears there may be an active fork here: https://github.com/indyprime/knockknock
Still digging through to see if the encrypt-then-authenticate change made it into this version.
Edit 2: It looks like it still uses authenticate-then-encrypt. I sent an email to the maintainer of that fork, we'll see what happens. ^__^
How I set it up specifically: https://peekread.info/tech/20190513-fwknop/
https://www.howtogeek.com/105693/how-to-knock-into-your-netw...
I wrote up how having a server on the internet is scary now (http://redgreenrepeat.com/2020/03/20/why-you-should-secure-y...) and how to protect it (http://redgreenrepeat.com/2020/04/10/how-to-secure-your-serv...)
One thing I didn't get into more was port knocking/knockd as there were not many resources for it.
I'd love to learn more about how you have used knockd.