def handle(self, *args, **options): i = 0 # To convert None to an empty string xstr = lambda s: '' if s is None else str(s) spaces = Space.objects.all() #spaces = spaces.filter(country__in=["US"]) for space in spaces: space_info = [space.name] if space.address1: space_info.append(space.address1) if space.city: space_info.append(space.city) if space.province: space_info.append(space.province) if space.country: space_info.append(str(space.country)) if space.postal_code: space_info.append(space.postal_code) space_stuff = " ".join(space_info).replace(",", "").replace( "-", "").replace(".", "").replace("_", "").replace("+", "") space_string = ' '.join(space_stuff.split()).encode("utf-8") print(space.id) print(str(space_string) + ":" + str(len(space_string))) space.fhash = tlsh.forcehash(space_string) print(space.fhash) print( "-----------------------------------------------------------") space.save()
def compute_1(path, force): try: f = open(path, "rb") data = f.read() if force == 1: hs = tlsh.forcehash(data) else: hs = tlsh.hash(data) return hs except IOError as e: print("cannot find file: ", path) return ""
def compute_1(path,force): try: f = open(path, 'rb') data = f.read() if force == 1: hs = tlsh.forcehash(data) else: hs = tlsh.hash(data) return hs except IOError as e: print('cannot find file: ', path) return ''
def keep_track_save(sender, instance, created, **kwargs): if created: print("create space") else: print("space updated") space_info = [instance.name] if instance.address1: space_info.append(instance.address1) if instance.city: space_info.append(instance.city) if instance.province: space_info.append(instance.province) if instance.country: space_info.append(str(instance.country)) if instance.postal_code: space_info.append(instance.postal_code) space_stuff = " ".join(space_info).replace(",", "").replace( "-", "").replace(".", "").replace("_", "").replace("+", "") space_string = ' '.join(space_stuff.split()).encode("raw_unicode_escape") print(instance.fhash) new_hash = tlsh.forcehash(space_string) instance.fhash = new_hash print(instance.fhash)
def get_hash(symbols_list): symbol_string = ",".join(symbols_list) encoded_symbol_string = symbol_string.encode("ascii", "ignore") return tlsh.forcehash(encoded_symbol_string)
def hash(password, prefixSalt, suffixSalt, multiplier): ''' Correctly hash the provided passwords using the salts and multiplier ''' return tlsh.forcehash( (prefixSalt + (password * multiplier) + suffixSalt).encode("utf-8"))
def get_hash(symbols_list): symbol_string = ",".join(symbols_list) encoded_symbol_string = symbol_string.encode('ascii') return tlsh.forcehash(encoded_symbol_string).lower()
#hex1 = compute_1(sys.argv[1]) #print('tlsh.hash hex1', hex1) #hex2 = compute_1(sys.argv[2]) #print('tlsh.hash hex2', hex2) #print('tlsh.diff(hex1, hex2)', tlsh.diff(hex1, hex2)) #print('tlsh.diff(hex2, hex1)', tlsh.diff(hex2, hex1)) #print('tlsh', tlsh.forcehash(open(sys.argv[1]).read())) files = listdir(sys.argv[1]) for f in files: if str(f).startswith('.'): continue else: filepath = sys.argv[1] + str(f) fmd5 = md5(filepath) ftlsh = tlsh.forcehash(open(filepath).read()) print(f, fmd5, ftlsh) """ h1 = compute_2(sys.argv[1]) hex1 = h1.hexdigest() print('tlsh.Tlsh hex1', hex1) h2 = compute_2(sys.argv[2]) hex2 = h2.hexdigest() print('tlsh.Tlsh hex2', hex2) print('h1.diff(h2)', h1.diff(h2)) print('h2.diff(h1)', h2.diff(h1)) print('h1.diff(hex2)', h1.diff(hex2)) print('h2.diff(hex1)', h2.diff(hex1)) h3 = tlsh.Tlsh() h3.fromTlshStr(hex2)
def computeTlsh(string): string = str.encode(string) hs = tlsh.forcehash(string) return hs
def compute_1(self, path): with open(path, 'rb') as f: data = f.read() hs = tlsh.forcehash(data) return hs
import tlsh import os password = '******' f = open('salt.txt', 'r') saltLines = f.read() salt = saltLines.splitlines() multiplier = 5 incorrectPWArray = [ 'swordfish', 'awordfish', 'aaordfish', 'aaardfish', 'swordfisa', 'swordfiaa', 'swordfaaa', 'aaaaaaaaa', 'zzzzzzzzz', 'swordfis', 'wordfish', 'sordfish', 'swordfisha', 'aswordfish', 'aaswordfish', 'swordfishaa', 'haufkljdioja', ' ' ] incorrectPWCharDifference = [ 0, 1, 2, 3, 1, 2, 3, 9, 9, 1, 1, 1, 1, 1, 2, 2, 12, 9 ] correctCombine = salt[0] + (password * multiplier) + salt[1] hashOutput = tlsh.forcehash(correctCombine.encode("utf-8")) for i in range(len(incorrectPWArray)): incorrectCombine = salt[0] + (incorrectPWArray[i] * multiplier) + salt[1] incorrectHashOutput = tlsh.forcehash(incorrectCombine.encode("utf-8")) diff = tlsh.diff(hashOutput, incorrectHashOutput) print('Attempted password: '******'Character Difference: ' + str(incorrectPWCharDifference[i])) print('difference score: ' + str(diff)) print()
oneInsertionDifference = list() oneDeletionDiffernce = list() oneSubstitutionDifference = list() incorrectDifference = list() oneCapDifference = list() # subPuncDifference = list() multiplier = 5 for password in csvinput["Password"]: password = csvinput.loc[csvinput["Password"] == password, 'Password'].values[0] prefixSalt = csvinput.loc[csvinput["Password"] == password, 'prefixSalt'].values[0] suffixSalt = csvinput.loc[csvinput["Password"] == password, 'suffixSalt'].values[0] passwordHashed = tlsh.forcehash((prefixSalt + (password * multiplier) + suffixSalt).encode("utf-8")) controlHashed = tlsh.forcehash((prefixSalt + ("PASSWORD" * multiplier) + suffixSalt).encode("utf-8")) insertionStr = csvinput.loc[csvinput["Password"] == password, 'oneInsertion'].values[0] insertionStrHashed = tlsh.forcehash((prefixSalt + (insertionStr * multiplier) + suffixSalt).encode("utf-8")) deletionStr = csvinput.loc[csvinput["Password"] == password, 'oneDeletion'].values[0] deletionStrHashed = tlsh.forcehash((prefixSalt + (deletionStr * multiplier) + suffixSalt).encode("utf-8")) substitutionStr = csvinput.loc[csvinput["Password"] == password, 'oneSubstitution'].values[0] substitutionStrHashed = tlsh.forcehash((prefixSalt + (substitutionStr * multiplier) + suffixSalt).encode("utf-8")) incorrectStr = csvinput.loc[csvinput["Password"] == password, 'incorrect'].values[0] incorrectStrHashed = tlsh.forcehash((prefixSalt + (incorrectStr * multiplier) + suffixSalt).encode("utf-8")) capStr = csvinput.loc[csvinput["Password"] == password, 'oneCapMistake'].values[0]