Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Using SSH via SOCKS5 Proxy (Solution Posted)

by cmv (Chaplain)
on Sep 10, 2007 at 15:43 UTC ( #638101=perlquestion: print w/ replies, xml ) Need Help??
cmv has asked for the wisdom of the Perl Monks concerning the following question:

I currently setup a SSH session via a SOCKS5 proxy using the OpenSSH command:
ssh -o "connect -5 -S proxy.socks5.ip.name %h %p" target.ip.name
Here's where I got connect.c to compile for my platform:
http://www.meadowy.org/~gotoh/projects/connect

Now, I want to have my existing perl programs that use Net::SSH::Perl, to be able to use a SOCKS5 proxy, if needed. What is the best way to make this happen?

My current thought is to patch Net::SSH::Perl to use Net::SOCKS. Is there a better/easier/faster way?

Thanks
-Craig

Update: Based on queries generated from this thread, I've posted my solution at Using SOCKS via Net::SSH::Perl. Comments welcome.

Comment on Using SSH via SOCKS5 Proxy (Solution Posted)
Download Code
Re: Using SSH via SOCKS5 Proxy
by cmv (Chaplain) on Sep 11, 2007 at 13:53 UTC
    Wow, no replies. Either this is an incredibly complex problem, or I'm being stupid here (I know where I would place my wager).

    We discussed this a bit in the chatterbox, and things that were said went along the lines of "use LD_PRELOAD to load a socksifier". I have no clue on either of these things are.

    I have existing perl programs that use Net::SSH::Perl, and I'd like to "just use them", but have all the ssh stuff go through the SOCKS5 proxy.

    Please help!

    Thanks

    -Craig

Re: Using SSH via SOCKS5 Proxy
by erroneousBollock (Curate) on Sep 11, 2007 at 16:03 UTC
    The dante debian package provides a program called socksify which:
    uses LD_PRELOAD environment variable to wrap all networking-related system calls so that programs can go thought a SOCKS server that was installed as part of a firewall.
    I'd imagine something like socksify ./script.pl will do the trick.

    If your program also needs to access some non-socksified subnet you'll need to split your program into two parts which talk via a pipe (or similar).

    Wikipedia has an article which discusses the LD_PRELOAD mechanism.

    -David

      David-

      Thanks for the information & pointers. Now I think I understand what was being said to me.

      The problem with this solution is that I need to have a socksify program built for all my platforms (MacOS, SunOS, Windows, linux), and I'm not sure that socksify will build for all of them. This is why I like Net::SSH::Perl so much. The native perl code provides the ssh protocol directly, so my perl code is easily plopped onto a platform, and will mostly, "just run".

      I think the better long-term way is to somehow have the Net::SSH::Perl module make use of the Net::SOCKS module to provide this functionality, when requested. Maybe I'll just "dig-in" and see what happens. After all, how bad can I muck things up... right? :-)

      Many thanks for the reply!

      -Craig

Re: Using SSH via SOCKS5 Proxy
by salva (Abbot) on Sep 11, 2007 at 18:18 UTC
    Create a new class derived from Net::SSH::Perl and redefine the _connect method to do whatever you want. For instance, implementing the SOCKS5 protocol yourself (it's a very simple one) or using an external SOCKS5 adapter connected by a pipe or a unix socket.
      Salva-

      Yes, thanks for the leg-up! This is along the lines I'm thinking of following.

      I'm actually hoping to modify Net::SSH::Perl to optionally utilize Net::SOCKS, when requested. If I can get this working, I'll provide my patches to the author for consideration in making it official.

      -Craig

        OpenSSH accepts a ProxyCommand option to define how to connect using custom proxies. It would be great if you used the same aproach for Net::SSH::Perl

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://638101]
Approved by almut
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-12-27 10:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls