首页 > 解决方案 > 使用 Python 将 ssh 客户端与 Paramiko 连接到 Dell idrac 失败键盘交互式身份验证

问题描述

所以戴尔在他们的新 iDRAC 固件中改变了一些东西,他们在你登录后需要键盘交互式身份验证,而我不能再使用 Paramiko 登录。

https://www.dell.com/community/Systems-Management-General/iDRAC8-2-70-70-70-SSH-keyboard-interactive-authentication/td-p/7427565

有人在论坛里贴了一段代码来修补 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

任何帮助表示赞赏

谢谢

标签: pythonsshparamiko

解决方案


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')

推荐阅读