pahaz / sshtunnel

SSH tunnels to remote server.
MIT License
1.22k stars 184 forks source link

Issue generating tunnels #224

Open yetanotherc0demonkey opened 3 years ago

yetanotherc0demonkey commented 3 years ago

I've been using SSHTunnel for some time on a project for creating multiple tunnels. Recently, it seems to have stopped working for me, so I've been doing a little investigation. To remove the possibility of my code being the issue, I've decided to test using the code from the documentation, slightly modified:

from sshtunnel import SSHTunnelForwarder
import logging

logging.basicConfig(level=logging.DEBUG)

server = SSHTunnelForwarder(
    '192.168.242.133',
    ssh_username="test1",
    ssh_password="password1",
    remote_bind_address=('192.168.242.135', 22),
    local_bind_address=('127.0.0.1',1234)
)

server.start()

input("Press enter to end")
server.stop()

I have 4 VM's on the same network as my current VM with the code in. These are instances of theSSS server (https://sourceforge.net/projects/thesss/files/) Details are shown below: TheSSServer 1: IP 192.168.150.133, username - test1, password - password1 TheSSServer 2: IP 192.168.150.135, username - test2, password - password2 TheSSServer 3: IP 192.168.150.134, username - test3, password - password3 TheSSServer 4: IP 192.168.150.136, username - test4, password - password4

This provides the following information from the logger:

