def verify_password(self, password): """ Verifies a plain-text password with the hashed in the current user. :param password: A plain-text password (must be of type str, not unicode!) :type password str :return: True if the password was verified, false otherwise :rtype boolean """ from auth.constants import PEPPERS # Get number of iterations # Get current salt and digest algorithm, iterations, salt, digest = self.password.split("$")[1:] salt = salt.decode('hex') digest = digest.decode('hex') iterations = int(iterations) if algorithm.startswith('pbkdf2'): algorithm, sha = algorithm.split("_") hash_func = getattr(hashlib, sha, 'sha512') else: raise ValueError("Unknown hash func") # Append the project salt to the end of the given user password password = password + current_app.config['PROJECT_SALT'] # Shuffle the peppers to be faster on average random.shuffle(PEPPERS) for pepper in PEPPERS: # The password is now: pepper + password + project salt pwd = pepper + password if pbkdf2_ctypes.pbkdf2_bin(data=pwd, salt=salt, iterations=iterations, hashfunc=hash_func) == digest: # Bcrypt have now confirmed that the password was correct! return True # None of the peppers made the password correct, password incorrect! return False
def crackProcess(Ssid, Passphrase, ClientMac, APMac, ANonce, SNonce, Mic, Data): #Replace Mic in Data with zeros Data = Data.replace(Mic, "00000000000000000000000000000000") #apply a2b_hex ClientMac = a2b_hex(ClientMac) APMac = a2b_hex(APMac) ANonce = a2b_hex(ANonce) SNonce = a2b_hex(SNonce) Mic = a2b_hex(Mic) Data = a2b_hex(Data) #build pke pke = "Pairwise key expansion" + '\x00' + min(APMac, ClientMac) + max( APMac, ClientMac) + min(ANonce, SNonce) + max(ANonce, SNonce) #generate pmk pmk = pbkdf2_bin(Passphrase, Ssid, 4096, 32) #calculate ptk ptk = hmac4times(pmk, pke) if ord(Data[6]) & 0b00000010 == 2: calculatedMic = hmac.new(ptk[0:16], Data, sha1).digest()[0:16] else: calculatedMic = hmac.new(ptk[0:16], Data).digest() if Mic == calculatedMic: return 1 #Correct password return 0 #Wrong password
def pre_compute_pmks(ssid): outfile_name = ssid + ".pmks" print "[+] Saving computed PMKS to:", outfile_name with open(outfile_name, "w") as pmks_out: while True: # Will break on exception which means all words were read try: word = word_queue.get(block = True, timeout = 1) pmk = pbkdf2_bin(word, ssid, 4096, 32) pmks_out.write(word + ":" + pmk + "\n") except Exception as e: print e break
def __init__(self, passphrase, salt=None, iterations=None): passphrase = passphrase.encode("utf-8") self.salt = unhexlify(salt) if salt else urandom(16) if iterations: self.iterations = iterations else: # per OWASP, use a random number of iterations between 90k and 110k self.iterations = self.ITERATIONS + randint(0, 20000) key = pbkdf2_bin(passphrase, salt=self.salt, iterations=self.iterations, keylen=64) self.aes_key = key[:32] self.hmac_key = key[32:]
def crackProcess(ssid, clientMac, APMac, Anonce, Snonce, mic, data, passQueue, foundPassQ): pke = "Pairwise key expansion" + '\x00' + min(APMac,clientMac)+max(APMac,clientMac)+min(Anonce,Snonce)+max(Anonce,Snonce) count = 0 timeA = datetime.now() while True: passPhrase = passQueue.get() pmk = pbkdf2_bin(passPhrase, ssid, 4096, 32) ptk = hmac4times(pmk,pke) if ord(data[6]) & 0b00000010 == 2: calculatedMic = hmac.new(ptk[0:16],data,sha1).digest()[0:16] else: calculatedMic = hmac.new(ptk[0:16],data).digest() if mic == calculatedMic: foundPassQ.put(passPhrase)
def compare_mic(ssid, clientMac, APMac, Anonce, Snonce, mic, data, pke_data, word): pmk = pbkdf2_bin(word, ssid, 4096, 32) ptk = PRF512(pmk, "Pairwise key expansion", pke_data) kck = ptk[:16] if ord(data[6]) & 0b00000010 == 2: calculatedMic = hmac.new(kck,data,hashlib.sha1).digest()[0:16] else: calculatedMic = hmac.new(kck,data).digest() if mic == calculatedMic: return True return False
def __init__(self, passphrase, salt=None, iterations=None): passphrase = passphrase.encode('utf-8') self.salt = salt.decode('hex') if salt else urandom(16) if iterations: self.iterations = iterations else: # per OWASP, use a random number of iterations between 90k and 110k self.iterations = self.ITERATIONS + randint(0,20000) key = pbkdf2_bin(passphrase, salt=self.salt, iterations=self.iterations, keylen=32) self.box = SecretBox(key)
def crackProcess(ssid, clientMac, APMac, Anonce, Snonce, mic, data, passQueue, foundPassQ): pke = "Pairwise key expansion" + '\x00' + min(APMac, clientMac) + max( APMac, clientMac) + min(Anonce, Snonce) + max(Anonce, Snonce) count = 0 timeA = datetime.now() while True: passPhrase = passQueue.get() pmk = pbkdf2_bin(passPhrase, ssid, 4096, 32) ptk = hmac4times(pmk, pke) if ord(data[6]) & 0b00000010 == 2: calculatedMic = hmac.new(ptk[0:16], data, sha1).digest()[0:16] else: calculatedMic = hmac.new(ptk[0:16], data).digest() if mic == calculatedMic: foundPassQ.put(passPhrase)
def __init__(self, passphrase, salt=None, iterations=None): passphrase = passphrase.encode('utf-8') self.salt = unhexlify(salt) if salt else urandom(16) if iterations: self.iterations = iterations else: # per OWASP, use a random number of iterations between 90k and 110k self.iterations = self.ITERATIONS + randint(0, 20000) key = pbkdf2_bin(passphrase, salt=self.salt, iterations=self.iterations, keylen=64) self.aes_key = key[:32] self.hmac_key = key[32:]
def crackProcess(ssid, clientMac, APMac, Anonce, Snonce, mic, data, passQueue, foundPassQ): # PRF-512(PMK, "Pairwise key expansion", MAC1||MAC2||Nonce1||Nonce2) # MAC: AP/Client MAC # Nonce: Anonce/Snonce # MAC1 < MAC2; Nonce1 < Nonce2 pke = "Pairwise key expansion" + '\x00' + min(APMac,clientMac)+max(APMac,clientMac)+min(Anonce,Snonce)+max(Anonce,Snonce) count = 0 timeA = datetime.now() while True: passPhrase = passQueue.get() # pbkdf2_bin(data, salt, iterations=1000, keylen=24, hashfunc=SHA-1): pmk = pbkdf2_bin(passPhrase, ssid, 4096, 32) # generate Pairwise Temporal Key ptk = hmac4times(pmk,pke) if ord(data[6]) & 0b00000010 == 2: calculatedMic = hmac.new(ptk[0:16],data,sha1).digest()[0:16] else: calculatedMic = hmac.new(ptk[0:16],data).digest() # match Message Integrity Code and find passphrase if mic == calculatedMic: foundPassQ.put(passPhrase)
def set_password(self, password): """ Sets the encrypted password from the given plain-text password :param password: The plain-text password (must be of type str, not unicode!) :type password str """ from simple_backend.auth.constants import PEPPERS iterations = current_app.config.get('PBKDF2_ITERATIONS', 2000) salt = os.urandom(16) # TODO: Support other algorithms than pbkdf2 and other than pbkdf2_sha512 digest = pbkdf2_ctypes.pbkdf2_bin( data=random.choice(PEPPERS) + password + current_app.config['PROJECT_SALT'], salt=salt, iterations=iterations, hashfunc=hashlib.sha512 ) self.password = "******".format( 'pbkdf2_sha512', iterations, salt.encode('hex'), digest.encode('hex') )
def derive_pbkdf2(password, salt, iterations): key_and_iv = pbkdf2_bin(b(password), salt, iterations=iterations, keylen=32) return key_and_iv[0:16], key_and_iv[16:]