Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@gerardo-junior 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