Skip to content

Commit

Permalink
Fix multiple bugs in sshng2john.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kholia committed Jan 26, 2013
1 parent 19ccb73 commit 6bc9252
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions run/sshng2john.py
Expand Up @@ -31,10 +31,18 @@

limited = False


class Object(object):
pass

try:
from Crypto.Cipher import DES3, AES
except ImportError:
print >> sys.stderr, "PyCrypto is missing in your Python installation, %s is operating is limited features mode!" % sys.argv[0]
# print >> sys.stderr, "PyCrypto is missing in your Python installation, %s is operating is limited features mode!" % sys.argv[0]
AES = Object()
AES.MODE_CBC = ""
DES3 = Object()
DES3.MODE_CBC = ""
limited = True


Expand Down Expand Up @@ -617,7 +625,8 @@ def _read_private_key(self, tag, f, password=None):
while (start < len(lines)) and (lines[start].strip() != '-----BEGIN ' + tag + ' PRIVATE KEY-----'):
start += 1
if start >= len(lines):
raise SSHException('not a valid ' + tag + ' private key file')
print >> sys.stderr, "%s is not a valid private key file" % f.name
return None
# parse any headers first
headers = {}
start += 1
Expand All @@ -639,7 +648,8 @@ def _read_private_key(self, tag, f, password=None):

if 'proc-type' not in headers:
# unencryped: done
return data
print >> sys.stderr, "%s has no password!" % f.name
return None
# encrypted keyfile: will need a password
if headers['proc-type'] != '4,ENCRYPTED':
raise SSHException('Unknown private key structure "%s"' % headers['proc-type'])
Expand Down Expand Up @@ -674,7 +684,7 @@ def _read_private_key(self, tag, f, password=None):
return ddata
except ValueError: # incorrect password
return data
return None
return self.hash # dummy value


def chunks(l, n):
Expand Down Expand Up @@ -717,6 +727,8 @@ def get_bits(self):
def _from_private_key_file(self, filename, password):
data = self._read_private_key_file('RSA', filename, password)

if not data:
return
if limited:
print self.hash
return
Expand Down

0 comments on commit 6bc9252

Please sign in to comment.