paramiko with Cisco ASA



是否有人尝试使用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设备时,在"command sent"之后挂起。

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

我在设备上看到活跃的SSH会话,但是我的脚本在输出"command sent"后挂起

下面是我连接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('enablen')
remote_conn.send(password + 'n')
output = remote_conn.recv(65535)
print output

我也一直在做一个库(Netmiko)来简化一些Paramiko SSH处理。网址:https://github.com/ktbyers/netmiko

在命令末尾添加一个换行符(n):

:

(stdin, stdout, stder) = ssh_client.exec_command('show version')
:后

(stdin, stdout, stder) = ssh_client.exec_command('show versionn')

最新更新