Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Thu, 09 Sep 2010 07:57:03 -0400
From: Brad Tilley <brad@...ystems.com>
To: john-users@...ts.openwall.com
Subject: Re: patch of JtR's netscreen.py script, now version
 2.01

Robert Harris wrote:
> Brad,
> 
> That seems to work both in python 2.6 and python 3.1.2.3.
> 
> I didn't know about the sys.version_info command.
> 
> I kept on getting errors on "m = hashlib.md5(s).digest()", I learned
> something new with "m = hashlib.md5(s.encode('latin_1')).digest()"
> 
> Do you want to create the patch, or shall I?
> 
> -Robert Harris


I'm not sure how you guys patch so it may be better if you do it. Here's
a unified diff (many of may changes are taste related and are irrelevant
to the problem you were working on):


--- netscreen.py	2010-02-28 16:17:12.000000000 -0500
+++ netscreen_rbt.py	2010-09-07 13:02:20.914433390 -0400
@@ -1,37 +1,50 @@
 # netscreen.py
 # Generate passwords in netscreen format.
-#

-import md5
 import sys

 def net(user, password):
-  b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
-  middle = "Administration Tools"
-  s = "%s:%s:%s" % (user, middle, password)
-  m = md5.new(s).digest()
-
-  narray = []
-  for i in range(8):
-    n1 = ord(m[2*i])
-    n2 = ord(m[2*i+1])
-    narray.append( (n1<<8 & 0xff00) | (n2 & 0xff) )
-
-  res = ""
-  for i in narray:
-    p1 = i >> 12 & 0xf
-    p2 = i >> 6  & 0x3f
-    p3 = i       & 0x3f
-    res = res + b64[p1] + b64[p2] + b64[p3]
-
-  for c, n in  zip("nrcstn", [0, 6, 12, 17, 23, 29]):
-	  res = res[:n] + c + res[n:]
-  return res
+
+        b64 =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
+        middle = "Administration Tools"
+        s = "%s:%s:%s" % (user, middle, password)
+
+        # For versions of Python 2.5 and older
+        if sys.version_info[0] == 2 and sys.version_info[1] < 6:
+                import md5
+                m = md5.new(s).digest()
+        else:
+                import hashlib
+                m = hashlib.md5(s.encode('latin_1')).digest()
+
+        narray = []
+        for i in range(8):
+                if sys.version_info[0] == 2:
+                        n1 = ord(m[2*i])
+                        n2 = ord(m[2*i+1])
+                        narray.append( (n1<<8 & 0xff00) | (n2 & 0xff) )
+
+                if sys.version_info[0] == 3:
+                        n1 = ord(chr(m[2*i]))
+                        n2 = ord(chr(m[2*i+1]))
+                        narray.append( (n1<<8 & 0xff00) | (n2 & 0xff) )
+
+        res = ""
+        for i in narray:
+                p1 = i >> 12 & 0xf
+                p2 = i >> 6  & 0x3f
+                p3 = i       & 0x3f
+                res = res + b64[p1] + b64[p2] + b64[p3]
+
+        for c, n in  zip("nrcstn", [0, 6, 12, 17, 23, 29]):
+                 res = res[:n] + c + res[n:]
+        return res


 if __name__ == '__main__':
-  user = sys.argv[1]
-  password = sys.argv[2]
+
+        user = sys.argv[1]
+        password = sys.argv[2]

-  ciphertext = net(user,password)
-  print "%s:%s$%s" % (user,user,ciphertext)
+        ciphertext = net(user,password)
+        print(("%s:%s$%s" % (user,user,ciphertext)))

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.