Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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 %h %p"
Here's where I got connect.c to compile for my platform:

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?


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

Replies are listed 'Best First'.
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 ./ 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.



      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!


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.

      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.


        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
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!



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://638101]
Approved by almut
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2017-11-21 06:39 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (296 votes). Check out past polls.