Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
RSA password bruteforce
#!/usr/bin/env python3
import paramiko
from paramiko import rsakey
kf = open("/root/.ssh/old/id_rsa", "r")
prefix = "prefix"
chars = {"a", "b", "c"}
def passgen(prefix, chars):
if not chars:
# TODO: re-implement using an iterative approach to improve performance
for c in chars:
newp = ''.join([prefix, c])
yield newp
yield from passgen(newp, chars - {c})
for d in passgen(prefix, chars):
nk = rsakey.RSAKey.from_private_key(kf, password=d)
print("success", d)
except paramiko.ssh_exception.SSHException:
print("fail", d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment