-
-
Save arcticlinux/564bb5c2de8217adfe5c to your computer and use it in GitHub Desktop.
Port Knocking SSH wrapper
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
#!/bin/bash | |
# Author: Michael Best <[email protected]> | |
# Designed to work with the Shorewall Port Knocking Implementation | |
# http://shorewall.net/PortKnocking.html | |
COMMAND="ssh" | |
PORT=1600 | |
TIMEOUT=2 | |
function USAGE { | |
echo -e "Usage for $0\n" | |
echo -e "By default this program knocks port 1600 with tcping, and then calls ssh" | |
echo -e "Example: kssh [email protected]\n " | |
echo "Options:" | |
echo "-c Sets the default ssh command, default ssh (ssh, mosh, etc)" | |
echo "-p Sets the port knocking port, default 1600" | |
echo "-t Sets the timeout value on tcping, default 2" | |
echo "-h Displays usage" | |
exit 1 | |
} | |
while getopts :c:p:t:h OPT; do | |
case $OPT in | |
c) # set ssh command | |
COMMAND=$OPTARG | |
;; | |
p) # set knocking port | |
PORT=$OPTARG | |
;; | |
t) # set timeout | |
TIMEOUT=$OPTARG | |
;; | |
h) #show usage | |
USAGE | |
;; | |
\?) | |
echo -e "\nInvalid Option -$OPTARG\n" | |
USAGE | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
HOST=`echo $1 | sed 's#.*@##'` | |
echo "knocking $HOST $PORT, $COMMAND $*" | |
tcping -q -t $TIMEOUT $HOST $PORT &> /dev/null | |
$COMMAND $* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment