#!/usr/bin/python2 # This script is a compliment to ngrep_analyzing_tool.html #---------- Import all modules ---------- from os import popen from crypt import crypt from random import random from string import letters, digits #---------- Create all global variables ---------- path = "{Add the path to the input file here}" #---------- Open the username file and get a list of usernames and passwords ---------- userFile = open(path, 'r') userNames = userFile.readlines() userFile.close() #---------- Begin loop to create users from file ---------- for i in range(len(userNames)): #---------- Create local variables ---------- rndStr = "" jeckylHide = userNames[i].split() #---------- Create 'salt' ---------- validStr = letters + digits validStrArray = list(validStr) rndRange = len(validStr) for j in range(8): r = int(rndRange*random()) rndStr = rndStr + validStrArray[r] salt = '$1$' + rndStr + '$' #---------- Create hash from username, and randomised salt ---------- maryJane = crypt(jeckylHide[1], salt) #---------- Create the command to add users ---------- command = "useradd -M -s /bin/false -p '%s' %s" % (maryJane, jeckylHide[0]) #---------- Print the results, and run the command ---------- print "The username is: " + jeckylHide[0] print "The password is: " + jeckylHide[1] print "The salt is: " + salt print "The hash is: " + maryJane print command print popen(command) # #---------- Other Notes ---------- # # NEEDS PYTHON 2.x OR ABOVE # # This script was designed to create users for email accounts. # They are users with no shell access, or home directory. # See 'man useradd' for further details. # # Currently this script is creating MD5 compliant password # hashes. # # For DES compliance, only 2 characters are required for # salt, and no "$1$" or "$" on either end of the salt. # To create DES compliant hashes, edit the "j" for-loop. # # With the current setup the input file should be in the format: # # username password # # However, if a delimiter is used, you can modify # the split function in line 20 to accomodate. #