SSH Proxy Commands that use `sed`
journal.paul.querna.org
journal.paul.querna.org
ProxyCommand ssh -aY bastion 'nc -w 900 `x="%h"; echo ${x%%.bast}` %p' # dark magicks for hopping hosts. first version
# (you'll need to specify target user name though)
Host *+*
VerifyHostKeyDNS=no
ProxyCommand ssh $(echo %h | sed 's/^\([^+]*\).*$/\1/') nc $(sed -n '/^Host[ \t]*\('$(echo %h | sed 's/^.*+\([^+]*\)$/\1/')'\)$/,/^$/{/^.*HostName[ \t]*/{s///; s/[ \t]*$//; h}}; ${x; /./{p; b}; s/^/'$(echo %h | sed 's/^.*+\([^+]*\)$/\1/')'/p}' ~/.ssh/config) $(sed -n '/^Host[ \t]*\('$(echo %h | sed 's/^.*+\([^+]*\)$/\1/')'\)$/,/^$/{/^.*Port[^0-9]*/{s///;s/[ \t]*$//;h;};};${x;/./{p;q;};s/^/22/p;}' ~/.ssh/config)http://en.wikibooks.org/wiki/OpenSSH/Cookbook/Proxies_and_Ju...
If you're being paranoid, you can also break this like: ssh -v 'foo;bar.bast'
Still, the only way I see this being any kind of "attack surface" is if an attacker could control the hostname you're connecting to, and I'll bet there are much naughtier thing possible in that case.
$ ssh localhost -o ProxyCommand="ssh localhost 'pstree -a \$PPID >&2 ; nc %h %p'"
sshd
`-bash -c pstree -a $PPID >&2 ; nc localhost 22
`-pstree -a 6703
Bash invoked this way will be non-interactive. Often bashrc will test "$PS1" to bail early in this case, but the point remains that it does run. I also tried my command with echos before and after that test in my bashrc to confirm what happens.It will never touch any part of the network, or handle any untrusted input. So this is not a concern.