Monday, August 24, 2020

Custom Password Generator tool and Weblogic Embedded LDAP automated password reset

**The tool is a custom one created for use in my current organization, by myself. Copyright lies with me.**

This tool creates a random password, pulls the e-mail IDs of users from database, resets the user's passwords and notifies them over email.

This is specific to Oracle CC&B application using embedded LDAP authentication.

Components of the Tool:

Files-----------------------

file.properties: Properties file

user.txt: User ID list

words.txt: Random words that'll be used to generate the passwords

punct.txt: Special characters

get_email.sql: PL/SQL query to fetch user's email ID from database table

Scripts---------------------

Password_generator.py

append.sh


Script Body

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

#Script created by Debomitra Roy, to create password

from java.io import FileInputStream

print ("############Custom script to generate random passwords will start now#############")

print ("#####################Script created by Debomitra Roy for SEWA#####################")

propInputStream = FileInputStream("file.properties")

configProps = Properties()

configProps.load(propInputStream)

import os

string = configProps.get("stringfile")

inputfile = configProps.get("inputfile")

punct =  configProps.get("punct")

userfile =  configProps.get("userfile")

efile=configProps.get("efile")

subjecta=configProps.get("subjecta")

subjectb=configProps.get("subjectb")

subjectc=configProps.get("subjectc")

subjectd=configProps.get("subjectd")

me=configProps.get("from")

domainName=configProps.get("domain.name")

adminURL=configProps.get("admin.url")

connect(url=adminURL,userConfigFile='/ouaf/cissys/debo_scripts/Reset_pass_user/keyfile/uatuserconfigfile.secure',userKeyFile='/ouaf/cissys/debo_scripts/Reset_pass_user/keyfile/uatuserkeyfile.secure')

os.system("sed -e '/^$/d' user.txt > user1.txt")

os.system("sort user1.txt| uniq -u > modified_user.txt")

fin=open(inputfile)

for line in fin.readlines():

  words = line.split()

  count = len(line.split())

  count1 = 0

  while(count1<count):

   for word in words:

     p=open(punct)

     for spl in p.readlines():

         spcl = spl.split()

         spcl=spcl[count1]

         word1 = word[-2]

         word2 = word[-3]

         word3 = word[0]

         word4 = word[-1]

         pas= word4 + word2 + word3 + word1 + spcl

         file_object = open('pass.txt', 'a+')

         data = file_object.read(100)

         file_object.write(pas)

         file_object.write("\n")

         file_object.close()

         count1+=1

  else:

   print "Complete"

os.system('mv passstring.txt ./backup/passstring.txt_old')

usr=open(userfile)

i=1

for lin in usr.readlines():

 each = lin.strip()

 i+=1

 tail=each[-3:]

 file_object = open('passstring.txt', 'a+')

 file_object.write(tail)

 file_object.write("\n")

 file_object.close()

os.system('sh append.sh')

print "########Passwords have been generated########"

print ("############Custom script to reset passwords will start now#############")

print ("#####################Script created by Debomitra Roy for SEWA#####################")

fin=open(efile)
for line in fin.readlines():
  words = line.split()
  atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider("DefaultAuthenticator")
  atnr.resetUserPassword(words[0],words[2])
  import smtplib
  msga = subjecta + " " + words[0] + " " + subjectb
  msgb = subjectc + " " + words[2]
  sub = ("High importance: %s\r\n\r\n%s\r\n\r\n%s\r\n(This is a system generated message)\r\n" %(msga, msgb, subjectd))
  mailid=words[1]
  s = smtplib.SMTP('localhost')
  s.sendmail(me, [mailid], sub)
  print "Password for user ID " + words[0] + " has been reset and communicated to user at " + mailid
  s.quit()
else:
  print "Complete"
os.system('sh flag.sh')
os.system('rm -f email.txt')
print "List of ID and passwords removed"
print "Copyright: Debomitra Roy"
disconnect()


append.sh

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

#!/bin/bash

count=`cat passstring.txt|wc -l`

i=1

count=$count+1

x=`ls passwords.txt`

d=`date +"%d_%m_%Y`

mv $x ./backup/passwords.txt_d

while [  $i -lt $count ]; do

 id=`sed -n "$i p" passstring.txt`

 wrd=`sed -n "$i p" pass.txt`

 str2=$wrd$id

 i=$(($i+1))

 echo $str2 >> passwords.txt

done

####Get email ID####

sort user.txt|uniq -d > check.txt

if [ -s check.txt ]

then

 echo "Duplicate values are there, check in file. Duplicate values will be skipped."

 mailx -s "Check duplicates in user list" debomitra.roy@sewa.gov.ae < /ouaf/cissys/debo_scripts/Reset_pass_user/module_uat/check.txt

else

 echo "File is empty, no duplicate values"

fi

count=`cat modified_user.txt|wc -l`

count=$count+1

i=1

x=`ls modified_user.txt`

mv email.txt ./backup/email.txt_d

while [  $i -lt $count ]; do

 mid=`sed -n "$i p" modified_user.txt`

 #echo $mid

 sqlplus -S usermod/usermod@CCBTEST @get_email.sql $mid > output.log

 eid=`tail -2 output.log|head -1`

 strng="no rows selected"

 if [ "$eid" = "$strng" ];

 then

  echo "No email ID found for user ID $mid, will skip writing output to file"

  #echo "Skip" >> email.txt

 else

  pass=`sed -n "$i p" passwords.txt`

  echo $mid $eid $pass >> email.txt

  echo "Email ID written to file successfully"

 fi

 i=$(($i+1))

done

exit 0


No comments:

Post a Comment