Git Product home page Git Product logo

Comments (18)

fernandezcuesta avatar fernandezcuesta commented on May 28, 2024 1

Please update the sshtunnel package and retry.

from sshtunnel.

fernandezcuesta avatar fernandezcuesta commented on May 28, 2024 1

This is not possible. What you're trying to achieve is not connecting to the SSH gateway through a SOCKS5 proxy. There's no support for dynamic application-level port forwarding (equivalent to OpenSSH's client -D option).
What you can do instead is a tunnel for a single destination, if that fulfils your requirements.

from sshtunnel.

fernandezcuesta avatar fernandezcuesta commented on May 28, 2024

If what you mean is how to make an ssh connection to a server behind a socks5 proxy, you may first create a proxy (i.e. with pysocks) and pass it to sshtunnel. I removed the restriction for the proxy argument in SSHTunnelForwarder so now any socket-like object may be used (see sock parameter information for more details).

import socks

SOCKS5_PROXY_HOST = '1.2.3.4'
SOCKS5_PROXY_PORT = 1080
s = socks.socksocket()
s.set_proxy(socks.SOCKS5, SOCKS5_PROXY_HOST, SOCKS5_PROXY_PORT)

tunnel = sshtunnel.SSHTunnelForwarder(
    ('ssh_server_ip', 22),
     ssh_username='user',
     ssh_password='secret',
     remote_bind_address=('127.0.0.1', 5555),
     ssh_proxy=s,
)

from sshtunnel.

 avatar commented on May 28, 2024

I modified according you. but It not working?
Source code:

import sshtunnel
import socks

SOCKS5_PROXY_HOST = '127.0.0.1'
SOCKS5_PROXY_PORT = 1080
s = socks.socksocket()
s.set_proxy(socks.SOCKS5, SOCKS5_PROXY_HOST, SOCKS5_PROXY_PORT)

tunnel = sshtunnel.SSHTunnelForwarder(
    ('182.69.xxx.70', 22),
     ssh_username='admin',
     ssh_password='admin',
     remote_bind_address=('127.0.0.1', 5555),
     ssh_proxy=s,
)
tunnel.start()
#
print(tunnel.local_bind_port)

Error:

  File "D:/data_sourcecode/Test/test.py", line 17, in <module>
    tunnel.start()
  File "C:\python-64bit\python-2.7.10.amd64\lib\site-packages\sshtunnel.py", line 1131, in start
    self._create_tunnels()
  File "C:\python-64bit\python-2.7.10.amd64\lib\site-packages\sshtunnel.py", line 1022, in _create_tunnels
    self._connect_to_gateway()
  File "C:\python-64bit\python-2.7.10.amd64\lib\site-packages\sshtunnel.py", line 1231, in _connect_to_gateway
    self._transport = self._get_transport()
  File "C:\python-64bit\python-2.7.10.amd64\lib\site-packages\sshtunnel.py", line 1000, in _get_transport
    assert(isinstance(self.ssh_proxy, paramiko.proxy.ProxyCommand))
AssertionError

from sshtunnel.

 avatar commented on May 28, 2024

I updated and tried then didn't show bug it. But It's not working( It's don't run to command line this
print(tunnel.local_bind_port) )

from sshtunnel.

fernandezcuesta avatar fernandezcuesta commented on May 28, 2024

Yeap, I think I know where the error is. Could you please re-update (from source, not pypi) and retry?

from sshtunnel.

 avatar commented on May 28, 2024

Still error:

Traceback (most recent call last):
  File "D:/data_sourcecode/Test/test.py", line 20, in <module>
    tunnel.start()
  File "build\bdist.win-amd64\egg\sshtunnel.py", line 1152, in start
  File "build\bdist.win-amd64\egg\sshtunnel.py", line 1043, in _create_tunnels
  File "build\bdist.win-amd64\egg\sshtunnel.py", line 1252, in _connect_to_gateway
  File "build\bdist.win-amd64\egg\sshtunnel.py", line 1029, in _get_transport
  File "C:\python-64bit\python-2.7.10.amd64\lib\site-packages\socks.py", line 687, in connect
    raise ProxyConnectionError(msg, error)
socks.ProxyConnectionError: Error connecting to SOCKS5 proxy 127.0.0.1:1080: [Errno 10061] No connection could be made because the target machine actively refused it

from sshtunnel.

fernandezcuesta avatar fernandezcuesta commented on May 28, 2024

That seems more like a local issue. It's working as expected with a socks proxy set up with openssh.

[...] the target machine actively refused it

from sshtunnel.

 avatar commented on May 28, 2024

I don't understand why it not working. the target machine actively refused it
I want to download a mp3 file with socks5 and It must be download fast. Please help me and share for me a example code to do it.
Thanks

from sshtunnel.

fernandezcuesta avatar fernandezcuesta commented on May 28, 2024

@thehung12a3 the example already provided should be valid. At first that could not work because before 0.0.8.3 the proxy had to be a paramiko.Proxycommand instance. Now this restriction is gone and any socket-like object may be used as proxy.
You may first try if you can access via your proxy with openssh:

$ ssh -o ProxyCommand='nc -x YOUR_PROXY_IP:YOUR_PROXY_PORT %h %p' \
 SSH_SERVER_TARGET -L <...>

from sshtunnel.

 avatar commented on May 28, 2024

I can not access via socks5 in firefox browser. When you release version0.0.8.3?. I'm waiting it and hope all is well.

from sshtunnel.

fernandezcuesta avatar fernandezcuesta commented on May 28, 2024

Can you describe or make a draw of what you have at the moment? I'm not sure I'm understanding your problem properly. With the changes I already did I was able to achieve the following:

                         +---------+
                    1080 |         |
                         | socks5  |   22+----------+  443-----------+
        +----------------> proxy   +----->  SSH     +---->    Web    |
       <-----------------+         <-----+  server  <----+    server |
                         |         |     |          | ^  |           |
                         |         |     +----------+ |  +-----------+
                         |         |                  |
                         +---------+                  +
                                                    tunnel

The scenario in this diagram worked for me with the code pasted before.

from sshtunnel.

 avatar commented on May 28, 2024

I run the above code snippets then It's still the occur attunnel.start()

File "C:\python-64bit\python-2.7.10.amd64\lib\site-packages\socks.py", line 687, in connect
    raise ProxyConnectionError(msg, error)
socks.ProxyConnectionError: Error connecting to SOCKS5 proxy 127.0.0.1:1080: [Errno 10061] No connection could be made because the target machine actively refused it

I used pip to uninstall sshtunnel and install from new source. But not working?. I don't know how to fix it?

My scenario:
I will run the above code snippets to a connection with socks5. After that I open a firefox browser and access with socks5 to download a file mp3

from sshtunnel.

fernandezcuesta avatar fernandezcuesta commented on May 28, 2024

I still don't understand what's the role of the SSH tunnel here. Where is your proxy? (behind/in front of the SSH server), where's your web service (tunnelled/not tunnelled over the SSH tunnel)?
A picture is worth a thousand words BTW.

from sshtunnel.

 avatar commented on May 28, 2024

I wanted it to be like this. https://www.youtube.com/watch?v=COg_LB4Fe5o

from sshtunnel.

quocduongpy avatar quocduongpy commented on May 28, 2024

hi
please help create socks5 with ssh auto login

from sshtunnel.

stefanct avatar stefanct commented on May 28, 2024

@fernandezcuesta I came here when looking for an ssh -D equivalent aka SOCKS over SSH tunnel in python. Above, in 2016, you stated that this is not supported. However, you did not state any reason or rationale why it isn't or might not be added in the future.

Can you please explain a bit why this is not supported yet, how this might be implemented and if you would like to see contributions towards it?

from sshtunnel.

fernandezcuesta avatar fernandezcuesta commented on May 28, 2024

Hi there. The idea was to keep it as simple as possible and not expend much time supporting what you can achieve with other packages (e.g. asyncssh).
Anyway feel free to contribute, it'll be more than welcome.

from sshtunnel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.