python - 使用 Python 将 ssh 客户端与 Paramiko 连接到 Dell idrac 失败键盘交互式身份验证
问题描述
所以戴尔在他们的新 iDRAC 固件中改变了一些东西,他们在你登录后需要键盘交互式身份验证,而我不能再使用 Paramiko 登录。
有人在论坛里贴了一段代码来修补 Paramiko client.py 我在 connect 函数中添加了以下内容
if password is not None:
try:
self._transport.auth_password(username, password)
return
self._log(DEBUG, "trying password")
allowed_types = self._transport.auth_password(username, password)
if not allowed_types:
return
except SSHException as e:
saved_exception = e
elif two_factor:
if 'keyboard-interactive' in allowed_types:
try:
self._log(DEBUG, "trying interactive")
self._transport.auth_interactive_dumb(username)
return
except SSHException as e:
saved_exception = e
但仍然有同样的错误。这是我正在使用的 ssh 连接功能。
def connectSSH(my_file, user_name, password):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ip = str(my_file.split(',')[0]).strip()
try:
ssh.connect(ip, 22, user_name, password, look_for_keys=False)
return ssh
except:
with open(f'{ip}.txt', 'a') as f:
f.writelines(ip + '\t COULDN\'T CONNECT\n')
当我在空闲时运行它时它会连接但说等待身份验证
ssh.get_transport() <paramiko.Transport at 0xe43670(密码 aes128-ctr,128 位)(已连接;等待身份验证)>
这是我得到的追溯
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
stdin, stdout, stderr = ssh.exec_command('racadm getsysinfo')
File "C:\Users\kevinc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\client.py", line 508, in exec_command
chan = self._transport.open_session(timeout=timeout)
File "C:\Users\kevinc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\transport.py", line 875, in open_session
return self.open_channel(
File "C:\Users\kevinc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\transport.py", line 1006, in open_channel
raise e
File "C:\Users\kevinc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\transport.py", line 2055, in run
ptype, m = self.packetizer.read_message()
File "C:\Users\kevinc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\packet.py", line 459, in read_message
header = self.read_all(self.__block_size_in, check_rekey=True)
File "C:\Users\kevinc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\packet.py", line 303, in read_all
raise EOFError()
EOFError
任何帮助表示赞赏
谢谢
解决方案
nvm 我发现它不知道有一种方法可以向连接发送虚假条目,无需编辑 client.py 文件
如果有人需要,这是我的连接方法**编辑注意到,如果它是旧版本并且不需要进一步的身份验证,它将失败,所以我进行了检查
def connectSSH(my_file, user_name, password):
ip = str(my_file.split(',')[0]).strip()
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(ip, 22, user_name, password)
key_auth = str(ssh.get_transport())
if 'awaiting auth' in key_auth:
(ssh.get_transport()).auth_interactive_dumb(user_name)
return ssh
except:
with open(f'{ip}.txt', 'a') as f:
f.writelines(ip + '\t COULDN\'T CONNECT\n')
推荐阅读
- angular - Angular 从服务中动态创建和销毁组件
- vba - VBA。根据来自另一个表格的匹配替换表格单元格内容,或者如果未找到匹配则删除整行
- android - 实现了哪种数据结构来管理手机中的文件和文件夹?
- angular5 - import Routes [ts] 'types' 只能在 .ts 文件中使用。虽然它们已经在 app.module.ts 中
- javascript - Xamarin Android WebView - JDE E1 Web 门户
- python - NaN 设置为 -1 时缩放特征的效果
- arrays - 如何显示数组的元素?
- node.js - 获取 PNG 图像时出现意外的缓冲区结果
- mongodb - MongoDB中的大数据是什么?
- angular - 找不到 API 编译器-cli,函数 __NGTOOLS_PRIVATE_API_2