有人尝试使用Paramiko连接到Cisco ASA吗?

我使用以下脚本:

import sys
import os
import paramiko


paramiko.util.log_to_file("ssh_conn.log")

ssh_client = paramiko.SSHClient()
print ('client created')
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print ('key policy set')
ssh_client.connect(hostname='10.10.10.10', username='user', password='pass', port=22)
print ('client connected')
(stdin, stdout, stder) = ssh_client.exec_command('show version')
print ('command sent')
data = stdout.readlines()
print ('data read')
stdout.close()
ssh_client.close()
print ('session closed')
print (data)

它与Cisco IOS(路由器)很好地配合使用,但是当我尝试连接到ASA设备时在“命令发送”之后挂起。

Paramiko日志包含以下消息:
DEB [20140718-18:12:52.534] thr=1   paramiko.transport: starting thread (client mode): 0x23902b0
INF [20140718-18:12:52.537] thr=1   paramiko.transport: Connected (version 2.0, client Cisco-1.25)
DEB [20140718-18:12:52.923] thr=1   paramiko.transport: kex algos:['diffie-hellman-group1-sha1'] server key:['ssh-rsa'] client encrypt:['aes128-cbc', '3des-cbc', 'aes192-cbc', 'aes256-cbc'] server encrypt:['aes128-cbc', '3des-cbc', 'aes192-cbc', 'aes256-cbc'] client mac:['hmac-sha1', 'hmac-sha1-96', 'hmac-md5', 'hmac-md5-96'] server mac:['hmac-sha1', 'hmac-sha1-96', 'hmac-md5', 'hmac-md5-96'] client compress:['none'] server compress:['none'] client lang:[''] server lang:[''] kex follows?False
DEB [20140718-18:12:52.923] thr=1   paramiko.transport: Ciphers agreed: local=aes128-cbc, remote=aes128-cbc
DEB [20140718-18:12:52.924] thr=1   paramiko.transport: using kex diffie-hellman-group1-sha1; server key type ssh-rsa; cipher: local aes128-cbc, remote aes128-cbc; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
DEB [20140718-18:12:53.040] thr=1   paramiko.transport: Switch to new keys ...
DEB [20140718-18:12:53.041] thr=2   paramiko.transport: Adding ssh-rsa host key for 10.10.10.10: b'10d3ea97246086679196bda085796063'
DEB [20140718-18:12:53.066] thr=1   paramiko.transport: userauth is OK
INF [20140718-18:12:53.084] thr=1   paramiko.transport: Authentication (password) successful!
DEB [20140718-18:12:53.084] thr=2   paramiko.transport: [chan 1] Max packet in: 34816 bytes
DEB [20140718-18:12:53.089] thr=1   paramiko.transport: [chan 1] Max packet out: 4096 bytes
INF [20140718-18:12:53.089] thr=1   paramiko.transport: Secsh channel 1 opened.
DEB [20140718-18:12:53.094] thr=1   paramiko.transport: [chan 1] Sesch channel 1 request ok

我在设备上看到 Activity 的SSH session ,但是输出“命令已发送”后,脚本挂起

最佳答案

这是我用于连接到Cisco ASA的过程:

import paramiko
ip = '1.1.1.16'
username = 'testuser'
password = 'password'
remote_conn_pre=paramiko.SSHClient()
remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())
remote_conn_pre.connect(ip, username=username, password=password,
                        look_for_keys=False, allow_agent=False)
remote_conn = remote_conn_pre.invoke_shell()
output = remote_conn.recv(65535)
print output
remote_conn.send('enable\n')
remote_conn.send(password + '\n')
output = remote_conn.recv(65535)
print output

我还一直在研究库(Netmiko),以简化一些Paramiko SSH处理。在https://github.com/ktbyers/netmiko

关于python - 使用Cisco ASA的paramiko,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24827276/

10-13 09:24