Skip to content

Instantly share code, notes, and snippets.

@gornostal
Created September 10, 2020 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gornostal/82413d7a805d1b3d54db2932da4d2233 to your computer and use it in GitHub Desktop.
Save gornostal/82413d7a805d1b3d54db2932da4d2233 to your computer and use it in GitHub Desktop.
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:
return
# 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):
kf.seek(0)
try:
nk = rsakey.RSAKey.from_private_key(kf, password=d)
print("success", d)
break
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