From 6bc9252342445e16ebc698a2568762c62e5d7f94 Mon Sep 17 00:00:00 2001 From: Dhiru Kholia Date: Sat, 26 Jan 2013 18:42:52 +0530 Subject: [PATCH] Fix multiple bugs in sshng2john.py --- run/sshng2john.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/run/sshng2john.py b/run/sshng2john.py index 12a6f60ece..8d287fe70e 100755 --- a/run/sshng2john.py +++ b/run/sshng2john.py @@ -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 @@ -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 @@ -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']) @@ -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): @@ -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