python - 测试 SSH 私钥密码(暴力破解)

标签 python ssh subprocess ssh-keys brute-force

我在编写 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/

相关文章:

python - 尝试安装 python asyncio 时失败

python - 为什么 pysqlite 不能正常工作?

ssh - hell AesCtrCryptoTransform

git - 是否可以将 scp/git 从我的本地机器推送到托管在 AWS 中的 docker 容器?

python - 无法在 Google 虚拟机 SSH 终端中打开 .py 文件

audio - 带有python子进程Popen的ffmpeg

python - 如何使用相对引用使用子进程运行复杂的python命令?

python - Google App Engine - 开发服务器上的代理/隧道权限被拒绝

python - 了解 Django Q - 动态

Python 可执行文件到 Linux 列表文件的大小