paramiko / paramiko

The leading native Python SSHv2 protocol library.
http://paramiko.org
GNU Lesser General Public License v2.1
9.1k stars 2.01k forks source link

strange unknown type exception when using password auth on windows #452

Open axfelix opened 9 years ago

axfelix commented 9 years ago

when running the following code:

from paramiko import SSHClient from paramiko import AutoAddPolicy ssh = SSHClient() ssh.set_missing_host_key_policy(AutoAddPolicy()) ssh.connect(server, username=Username, password=Password, look_for_keys=False)

I'm getting:

File "myscript.py", line 243, in check_zip_and_send ssh.connect(server, username=Username, password=Password, look_for_keys=False) File "c:\Users\Alex\Dropbox\Python27\lib\site-packages\paramiko\client.py", line 307, in connect look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host) File "c:\Users\Alex\Dropbox\Python27\lib\site-packages\paramiko\client.py", line 510, in _auth self._transport.auth_password(username, password) File "c:\Users\Alex\Dropbox\Python27\lib\site-packages\paramiko\transport.py", line 1166, in auth_password return self.auth_handler.wait_for_response(my_event) File "c:\Users\Alex\Dropbox\Python27\lib\site-packages\paramiko\auth_handler.py", line 197, in wait_for_response raise e Exception: Unknown type

any ideas? not seeing any hits for this one; everything was installed from pip. I can test on OSX and Linux later this evening.

axfelix commented 9 years ago

yep, it's fine on Linux, I'm assuming fine on OSX too. any idea if this could be a recent regression?

bitprophet commented 9 years ago

To clarify - it's broken on Windows only, and targeting a server that worked with Windows prior? If so, could definitely be a regression, we're unable to do CI on Windows and core devs don't Windows either. If you're able to try a few different recent releases to narrow down when it was introduced, that'd be rad. Thanks!

axfelix commented 9 years ago

I grabbed 1.12.4 the other day and that worked okay ... I can do some more thorough testing later to see if it was broken in 1.13.x, 1.14.x, or 1.15.x.

frizzby commented 9 years ago

I've got the same on Ubuntu 14.10. Paramiko was installed via apt-get:

$ sudo dpkg -s python-paramiko | grep Version
Version: 1.15.1-1

The exception:

(lines skipped)
  File "/usr/lib/python2.7/dist-packages/paramiko/client.py", line 307, in connect
    look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
  File "/usr/lib/python2.7/dist-packages/paramiko/client.py", line 510, in _auth
    self._transport.auth_password(username, password)
  File "/usr/lib/python2.7/dist-packages/paramiko/transport.py", line 1166, in auth_password
    return self.auth_handler.wait_for_response(my_event)
  File "/usr/lib/python2.7/dist-packages/paramiko/auth_handler.py", line 197, in wait_for_response
    raise e
Exception: Unknown type

Update: I did a quick investigation and found that in my particular case this is caused by setting password to int value. ssh.connect("127.0.0.1", username="user", password=1, look_for_keys=False) This is obviously not a really valid case, but i believe input validation is lacking some steps here.

bitprophet commented 9 years ago

Feels related to other ongoing key related issues (e.g. target server may be issuing keys Paramiko doesn't support yet, or Paramiko is incorrectly not trying key types in the right order). Leaving open for now until we iron some of that out.

aburgel commented 9 years ago

Just an FYI in case someone else has a similar problem. I ran into this exception and tracked it down to having an int value as the username (same as @frizzby's comment).

SingularBunny commented 9 years ago

Same error (paramiko1.15.2, Linux kali 3.18.0-kali3-amd64 #1 SMP Debian 3.18.6-1~kali2 (2015-03-02) x86_64 GNU/Linux):

  File "/usr/local/lib/python2.7/dist-packages/paramiko/transport.py", line 1168, in auth_password
    return self.auth_handler.wait_for_response(my_event)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/auth_handler.py", line 197, in wait_for_response
    raise e
Exception: Unknown type

Logins:passwords that throws exception are:

:default
:use ALT+G at boot to reset config
Administrator:ganteng

Pretty work logins:passwords:

:help
:sa

No int password used.

ghost commented 9 years ago

Same issue here, running on os x 10.11 (El Capitan), nothing fancy, script goes as:

import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect(s, username='root', password='myPass')
stdin, stdout, stderr = ssh.exec_command('myCommand')
...
ssh.close()

script hangs forever (presumably, couldn't wait forever hehe, had to interrupt). here is what i get when I interrupt the script execution:

^CTraceback (most recent call last):
DEBUG:paramiko.transport:userauth is OK
  File "./json.py", line 4, in <module>
    import json
  File "/root/json.py", line 17, in <module>
    ssh.connect(s, username='root', password='myPass')
  File "/usr/lib/python2.7/dist-packages/paramiko/client.py", line 332, in connect
    self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys)
  File "/usr/lib/python2.7/dist-packages/paramiko/client.py", line 477, in _auth
    self._transport.auth_publickey(username, key)
  File "/usr/lib/python2.7/dist-packages/paramiko/transport.py", line 1234, in auth_publickey
    return self.auth_handler.wait_for_response(my_event)
  File "/usr/lib/python2.7/dist-packages/paramiko/auth_handler.py", line 158, in wait_for_response
    event.wait(0.1)
  File "/usr/lib/python2.7/threading.py", line 404, in wait
    self.__cond.wait(timeout)
  File "/usr/lib/python2.7/threading.py", line 263, in wait
    _sleep(delay)
KeyboardInterrupt

When I check the logs, here is what i see:

root@srv-01:~# ./json.py
DEBUG:paramiko.transport:starting thread (client mode): 0x1dfaa10L
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_6.0p1)
DEBUG:paramiko.transport:kex algos:['ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-rsa', 'ssh-dss', 'ecdsa-sha2-nistp256'] client encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'arcfour256', 'arcfour128', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', 'rijndael-cbc@lysator.liu.se'] server encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'arcfour256', 'arcfour128', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', 'rijndael-cbc@lysator.liu.se'] client mac:['hmac-md5', 'hmac-sha1', 'umac-64@openssh.com', 'hmac-sha2-256', 'hmac-sha2-256-96', 'hmac-sha2-512', 'hmac-sha2-512-96', 'hmac-ripemd160', 'hmac-ripemd160@openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] server mac:['hmac-md5', 'hmac-sha1', 'umac-64@openssh.com', 'hmac-sha2-256', 'hmac-sha2-256-96', 'hmac-sha2-512', 'hmac-sha2-512-96', 'hmac-ripemd160', 'hmac-ripemd160@openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] client compress:['none', 'zlib@openssh.com'] server compress:['none', 'zlib@openssh.com'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:Ciphers agreed: local=aes128-ctr, remote=aes128-ctr
DEBUG:paramiko.transport:using kex diffie-hellman-group1-sha1; server key type ssh-rsa; cipher: local aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:Adding ssh-rsa host key for se01: 9c63e0fc76490ed397d7978e
DEBUG:paramiko.transport:Trying discovered key 41d33968950ea5a79ca10d6 in /root/.ssh/id_rsa

i have to notice, there is a key on the remote server, that allows me for a passwordless login if that helps track down the issue.

Another thing, worth mentioning - when I do the same thing in interactive shell - runs flawlessly, no errors, no exceptions, just the way it should.