Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <4C86711B.8040401@16systems.com>
Date: Tue, 07 Sep 2010 13:06:35 -0400
From: Brad Tilley <brad@...ystems.com>
To: john-users@...ts.openwall.com
Subject: bug in netscreen.py I sent earlier

I wasn't checking for Python < 2.6 correctly. Still rough, but seems to
work OK on Python 2 or 3:

----------------

# netscreen.py
# Generate passwords in netscreen format.

import sys

def net(user, password):

        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]

        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.