DEBUG:paramiko.transport:starting thread (client mode): 0x554131f0
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.7.2
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-OpenSSH_8.4
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_8.4)
DEBUG:paramiko.transport:kex algos:['curve25519-sha256', 'curve25519-sha256@libssh.org', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group16-sha512', 'diffie-hellman-group18-sha512', 'diffie-hellman-group14-sha256'] server key:['rsa-sha2-512', 'rsa-sha2-256', 'ssh-rsa', 'ecdsa-sha2-nistp256'] client encrypt:['chacha20-poly1305@openssh.com', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com'] server encrypt:['chacha20-poly1305@openssh.com', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com'] client mac:['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] server mac:['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] client compress:['none', 'zlib@openssh.com'] server compress:['none', 'zlib@openssh.com'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: curve25519-sha256@libssh.org
DEBUG:paramiko.transport:HostKey agreed: ecdsa-sha2-nistp256
DEBUG:paramiko.transport:Cipher agreed: aes128-ctr
DEBUG:paramiko.transport:MAC agreed: hmac-sha2-256
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:kex engine KexCurve25519 specified hash_algo <built-in function openssl_sha256>
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:Attempting password auth...
DEBUG:paramiko.transport:userauth is OK
INFO:paramiko.transport:Authentication (password) successful!

When using netstat, I can see that port 1234 has been set up on the machine the script is running on, however running netstat on theSSS Server 1 does not show any connection being created and running 'ssh test2@127.0.0.1 -p 1234' does not allow me to connect to anything.

I've tried running the code as root on Ubunutu 20.04 and on Windows 10 with almost identical results. I can provide any further information required.

Any ideas? I'm fully aware this may be a fleshware error!

pahaz commented 3 years ago

Could you please provide the whole log of your program with sshtunnel.DEFAULT_LOGLEVEL = logging.DEBUG or better with sshtunnel.DEFAULT_LOGLEVEL = 1 ?

yetanotherc0demonkey commented 3 years ago

Output is provided below:

2021-01-23 07:19:36,514| WAR | MainThrea/1032@sshtunnel | Could not read SSH configuration file: ~/.ssh/config
WARNING:sshtunnel.SSHTunnelForwarder:Could not read SSH configuration file: ~/.ssh/config
2021-01-23 07:19:36,534| INF | MainThrea/1060@sshtunnel | 2 keys loaded from agent
INFO:sshtunnel.SSHTunnelForwarder:2 keys loaded from agent
2021-01-23 07:19:36,572| DEB | MainThrea/1309@sshtunnel | Private key file (/home/prog/.ssh/id_rsa, <class 'paramiko.rsakey.RSAKey'>) successfully loaded
DEBUG:sshtunnel.SSHTunnelForwarder:Private key file (/home/prog/.ssh/id_rsa, <class 'paramiko.rsakey.RSAKey'>) successfully loaded
2021-01-23 07:19:36,595| ERR | MainThrea/1314@sshtunnel | Password is required for key /home/prog/.ssh/id_ed25519
ERROR:sshtunnel.SSHTunnelForwarder:Password is required for key /home/prog/.ssh/id_ed25519
2021-01-23 07:19:36,611| INF | MainThrea/1117@sshtunnel | 3 key(s) loaded
INFO:sshtunnel.SSHTunnelForwarder:3 key(s) loaded
2021-01-23 07:19:36,625| INF | MainThrea/0978@sshtunnel | Connecting to gateway: 192.168.242.133:22 as user 'test1'
INFO:sshtunnel.SSHTunnelForwarder:Connecting to gateway: 192.168.242.133:22 as user 'test1'
2021-01-23 07:19:36,635| DEB | MainThrea/0983@sshtunnel | Concurrent connections allowed: True
DEBUG:sshtunnel.SSHTunnelForwarder:Concurrent connections allowed: True
2021-01-23 07:19:36,657| DEB | MainThrea/1400@sshtunnel | Trying to log in with key: b'dd85d552f753ca79ea297a6c4061f9ff'
DEBUG:sshtunnel.SSHTunnelForwarder:Trying to log in with key: b'dd85d552f753ca79ea297a6c4061f9ff'
2021-01-23 07:19:36,681| DEB | MainThrea/1204@sshtunnel | Transport socket info: (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 0), timeout=0.1
DEBUG:sshtunnel.SSHTunnelForwarder:Transport socket info: (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 0), timeout=0.1
2021-01-23 07:19:36,696| DEB |  Thread-1/1819@transport | starting thread (client mode): 0xc803c370
DEBUG:paramiko.transport:starting thread (client mode): 0xc803c370
2021-01-23 07:19:36,709| DEB |  Thread-1/1819@transport | Local version/idstring: SSH-2.0-paramiko_2.7.2
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.7.2
2021-01-23 07:19:36,717| DEB |  Thread-1/1819@transport | Remote version/idstring: SSH-2.0-OpenSSH_8.4
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-OpenSSH_8.4
2021-01-23 07:19:36,730| INF |  Thread-1/1819@transport | Connected (version 2.0, client OpenSSH_8.4)
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_8.4)
2021-01-23 07:19:36,743| DEB |  Thread-1/1819@transport | kex algos:['curve25519-sha256', 'curve25519-sha256@libssh.org', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group16-sha512', 'diffie-hellman-group18-sha512', 'diffie-hellman-group14-sha256'] server key:['rsa-sha2-512', 'rsa-sha2-256', 'ssh-rsa', 'ecdsa-sha2-nistp256'] client encrypt:['chacha20-poly1305@openssh.com', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com'] server encrypt:['chacha20-poly1305@openssh.com', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com'] client mac:['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] server mac:['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] client compress:['none', 'zlib@openssh.com'] server compress:['none', 'zlib@openssh.com'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:kex algos:['curve25519-sha256', 'curve25519-sha256@libssh.org', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group16-sha512', 'diffie-hellman-group18-sha512', 'diffie-hellman-group14-sha256'] server key:['rsa-sha2-512', 'rsa-sha2-256', 'ssh-rsa', 'ecdsa-sha2-nistp256'] client encrypt:['chacha20-poly1305@openssh.com', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com'] server encrypt:['chacha20-poly1305@openssh.com', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com'] client mac:['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] server mac:['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] client compress:['none', 'zlib@openssh.com'] server compress:['none', 'zlib@openssh.com'] client lang:[''] server lang:[''] kex follows?False
2021-01-23 07:19:36,792| DEB |  Thread-1/1819@transport | Kex agreed: curve25519-sha256@libssh.org
DEBUG:paramiko.transport:Kex agreed: curve25519-sha256@libssh.org
2021-01-23 07:19:36,799| DEB |  Thread-1/1819@transport | HostKey agreed: ecdsa-sha2-nistp256
DEBUG:paramiko.transport:HostKey agreed: ecdsa-sha2-nistp256
2021-01-23 07:19:36,813| DEB |  Thread-1/1819@transport | Cipher agreed: aes128-ctr
DEBUG:paramiko.transport:Cipher agreed: aes128-ctr
2021-01-23 07:19:36,829| DEB |  Thread-1/1819@transport | MAC agreed: hmac-sha2-256
DEBUG:paramiko.transport:MAC agreed: hmac-sha2-256
2021-01-23 07:19:36,840| DEB |  Thread-1/1819@transport | Compression agreed: none
DEBUG:paramiko.transport:Compression agreed: none
2021-01-23 07:19:36,869| DEB |  Thread-1/1819@transport | kex engine KexCurve25519 specified hash_algo <built-in function openssl_sha256>
DEBUG:paramiko.transport:kex engine KexCurve25519 specified hash_algo <built-in function openssl_sha256>
2021-01-23 07:19:36,884| DEB |  Thread-1/1819@transport | Switch to new keys ...
DEBUG:paramiko.transport:Switch to new keys ...
2021-01-23 07:19:36,896| DEB | MainThrea/1819@transport | Attempting public-key auth...
DEBUG:paramiko.transport:Attempting public-key auth...
2021-01-23 07:19:36,912| DEB |  Thread-1/1819@transport | userauth is OK
DEBUG:paramiko.transport:userauth is OK
2021-01-23 07:19:36,931| ERR |  Thread-1/1819@transport | Exception: key cannot be used for signing
ERROR:paramiko.transport:Exception: key cannot be used for signing
2021-01-23 07:19:36,947| ERR |  Thread-1/1817@transport | Traceback (most recent call last):
ERROR:paramiko.transport:Traceback (most recent call last):
2021-01-23 07:19:36,976| ERR |  Thread-1/1817@transport |   File "/usr/local/lib/python3.8/dist-packages/paramiko/transport.py", line 2109, in run
ERROR:paramiko.transport:  File "/usr/local/lib/python3.8/dist-packages/paramiko/transport.py", line 2109, in run
2021-01-23 07:19:37,001| ERR |  Thread-1/1817@transport |     handler(self.auth_handler, m)
ERROR:paramiko.transport:    handler(self.auth_handler, m)
2021-01-23 07:19:37,048| ERR |  Thread-1/1817@transport |   File "/usr/local/lib/python3.8/dist-packages/paramiko/auth_handler.py", line 298, in _parse_service_accept
ERROR:paramiko.transport:  File "/usr/local/lib/python3.8/dist-packages/paramiko/auth_handler.py", line 298, in _parse_service_accept
2021-01-23 07:19:37,069| ERR |  Thread-1/1817@transport |     sig = self.private_key.sign_ssh_data(blob)
ERROR:paramiko.transport:    sig = self.private_key.sign_ssh_data(blob)
2021-01-23 07:19:37,093| ERR |  Thread-1/1817@transport |   File "/usr/local/lib/python3.8/dist-packages/paramiko/agent.py", line 418, in sign_ssh_data
ERROR:paramiko.transport:  File "/usr/local/lib/python3.8/dist-packages/paramiko/agent.py", line 418, in sign_ssh_data
2021-01-23 07:19:37,118| ERR |  Thread-1/1817@transport |     raise SSHException("key cannot be used for signing")
ERROR:paramiko.transport:    raise SSHException("key cannot be used for signing")
2021-01-23 07:19:37,142| ERR |  Thread-1/1817@transport | paramiko.ssh_exception.SSHException: key cannot be used for signing
ERROR:paramiko.transport:paramiko.ssh_exception.SSHException: key cannot be used for signing
2021-01-23 07:19:37,171| ERR |  Thread-1/1817@transport | 
ERROR:paramiko.transport:
2021-01-23 07:19:37,199| ERR | MainThrea/1223@sshtunnel | Could not connect to gateway 192.168.242.133:22 : key cannot be used for signing
ERROR:sshtunnel.SSHTunnelForwarder:Could not connect to gateway 192.168.242.133:22 : key cannot be used for signing
Traceback (most recent call last):
  File "/home/prog/Desktop/testtunnel.py", line 17, in <module>
    server.start()
  File "/usr/local/lib/python3.8/dist-packages/sshtunnel.py", line 1331, in start
    self._raise(BaseSSHTunnelForwarderError,
  File "/usr/local/lib/python3.8/dist-packages/sshtunnel.py", line 1174, in _raise
    raise exception(reason)
sshtunnel.BaseSSHTunnelForwarderError: Could not establish session to SSH gateway

However SSH to the server works fine with a password:

ssh test1@192.168.242.133
The authenticity of host '192.168.242.133 (192.168.242.133)' can't be established.
ECDSA key fingerprint is SHA256:wgcSTfmOuNsC4o0PBtG7bM/8OADvgygkhVMR6DdGe/k.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.242.133' (ECDSA) to the list of known hosts.
test1@192.168.242.133's password: 
test1@TheSSS:~# 
pahaz commented 3 years ago

I think it's maybe the same problem as the #226 .

As I can see sshtunnel trying to use the id_rsa key instead of the password.

You can try this hack:

...
tunnel = SSHTunnelForwarder(
    '192.168.242.133',
    ssh_username="test1",
    ssh_password="password1",
    remote_bind_address=('192.168.242.135', 22),
    local_bind_address=('127.0.0.1',1234)
)
tunnel.ssh_pkeys = []  # DIRTY HACK!! Change it in future!
...

Or it's by be related to some paramiko issue like https://github.com/paramiko/paramiko/issues/23

yetanotherc0demonkey commented 3 years ago

OK, tried this today, got the following output:

2021-01-25 02:03:56,641| WAR | MainThrea/1032@sshtunnel | Could not read SSH configuration file: ~/.ssh/config
WARNING:sshtunnel.SSHTunnelForwarder:Could not read SSH configuration file: ~/.ssh/config
2021-01-25 02:03:56,660| INF | MainThrea/1060@sshtunnel | 0 keys loaded from agent
INFO:sshtunnel.SSHTunnelForwarder:0 keys loaded from agent
2021-01-25 02:03:56,679| INF | MainThrea/1117@sshtunnel | 0 key(s) loaded
INFO:sshtunnel.SSHTunnelForwarder:0 key(s) loaded
2021-01-25 02:03:56,697| INF | MainThrea/0978@sshtunnel | Connecting to gateway: 192.168.242.133:22 as user 'test1'
INFO:sshtunnel.SSHTunnelForwarder:Connecting to gateway: 192.168.242.133:22 as user 'test1'
2021-01-25 02:03:56,720| DEB | MainThrea/0983@sshtunnel | Concurrent connections allowed: True
DEBUG:sshtunnel.SSHTunnelForwarder:Concurrent connections allowed: True
2021-01-25 02:03:56,745| DEB | MainThrea/1414@sshtunnel | Trying to log in with password: *********
DEBUG:sshtunnel.SSHTunnelForwarder:Trying to log in with password: *********
2021-01-25 02:03:56,776| DEB | MainThrea/1204@sshtunnel | Transport socket info: (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 0), timeout=0.1
DEBUG:sshtunnel.SSHTunnelForwarder:Transport socket info: (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 0), timeout=0.1
2021-01-25 02:03:56,801| DEB |  Thread-1/1819@transport | starting thread (client mode): 0xa1d857c0
DEBUG:paramiko.transport:starting thread (client mode): 0xa1d857c0
2021-01-25 02:03:56,823| DEB |  Thread-1/1819@transport | Local version/idstring: SSH-2.0-paramiko_2.7.2
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.7.2
2021-01-25 02:03:56,839| DEB |  Thread-1/1819@transport | Remote version/idstring: SSH-2.0-OpenSSH_8.4
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-OpenSSH_8.4
2021-01-25 02:03:56,855| INF |  Thread-1/1819@transport | Connected (version 2.0, client OpenSSH_8.4)
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_8.4)
2021-01-25 02:03:56,875| DEB |  Thread-1/1819@transport | kex algos:['curve25519-sha256', 'curve25519-sha256@libssh.org', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group16-sha512', 'diffie-hellman-group18-sha512', 'diffie-hellman-group14-sha256'] server key:['rsa-sha2-512', 'rsa-sha2-256', 'ssh-rsa', 'ecdsa-sha2-nistp256'] client encrypt:['chacha20-poly1305@openssh.com', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com'] server encrypt:['chacha20-poly1305@openssh.com', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com'] client mac:['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] server mac:['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] client compress:['none', 'zlib@openssh.com'] server compress:['none', 'zlib@openssh.com'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:kex algos:['curve25519-sha256', 'curve25519-sha256@libssh.org', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group16-sha512', 'diffie-hellman-group18-sha512', 'diffie-hellman-group14-sha256'] server key:['rsa-sha2-512', 'rsa-sha2-256', 'ssh-rsa', 'ecdsa-sha2-nistp256'] client encrypt:['chacha20-poly1305@openssh.com', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com'] server encrypt:['chacha20-poly1305@openssh.com', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com'] client mac:['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] server mac:['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] client compress:['none', 'zlib@openssh.com'] server compress:['none', 'zlib@openssh.com'] client lang:[''] server lang:[''] kex follows?False
2021-01-25 02:03:56,930| DEB |  Thread-1/1819@transport | Kex agreed: curve25519-sha256@libssh.org
DEBUG:paramiko.transport:Kex agreed: curve25519-sha256@libssh.org
2021-01-25 02:03:56,946| DEB |  Thread-1/1819@transport | HostKey agreed: ecdsa-sha2-nistp256
DEBUG:paramiko.transport:HostKey agreed: ecdsa-sha2-nistp256
2021-01-25 02:03:56,966| DEB |  Thread-1/1819@transport | Cipher agreed: aes128-ctr
DEBUG:paramiko.transport:Cipher agreed: aes128-ctr
2021-01-25 02:03:56,984| DEB |  Thread-1/1819@transport | MAC agreed: hmac-sha2-256
DEBUG:paramiko.transport:MAC agreed: hmac-sha2-256
2021-01-25 02:03:57,004| DEB |  Thread-1/1819@transport | Compression agreed: none
DEBUG:paramiko.transport:Compression agreed: none
2021-01-25 02:03:57,039| DEB |  Thread-1/1819@transport | kex engine KexCurve25519 specified hash_algo <built-in function openssl_sha256>
DEBUG:paramiko.transport:kex engine KexCurve25519 specified hash_algo <built-in function openssl_sha256>
2021-01-25 02:03:57,058| DEB |  Thread-1/1819@transport | Switch to new keys ...
DEBUG:paramiko.transport:Switch to new keys ...
2021-01-25 02:03:57,070| DEB | MainThrea/1819@transport | Attempting password auth...
DEBUG:paramiko.transport:Attempting password auth...
2021-01-25 02:03:57,088| DEB |  Thread-1/1819@transport | userauth is OK
DEBUG:paramiko.transport:userauth is OK
2021-01-25 02:03:57,117| INF |  Thread-1/1819@transport | Authentication (password) successful!
INFO:paramiko.transport:Authentication (password) successful!
2021-01-25 02:03:57,135| INF |  Srv-1234/1433@sshtunnel | Opening tunnel: 127.0.0.1:1234 <> 192.168.242.135:22
Press enter to endINFO:sshtunnel.SSHTunnelForwarder:Opening tunnel: 127.0.0.1:1234 <> 192.168.242.135:22

