Skip to content

Instantly share code, notes, and snippets.

@gerardo-junior
Last active September 3, 2020 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerardo-junior/00a670bb060ab2aa5b6c6a78916bd66e to your computer and use it in GitHub Desktop.
Save gerardo-junior/00a670bb060ab2aa5b6c6a78916bd66e to your computer and use it in GitHub Desktop.
Add suport DNS srv record type to ssh client (https://www.ietf.org/rfc/rfc2782.txt)
#!/bin/bash
target_host=$1
if [ ! -z "$2" ];then
target_port=$2
else
target_port="22"
fi
while read record;do
if [ ! -z "$record" ];then
host=$(echo $record | awk '{print $NF}')
port=$(echo $record | awk '{print $(NF-1)}')
if timeout 1 bash -c "cat < /dev/null > /dev/tcp/$host/$port" &> /dev/null;then
target_host=$host
target_port=$port
break
fi
fi
done < <(dig +short SRV _ssh._tcp.$target_host @$(dig +short NS $(echo $target_host | awk -F '.' '{print $(NF-1)"."$NF}') | head -n1) | sort -nk1)
socat STDIO TCP:$target_host:$target_port 2> /dev/null
@gerardo-junior
Copy link
Author

gerardo-junior commented Sep 3, 2020

just add -o ProxyCommand=sshsrv-proxy-command.sh %h %p on ssh command

or edit ~/.ssh/config file and put:

Host *.DOMAIN
ProxyCommand=sshsrv-proxy-command.sh %h %p

there are two dependencies to run the script: socat and dig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment