Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate

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 

  1. #!/usr/bin/python
  2.  
  3. import os, md5, sys
  4.  
  5. def md5crypt(password, salt, magic='$1$'):
  6.     # /* The password first, since that is what is most unknown */ /* Then our magic string */ /* Then the raw salt */
  7.     m = md5.new()
  8.     m.update(password + magic + salt)
  9.  
  10.     # /* Then just as many characters of the MD5(pw,salt,pw) */
  11.     mixin = md5.md5(password + salt + password).digest()
  12.     for i in range(0, len(password)):
  13.         m.update(mixin[i % 16])
  14.  
  15.     # /* Then something really weird... */
  16.     # Also really broken, as far as I can tell.  -m
  17.     i = len(password)
  18.     while i:
  19.         if i & 1:
  20.             m.update('\x00')
  21.         else:
  22.             m.update(password[0])
  23.         i >>= 1
  24.  
  25.     final = m.digest()
  26.  
  27.     # /* and now, just to make sure things don't run too fast */
  28.     for i in range(1000):
  29.         m2 = md5.md5()
  30.         if i & 1:
  31.             m2.update(password)
  32.         else:
  33.             m2.update(final)
  34.  
  35.         if i % 3:
  36.             m2.update(salt)
  37.  
  38.         if i % 7:
  39.             m2.update(password)
  40.  
  41.         if i & 1:
  42.             m2.update(final)
  43.         else:
  44.             m2.update(password)
  45.  
  46.         final = m2.digest()
  47.  
  48.     # This is the bit that uses to64() in the original code.
  49.  
  50.     itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
  51.  
  52.     rearranged = ''
  53.     for a, b, c in ((0, 6, 12), (1, 7, 13), (2, 8, 14), (3, 9, 15), (4, 10, 5)):
  54.         v = ord(final[a]) << 16 | ord(final[b]) << 8 | ord(final[c])
  55.         for i in range(4):
  56.             rearranged += itoa64[v & 0x3f]; v >>= 6
  57.  
  58.     v = ord(final[11])
  59.     for i in range(2):
  60.         rearranged += itoa64[v & 0x3f]; v >>= 6
  61.  
  62.     return magic + salt + '$' + rearranged
  63.  
  64.  
  65. if __name__ == "__main__":
  66.     fd = file(sys.argv[1])
  67.     for line in fd.readlines():
  68.         (firstname,lastname) = line.strip().split(",")
  69.         fullname = "%s %s" % (firstname, lastname)
  70.         username = ("%s%s" % (firstname[0], lastname)).lower()
  71.         cryptpassword = md5crypt(username, 'npBmgt75')
  72.         command = "useradd '%s' -m -d '/home/%s' -c '%s' -p '%s'" % (username, username, fullname, cryptpassword)
  73.  
  74.         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.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



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.

comments powered by Disqus
worth-right
worth-right