Repository navigation
Description
I am trying to send remote commands to a CISCO ISR-891.
I have tried doing so with username and password without issues. But when I try to do it using private key authentication I get the following error:
Traceback (most recent call last):
File "CA_srv.py", line 17, in
ssh.connect(hostname, port=2222, username='control', password=None, pkey=mkey, look_for_keys=False)
File "/usr/local/lib/python2.7/dist-packages/paramiko-1.9.0-py2.7.egg/paramiko/client.py", line 338, in connect
self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys)
File "/usr/local/lib/python2.7/dist-packages/paramiko-1.9.0-py2.7.egg/paramiko/client.py", line 519, in _auth
raise saved_exception
paramiko.SSHException: Illegal info request from server
The output of the logfile is the following:
....................
....................
DEB [20121217-13:35:50.025] thr=2 paramiko.transport: Trying SSH key 32324d2e86db5b638bcb87a44774d9e7
DEB [20121217-13:35:50.213] thr=1 paramiko.transport: userauth is OK
ERR [20121217-13:35:50.229] thr=1 paramiko.transport: Exception: Illegal info request from server
ERR [20121217-13:35:50.230] thr=1 paramiko.transport: Traceback (most recent call last):
ERR [20121217-13:35:50.231] thr=1 paramiko.transport: File "/usr/local/lib/python2.7/dist-packages/paramiko-1.9.0-py2.7.egg/paramiko/transport.py", line 1598, in run
ERR [20121217-13:35:50.231] thr=1 paramiko.transport: self.auth_handler._handler_table[ptype](self.auth_handler, m)
ERR [20121217-13:35:50.231] thr=1 paramiko.transport: File "/usr/local/lib/python2.7/dist-packages/paramiko-1.9.0-py2.7.egg/paramiko/auth_handler.py", line 384, in _parse_userauth_info_request
ERR [20121217-13:35:50.231] thr=1 paramiko.transport: raise SSHException('Illegal info request from server')
ERR [20121217-13:35:50.231] thr=1 paramiko.transport: SSHException: Illegal info request from server
Here is my code:
import paramiko
privatekeyfile = '/root/.ssh/id_rsa'
hostname = '200.125.52.2'
paramiko.util.log_to_file('/root/log.para')
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
mkey = paramiko.RSAKey.from_private_key_file(privatekeyfile)
ssh.connect(hostname, port=2222, username='control', password=None, pkey=mkey, look_for_keys=False)
Activity
ghalevy commentedon Jun 9, 2014
Was this ever answered? I'm having a similar issue and am curious if/how you resolved it.
fmiceli commentedon Jun 9, 2014
Never answered. Ended up using subprocess and pexpect.
Regards,
2014-06-09 15:44 GMT-03:00 Gilad Halevy [email protected]:
Ing. Franco Miceli
Coordinador de Proyectos de I+D - Plan Ceibal
Av. Italia 6201 - Montevideo, Uruguay
CP: 11500
Tel: (598 2) 601 5773 int.: 2232
ghalevy commentedon Jun 9, 2014
That's too bad. Paramiko seems very feature rich and would be infinitely more useful with good tutorials and support responsiveness.
lndbrg commentedon Jun 11, 2014
It's extremely hard to support every incarnation of the ssh-server; there are several that are almost conforming to rfcs, some that are non-conformant and some that are more strict than openssh. We would love to support every single one of them, but without access to all the different devices this is impossible. However, if you have access to a device we are happy to receive patches.
StephanieSunshine commentedon Jun 11, 2014
Shouldn't Wireshark logs of the event be good enough for a developer to be able debug this issue? A member on our team has suggested the use of Paramiko for a project, but I'm worried this unresolved issue is going to cause problems for us.
lndbrg commentedon Jun 11, 2014
No. Wireshark captures stuff going passing through the network stack, when ssh traffic hits the network interface it is already encrypted and wireshark will only log garbage.
This is also a really, really old issue, i know we have landed some compatibility fixes since then, but i can not say if they relate to this issue.
Have you tried connecting to such a host to verify that it's still an issue or not? That would be much more productive than worrying about issues that are 2 years old and may or may not be resolved. That way we might even get a better bug report and someone that can try out the patches OR even better: patches from the a developer that has access to such a device.
bitprophet commentedon Aug 8, 2014
To back up @lndbrg, this sort of support is incredibly tricky because it's super unlikely that the core devs will have ready access to devices similar to those causing the error. It's partly for that reason that we primarily support vanilla OpenSSH.
In an ideal world, yes, of course we'd love to support various target platforms. Sadly volunteer work means that's a rare thing. Again as @lndbrg says, if we can obtain in-depth information from somebody capable of adding debug output + who has access to the platform in question, that can help greatly.
I'm closing this for now, but if somebody has the time/effort to debug Cisco devices like the one mentioned, feel free to comment and we'll do our best to notice & follow up. Thanks!
toghraee commentedon May 26, 2017
I have the same problem. trying to connect to a Cisco 6500 switch via paramiko
Python2.7
import logging
import paramiko
logging.getLogger("paramiko").setLevel(logging.DEBUG)
ssh = paramiko.SSHClient()
ssh.load_system_host_keys('/root/.ssh/known_hosts')
ssh.set_missing_host_key_policy(paramiko.WarningPolicy())
paramiko.util.log_to_file("/root/paramiko.log")
ssh.connect('router', username='user',password='pass_phrase', key_filename='/root/.ssh/id_rsa', allow_agent='False')
DEB [20170526-16:46:29.252] thr=3 paramiko.transport: starting thread (client mode): 0x4eae3890L DEB [20170526-16:46:29.252] thr=3 paramiko.transport: Local version/idstring: SSH-2.0-paramiko_2.1.2 DEB [20170526-16:46:29.253] thr=3 paramiko.transport: Remote version/idstring: SSH-2.0-Cisco-1.25 INF [20170526-16:46:29.253] thr=3 paramiko.transport: Connected (version 2.0, client Cisco-1.25) DEB [20170526-16:46:29.254] thr=3 paramiko.transport: kex algos:[u'diffie-hellman-group-exchange-sha1', u'diffie-hellman-group14-sha1', u'diffie-hellman-group1-sha1'] server key:[u'ssh-rsa'] client encrypt:[u'aes128-cbc', u'3des-cbc', u'aes192-cbc', u'aes256-cbc'] server encrypt:[u'aes128-cbc', u'3des-cbc', u'aes192-cbc', u'aes256-cbc'] client mac:[u'hmac-sha1', u'hmac-sha1-96', u'hmac-md5', u'hmac-md5-96'] server mac:[u'hmac-sha1', u'hmac-sha1-96', u'hmac-md5', u'hmac-md5-96'] client compress:[u'none'] server compress:[u'none'] client lang:[u''] server lang:[u''] kex follows?False DEB [20170526-16:46:29.254] thr=3 paramiko.transport: Kex agreed: diffie-hellman-group1-sha1 DEB [20170526-16:46:29.254] thr=3 paramiko.transport: Cipher agreed: aes128-cbc DEB [20170526-16:46:29.254] thr=3 paramiko.transport: MAC agreed: hmac-md5 DEB [20170526-16:46:29.255] thr=3 paramiko.transport: Compression agreed: none DEB [20170526-16:46:29.512] thr=3 paramiko.transport: kex engine KexGroup1 specified hash_algo <built-in function openssl_sha1> DEB [20170526-16:46:29.512] thr=3 paramiko.transport: Switch to new keys ... DEB [20170526-16:46:29.519] thr=1 paramiko.transport: Trying key 542f7f11dcaafae42ec947dbf96bac97 from /root/.ssh/id_rsa DEB [20170526-16:46:29.711] thr=3 paramiko.transport: userauth is OK ERR [20170526-16:46:29.714] thr=3 paramiko.transport: Exception: Illegal info request from server ERR [20170526-16:46:29.714] thr=3 paramiko.transport: Traceback (most recent call last): ERR [20170526-16:46:29.714] thr=3 paramiko.transport: File "/usr/local/lib/python2.7/site-packages/paramiko/transport.py", line 1800, in run ERR [20170526-16:46:29.714] thr=3 paramiko.transport: self.auth_handler._handler_table[ptype](self.auth_handler, m) ERR [20170526-16:46:29.714] thr=3 paramiko.transport: File "/usr/local/lib/python2.7/site-packages/paramiko/auth_handler.py", line 575, in _parse_userauth_info_request ERR [20170526-16:46:29.714] thr=3 paramiko.transport: raise SSHException('Illegal info request from server') ERR [20170526-16:46:29.714] thr=3 paramiko.transport: SSHException: Illegal info request from server ERR [20170526-16:46:29.714] thr=3 paramiko.transport:lindenaar commentedon May 15, 2018
I bumped into this problem today when trying to connect to one of my older Cisco devices using:
This works as expected for Cisco routers running IOS 15.5 but not for one running IOS 15.1. @bitprophet so it looks like at least I have a working test case / setup for debugging. The error I get when connecting to the old (IOS 15.1) router is:
however in the logfile I see that the actual error is raised in the file
auth_handler.py, line 622. I did a bit of debugging and noticed that_parse_userauth_info_requestis called thoughself.auth_methodis set to "publickey", that doesn't seem right to me.Hope this is useful though I have no problem to dig into this further but would need some hints from @bitprophet or @lndbrg to point me in the right direction. Any suggestions are appreciated.
lindenaar commentedon May 16, 2018
Did some more testing, just to add, when NOT using public key authentication, the same problem occurs unless
allow_agentis set toFalse, i.e. the following code works but still triggers the same exception in line 622 whenallow_agentisTrue- seems the Cisco is requesting/offering public key authentication when Paramiko does not expect it (as it ends up in_parse_userauth_info_request) when using SSH Agent / public key modeAny suggestions what to test / debug further?
adobloug commentedon Jan 18, 2019
I've debugged the connection to a switch which fails.
The switch sends these messages (in this sequence):
#define SSH2_MSG_KEXINIT 20
#define SSH2_MSG_KEX_DH_GEX_GROUP 31
#define SSH2_MSG_KEX_DH_GEX_REPLY 33
#define SSH2_MSG_NEWKEYS 21
#define SSH2_MSG_SERVICE_ACCEPT 6
The next message is '60', which according to openssh can have several meanings:
/* user authentication: method specific, can be reused */
#define SSH2_MSG_USERAUTH_PK_OK 60
#define SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ 60
#define SSH2_MSG_USERAUTH_INFO_REQUEST 60
I believe the correct interpretation for ptype==60 is SSH2_MSG_USERAUTH_PK_OK and not SSH2_MSG_USERAUTH_INFO_REQUEST
SSH2_MSG_USERAUTH_PK is handled in openssh/sshconnect2.c by the input_userauth_pk_ok procedure
radssh commentedon Jan 18, 2019
It looks like what is happening here is that the Cisco switch is not conforming to RFC-4252 regarding publickey authentication (Section 7).
The client may offer a public key packet with or without an accompanying signature, indicated by the required boolean flag. Without including the signature, the server can indicate to the client that the given key is able to be accepted for authentication (
SSH2_MSG_USERAUTH_PK_OK), in which case, the client should reply with a request packet that includes the signature field.Per the RFC, the client MAY send the signature directly without first verifying whether the key is acceptable. This is what the current Paramiko code does when performing publickey authentication - all pubkey auth requests include the signature (and the boolean flag is always set to
True. In this case, the only allowable responses from the server should beSSH_MSG_USERAUTH_SUCCESSorSSH_MSG_USERAUTH_FAILURE.My guess is that the Cisco implementation is hard-coded to expect the first request to not include the signature (ignoring the boolean flag), and checking only that the provided key is valid for authentication, then sending the
SSH2_MSG_USERAUTH_PK_OKback to the client to request a packet that includes the signature, even though the previous packet already included it.adobloug commentedon Jan 21, 2019
Thanks!
Have done some digging in the Cisco release notes.
This bug has been fixed by Cisco - at least for some versions of IOS and IOS-XE.
The Cisco bug-ids are CSCuz95753 and CSCuz65461.
lindenaar commentedon Oct 11, 2019
Sorry for responding to this, but even though Cisco has resolved this for new Firmware's, older equipment (e.g. used in labs) cannot be upgraded to that as Cisco does not provide new IOS images for those anymore.
I realize this is not a bug on Paramiko's side, but handling this bug in a lenient way would be great so that it is possible to connect to legacy equipment despite this bug. (in my case, so that I can test my ansible scripts against a test router before applying it in production). Is there any way to achieve this?
Thanks!
dallas6672 commentedon Mar 22, 2022
Is there a work around for older Cisco devices like @lindenaar mentioned?
j2s2 commentedon May 22, 2023
hello,
I faced this bug on some Cisco device and I patched the code to work around (cf. #2242 ). The idea is very simple : if device answers USERAUTH_PK_OK, I resend the precedent message with signature inside.
I've tested the patch on v2.7.2 and it seems to work.
Best regards
bskinn commentedon May 23, 2023
This issue is closed, but represents a use-case that would be good to consider as part of the key/auth overhaul of #387.
bskinn commentedon May 23, 2023
@j2s2:
Is this
paramikov2.7.2? If so, is there any reason you didn't test also onparamiko3.x?j2s2 commentedon May 23, 2023
I've tested it on the main branch of git (this from pull request) but I've also tested it on paramiko v2.7.2 which is the version of Debian 11.