我在编写 Python 脚本来暴力破解 /.ssh/id_rsa
文件的 SSH 私钥密码时遇到问题。我正在使用 ssh-add
命令询问密码,直到您输入密码为止。
但是脚本失败并出现错误:
ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory
我不明白为什么。
使用 .Popen
、.call
等尝试了子进程模块的所有变体。但我认为最适合我的情况的是:
import subprocess
p = subprocess.Popen('ssh-add id_rsa', stdin=subprocess.PIPE, text=True, shell=True)
p.stdin.write(str('password'))
预期的密码请求,例如“输入 id_rsa 的密码”
最佳答案
我建议您使用 Paramiko,而不是使用外部控制台工具。
使用RSAKey
class (or DSSKey
, ECDSAKey
, Ed25519Key
) :
key = paramiko.RSAKey.from_private_key_file(filename, passphrase)
如果密码错误,它会抛出异常。
关于python - 测试 SSH 私钥密码(暴力破解),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58403221/