Python ssh client over socks (proxy)

2019-04-11 22:16发布

问题:

So, I need to connect to SSH server through proxy socks. I read paramiko and twisted.conch docs, but didn`t found proxy socks support there.

回答1:

This socket-wrapper allows you to use static ssh-tunnels. I found a common solution for my problem:

  1. Use paramiko SSHClient class
  2. Extend SSHClient with your own class
  3. Re-implement the connect() method: Instead of using a standard socket object we pass to it a fixed proxied socket from the python package sockipy


回答2:

Paraproxy (a Paramiko addon for SSH2 ProxyCommands) looks like it can do it. There's no documentation online but in downloading the source and inspecting the README file, I found this:

Paraproxy is a supplement to the great "paramiko" SSH2 module. While paramiko has a really good support for SSH(2) it lacks the ProxyCommand feature.

ProxyCommands can be used e.g. to connect to VPN tunnels but they provide manny other nice features.

Paraproxy, once imported will hook into the SSHClient class provided by paramiko which in turn gains full support for SSH ProxyCommands.

No changes to existing code are needed.

Give that a shot!