kompotkot
kompotkot

Reputation: 19

Test SSH private key passphrase (brute-force)

I have a problem with writing Python script which brute-force SSH private key passphrase for /.ssh/id_rsa file. I am using ssh-add command that ask passphrase until you enter it.

But script fail with error:

ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory

I don't understand why.

Tried all variations of subprocess module with .Popen, .call and etc. But I think most suitable for my situation is:

import subprocess

p = subprocess.Popen('ssh-add id_rsa', stdin=subprocess.PIPE, text=True, shell=True)
p.stdin.write(str('password'))

Expected password request, like "Enter passphrase for id_rsa"

Upvotes: 1

Views: 1296

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202272

I suggest you use Paramiko, instead of hassling with an external console tool.

Use RSAKey class (or DSSKey, ECDSAKey, Ed25519Key):

key = paramiko.RSAKey.from_private_key_file(filename, passphrase)

It throws an exception, if the passphrase is wrong.

Upvotes: 3

Related Questions