Suppose I wanted to have this script run through more than one shadow file, what
ID: 3729393 • Letter: S
Question
Suppose I wanted to have this script run through more than one shadow file, what would the code look like? So it would go through/open shadow one then shadow 2 etc....
I have 3 files total. Shadow1-3
import hashLib #Open the files in read mode shadowopen('shadow1', 'r') dictionary = openCdictionary.txt', 'r') #Loop through all lines in the shadow file for line in shadow: #Split username:MDShash the line using the ":" delimiter entry line . split(':' ,1) The first item in the list of split values is the username #We also strip the values of any invisible characters #in the beginning or end using the strip() function user entry[0].stripO) #The hash value is the next hash = entry[1] . strip #Reset the dictionary file cursor to the start of the file dictionary.seek(0,0) #For each line in the shadow file loop #through all lines in the dictionary for word in dictionary: #For each line in the shadow file loop through all lines in the #dictionary and salt values from 0x00 to 0xFF for i in range(256): salt = chr(i) password = Word. strip saltedpassword salt password We initialize the MD5 hashlib object in the loop so that #it reinitializes every time, clearing its contents x = hashlib.md50 #Compute the digest x.update(saltedpassword) #if the generated hash matches the shadow hash --> Success! if (x.hexdigest() == hash): print '::.format(user, i, passwordExplanation / Answer
To rad multiple files for same code you need to apply following code ::::::::::::
#Array of file names that you want to read
shadow_files = ["File1", "File2", "File3"]
#Access each file in array one by one
for s_file in shadow_files:
#Open one file at a time
shadow = open(s_file, 'r')
#Paste your code here
So, your code will look like ::::::::::
import hashlib
shadow_files = ["Shadow1", "Shadow2", "Shadow3"]
for s_file in shadow_files:
print (s_file + '************************')
#Open file in read mode
shadow = open(s_file, 'r')
dictionary = open('dictionary.txt', 'r')
#Loop through all lines in the shadow file
for line in shadow:
#Split username:MD5hash the line using the ":" delimiter
entry = line.split(':',1)
#The first item in the list of split values is the username
#We also strip the values of any invisible characters
#in the beginning or end using the strip() function
user = entry[0].strip()
#The hash value is the next
hash = entry[1].strip()
#Reset the dictionary file cursor to the start of the file
dictionary.seek(0, 0)
#For each line in the shadow file loop
#through all lines in the dictionary
for word in dictionary:
#For each line in the shadow file loop through all lines in the
#dictionary and salt values from 0x00 to 0xFF
for i in range(256):
salt = chr(i)
password = word.strip()
saltedpassword = salt + password
#We initialize the MD5 hashlib object in the loop so that
#it reinitializes every time, clearing its contents
x = hashlib.md5()
#Compute the digest
x.update(saltedpassword)
#if the generated hash matches the shadow hash --> Success!
if(x.hexdigest() == hash):
print '{}:{}:{}'.format(user, i, password)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.