Page 1 of 1

Reverse ssh

PostPosted: Tue Jan 29, 2013 2:27 pm
by NkC3ll
Hello guys,

I'm trying to write reverse ssh tunneling, but for some reason it doesn't run well !

If Someone know how to make right this sort of script, please help !

Thanks a lot ! :)

Re: Reverse ssh

PostPosted: Tue Jan 29, 2013 2:39 pm
by fashizzlepop
Post your code (in a gist or pastebin please) and we can look over it for you.

Re: Reverse ssh

PostPosted: Tue Jan 29, 2013 4:35 pm
by NkC3ll
Code: Select all
#!/bin/sh

REMOTE_HOST='the remote host'
PASS='the remote password'
REMOTE_PORT=5000

# $COMMAND is the command used to create the reverse ssh tunnel
COMMAND="ssh -q -N -R $REMOTE_PORT:localhost:22 the-remote-username@$REMOTE_HOST"

# Is the tunnel up? Perform two tests:

# 1. Check for relevant process ($COMMAND)
pgrep -f -x "$COMMAND" > /dev/null 2>&1 || $COMMAND

# 2. Test tunnel by looking at "netstat" output on $REMOTE_HOST
ssh $REMOTE_HOST netstat -an | egrep "tcp.*:$REMOTE_PORT.*LISTEN" > /dev/null 2>&1

if [ $? -ne 0 ] ; then
   pkill -f -x "$COMMAND"
   $COMMAND
fi


-- Wed Jan 30, 2013 12:24 pm --

fashizzlepop i have post it ...

Did you found the wrong syntax ??


Please help !