Skip to content

Connection with CISCO by private-key throwing 'Illegal info request from server' #122

Closed

Description

@fmiceli

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)

ssh.connect(hostname, username='ceibal', password='55hReMoTo!', port=2222, look_for_keys=False)

ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('show running')

Activity

  1. ghalevy commented on Jun 9, 2014

    @ghalevy

    Was this ever answered? I'm having a similar issue and am curious if/how you resolved it.

  2. fmiceli commented on Jun 9, 2014

    @fmiceli
    Author

    Never answered. Ended up using subprocess and pexpect.

    Regards,

    2014-06-09 15:44 GMT-03:00 Gilad Halevy [email protected]:

    Was this ever answered? I'm having a similar issue and am curious if/how
    you resolved it.

    —
    Reply to this email directly or view it on GitHub
    #122 (comment).

    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

  3. ghalevy commented on Jun 9, 2014

    @ghalevy

    That's too bad. Paramiko seems very feature rich and would be infinitely more useful with good tutorials and support responsiveness.

  4. lndbrg commented on Jun 11, 2014

    @lndbrg
    Contributor

    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.

  5. StephanieSunshine commented on Jun 11, 2014

    @StephanieSunshine

    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.

  6. lndbrg commented on Jun 11, 2014

    @lndbrg
    Contributor

    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.

  7. bitprophet commented on Aug 8, 2014

    @bitprophet
    Member

    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!

  8. toghraee commented on May 26, 2017

    @toghraee

    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:

  9. lindenaar commented on May 15, 2018

    @lindenaar

    I bumped into this problem today when trying to connect to one of my older Cisco devices using:

    #! /usr/bin/env python
    
    import os
    import logging
    import paramiko
    
    logging.getLogger("paramiko").setLevel(logging.DEBUG)
    paramiko.util.log_to_file("paramiko.log")
    
    ssh = paramiko.SSHClient()
    ssh.load_system_host_keys(os.environ['HOME'] + '/.ssh/known_hosts')
    ssh.set_missing_host_key_policy(paramiko.WarningPolicy())
    ssh.connect('router', allow_agent='True')
    
    ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('show clock')
    for line in ssh_stdout.readlines():
        print line
    
    ssh.close()
    

    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:

    Traceback (most recent call last):
      File "./paramiko_test.py", line 14, in <module>
        ssh.connect('router', allow_agent='True')
      File "/Users/jfl/projects/ansible/lib/python2.7/site-packages/paramiko/client.py", line 424, in connect
        passphrase,
      File "/Users/jfl/projects/ansible/lib/python2.7/site-packages/paramiko/client.py", line 714, in _auth
        raise saved_exception
    paramiko.ssh_exception.PasswordRequiredException: Private key file is encrypted
    

    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_request is called though self.auth_method is 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.

  10. lindenaar commented on May 16, 2018

    @lindenaar

    Did some more testing, just to add, when NOT using public key authentication, the same problem occurs unless allow_agent is set to False, i.e. the following code works but still triggers the same exception in line 622 when allow_agent is True - 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 mode

    #! /usr/bin/env python
    
    import os
    import getpass
    import logging
    import paramiko
    
    logging.getLogger("paramiko").setLevel(logging.DEBUG)
    paramiko.util.log_to_file("paramiko.log")
    
    ssh = paramiko.SSHClient()
    ssh.load_system_host_keys(os.environ['HOME'] + '/.ssh/known_hosts')
    ssh.set_missing_host_key_policy(paramiko.WarningPolicy())
    ssh.connect('router',  key_filename=None, allow_agent=False,
            username=os.environ['LOGNAME'], password=getpass.getpass())
    
    ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('show clock')
    for line in ssh_stdout.readlines():
        print line
    
    ssh.close()
    

    Any suggestions what to test / debug further?

  11. adobloug commented on Jan 18, 2019

    @adobloug

    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

  12. radssh commented on Jan 18, 2019

    @radssh
    Contributor

    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 be SSH_MSG_USERAUTH_SUCCESS or SSH_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_OK back to the client to request a packet that includes the signature, even though the previous packet already included it.

  13. adobloug commented on Jan 21, 2019

    @adobloug

    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.

  14. lindenaar commented on Oct 11, 2019

    @lindenaar

    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!

  15. dallas6672 commented on Mar 22, 2022

    @dallas6672

    Is there a work around for older Cisco devices like @lindenaar mentioned?

  16. j2s2 commented on May 22, 2023

    @j2s2

    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

  17. bskinn commented on May 23, 2023

    @bskinn
    Contributor

    This issue is closed, but represents a use-case that would be good to consider as part of the key/auth overhaul of #387.

  18. bskinn commented on May 23, 2023

    @bskinn
    Contributor

    @j2s2:

    I've tested the patch on v2.7.2 and it seems to work.

    Is this paramiko v2.7.2? If so, is there any reason you didn't test also on paramiko 3.x?

  19. j2s2 commented on May 23, 2023

    @j2s2

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions