Created
September 10, 2020 04:54
-
-
Save gornostal/82413d7a805d1b3d54db2932da4d2233 to your computer and use it in GitHub Desktop.
RSA password bruteforce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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