Skip to content
Permalink
Browse files
Simple Salting Added
  • Loading branch information
aa9863 committed Oct 15, 2021
1 parent edd4366 commit 90b6418120267e3712cf515614ff7c930eb5dd39
Showing 1 changed file with 110 additions and 0 deletions.
@@ -0,0 +1,110 @@
"""
Test Cases and Demo code for Salted Hashed
"""

import unittest
import time
import hashlib

TARGETS = ["283140d63e0937fb652ff7066bbf5c2f",
"ba7c94b0431f30103c7eb5cdae180be6",
"ff0e0cefdceb54618f47767d17b95a12",
"ef98a984f8ab1341039f9f3344d80298",
"25e2262b5d8c95f7ece0bc4f30f5213d"]

CORRECT_MATCHES = {'283140d63e0937fb652ff7066bbf5c2f': 'coffee',
'ba7c94b0431f30103c7eb5cdae180be6': 'azerty',
'ff0e0cefdceb54618f47767d17b95a12': 'spitfire',
'ef98a984f8ab1341039f9f3344d80298': 'f00tball',
'25e2262b5d8c95f7ece0bc4f30f5213d': '1qazxsw23edc'}



def simpleSalt(plaintext):
"""
Simple Salting Strategy
"""
return "{0}SALT".format(plaintext)


#And modify the function with lookups we used before

def crackList_Lookup_Salt(wordlist, targets):
"""
This time we hash everything and stash in a dictionry (or DB),
then do a lookup.
This time we just add the SALT to the plantext, before we generate the Hash
"""

#Somewhere to store the hashes
hashLookup = {}

#Go through the wordlist and get the hash for each item.
for plaintext in wordlist:
plaintext = plaintext.strip()
saltedText = simpleSalt(plaintext)
theHash = hashlib.md5(saltedText.encode()).hexdigest()
#Store in the "Database"
hashLookup[theHash] = plaintext

#Now look for the cracked passwords using the dict
matches = {}
for item in targets:
matches[item] = hashLookup.get(item)

return matches





class TestCases(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""
A bit of magic to keep the stats.
Called the first time the class is run
"""

cls.statsDict = {}

@classmethod
def tearDownClass(cls):
"""
And a bit more magic to print the stats.
"""

print("\n\n{0} STATS (List) {0}".format("-"*20))

print("Crack With Simple Salt: {0}".format(cls.statsDict["simpleSalt"]))
#print("Crack Lookup Tab: {0}".format(cls.statsDict["lookup"]))

def setUp(self):
"""
Load the wordlist each time we run a test case
Here we open the wordlist file, then store it as an array
This lets us reuse the list multiple times
"""

with open("10-million-password-list-top-10000.txt") as fd:
#Store as an array
self.wordlist = fd.readlines()


def testList_SimpleSalt(self):
"""
Check how long it takes with the simple salting strategy
This should be something close to the Lookup table for the list
"""

t1 = time.time()
out = crackList_Lookup_Salt(self.wordlist, TARGETS)
t2 = time.time()
#print(out)
self.assertEqual(out, CORRECT_MATCHES) #check we were successful
self.statsDict["simpleSalt"] = t2-t1

0 comments on commit 90b6418

Please sign in to comment.