Netstat shows that the port has been opened:

prog@ubuntu:~$ netstat -tulpn
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:58201         0.0.0.0:*               LISTEN      3055/python3.8      
tcp        0      0 127.0.0.1:43207         0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:1234          0.0.0.0:*               LISTEN      3289/python3.8 

However attempts to SSH using "ssh test2@127.0.0.1 -p 1234" fails "ssh test2@192.168.242.135" however works fine

I've tried clearing all SSH keys on my local machine and this hasn't had any effect. Not sure what else I can try, this is a newly built box.

yetanotherc0demonkey commented 3 years ago

Equally, using the command line tool version of this project works, the following command generates the desired effect: sshtunnel -U test1 -p 22 -P password1 -L 127.0.0.1:1234 -R 192.168.242.135:22 -v 192.168.242.133

pahaz commented 3 years ago

Could you please run this command with -vvvv option? And shows the output.

yetanotherc0demonkey commented 3 years ago

Of course:

sshtunnel -U test1 -p 22 -P password1 -L 127.0.0.1:1234 -R 192.168.242.135:22 -vvvv  192.168.242.133
2021-01-25 11:01:56,481| WAR | MainThrea/1032@sshtunnel | Could not read SSH configuration file: ~/.ssh/config
2021-01-25 11:01:56,481| INF | MainThrea/1060@sshtunnel | 0 keys loaded from agent
2021-01-25 11:01:56,482| INF | MainThrea/1117@sshtunnel | 0 key(s) loaded
2021-01-25 11:01:56,482| INF | MainThrea/0978@sshtunnel | Connecting to gateway: 192.168.242.133:22 as user 'test1'
2021-01-25 11:01:56,482| DEB | MainThrea/0983@sshtunnel | Concurrent connections allowed: False
2021-01-25 11:01:56,482| DEB | MainThrea/1414@sshtunnel | Trying to log in with password: *********
2021-01-25 11:01:56,484| DEB | MainThrea/1204@sshtunnel | Transport socket info: (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 0), timeout=0.1
2021-01-25 11:01:56,590| INF |  Srv-1234/1433@sshtunnel | Opening tunnel: 127.0.0.1:1234 <> 192.168.242.135:22

            Press <Ctrl-C> or <Enter> to stop!
yetanotherc0demonkey commented 3 years ago

Hi,

Do you have any ideas on this issue or any further information that you need for it?

pahaz commented 3 years ago

Sorry for the delay. As I understand the hack tunnel.ssh_pkeys = [] # DIRTY HACK! is helped to solve the first problem.

About the second: could you please check your ssh config. Maybe your ssh gateway client has some extra configs. Also, you can try to check ssh test2@127.0.0.1 -p 1234 -vvvv output.

yetanotherc0demonkey commented 3 years ago

Hi,

The hack tunnel.ssh_pkeys = [] # DIRTY HACK! didnt work for me, I still had the same issue, the output that starts with: "OK, tried this today, got the following output:" shows the output when I used that.

However the command line program works while the test code does not.

yetanotherc0demonkey commented 3 years ago

Hi,

Do you have any ideas on what I can do to fix this, as all my work arounds are failing and this is part of a larger project.

syfantid commented 5 months ago

Same issue here; tunnel.ssh_pkeys = [] # DIRTY HACK! doesn't fix the issue.