Advertising
Paste Description for Unnamed
Takes file in the following format:
Joe,Schmoe
John,Doe
Jane,Watson
To generate accounts, run 'sudo python create_users.py '
- Unnamed
- Thursday, November 1st, 2007 at 7:27:16pm UTC
- #!/usr/bin/python
- import os, md5, sys
- def md5crypt(password, salt, magic='$1$'):
- # /* The password first, since that is what is most unknown */ /* Then our magic string */ /* Then the raw salt */
- m = md5.new()
- m.update(password + magic + salt)
- # /* Then just as many characters of the MD5(pw,salt,pw) */
- mixin = md5.md5(password + salt + password).digest()
- for i in range(0, len(password)):
- m.update(mixin[i % 16])
- # /* Then something really weird... */
- # Also really broken, as far as I can tell. -m
- i = len(password)
- while i:
- if i & 1:
- m.update('\x00')
- else:
- m.update(password[0])
- i >>= 1
- final = m.digest()
- # /* and now, just to make sure things don't run too fast */
- for i in range(1000):
- m2 = md5.md5()
- if i & 1:
- m2.update(password)
- else:
- m2.update(final)
- if i % 3:
- m2.update(salt)
- if i % 7:
- m2.update(password)
- if i & 1:
- m2.update(final)
- else:
- m2.update(password)
- final = m2.digest()
- # This is the bit that uses to64() in the original code.
- itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
- rearranged = ''
- for a, b, c in ((0, 6, 12), (1, 7, 13), (2, 8, 14), (3, 9, 15), (4, 10, 5)):
- v = ord(final[a]) << 16 | ord(final[b]) << 8 | ord(final[c])
- for i in range(4):
- rearranged += itoa64[v & 0x3f]; v >>= 6
- v = ord(final[11])
- for i in range(2):
- rearranged += itoa64[v & 0x3f]; v >>= 6
- return magic + salt + '$' + rearranged
- if __name__ == "__main__":
- fd = file(sys.argv[1])
- for line in fd.readlines():
- (firstname,lastname) = line.strip().split(",")
- fullname = "%s %s" % (firstname, lastname)
- username = ("%s%s" % (firstname[0], lastname)).lower()
- cryptpassword = md5crypt(username, 'npBmgt75')
- command = "useradd '%s' -m -d '/home/%s' -c '%s' -p '%s'" % (username, username, fullname, cryptpassword)
- os.system(command)
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.