Beispiel #1
0
def DESL(K, D):
    """
	Indicates the encryption of an 8-byte data item D with the 16-byte key K
	using the Data Encryption Standard Long (DESL) algorithm.
	The result is 24 bytes in length.
	:param K:
	:param D:
	:return:
	"""
    if len(K) != 16:
        raise Exception("K MUST be 16 bytes long")
    if len(D) != 8:
        raise Exception("D MUST be 8 bytes long")

    res = b''
    res += DES(K[:7]).encrypt(D)
    res += DES(K[7:14]).encrypt(D)
    res += DES(K[14:] + b'\x00' * 5).encrypt(D)
    return res
Beispiel #2
0
	def calc_key_exchange_key(self, with_lm = False, non_nt_session_key = False):
	
		if self.credentials.password:
			lm_hash = LMOWFv1(self.credentials.password)
		else:
			lm_hash = self.credentials.lm_hash
		
		if with_lm:
			temp1 = DES(lm_hash[:7]).encrypt(self.LMResponse.to_bytes()[:8])
			temp2 = DES(lm_hash[7:8] + b'\xBD\xBD\xBD\xBD\xBD\xBD').encrypt(self.LMResponse.to_bytes()[:8])
			kex = temp1 + temp2

		else:
			if non_nt_session_key:
				kex = lm_hash[:8] + b'\x00' * 8
			else:
				kex = self.SessionBaseKey
				
		return kex
Beispiel #3
0
def LMOWFv1(password):
    LM_SECRET = b'KGS!@#$%'
    t1 = password[:14].ljust(14, '\x00').upper()
    d = DES(t1[:7].encode('ascii'))
    r1 = d.encrypt(LM_SECRET)
    d = DES(t1[7:].encode('ascii'))
    r2 = d.encrypt(LM_SECRET)

    return r1 + r2
Beispiel #4
0
def removeDESLayer(cryptedHash, rid):
	Key1,Key2 = deriveKey(rid)

	Crypt1 = DES(Key1, cipherMODE.ECB)
	Crypt2 = DES(Key2, cipherMODE.ECB)

	decryptedHash = Crypt1.decrypt(cryptedHash[:8]) + Crypt2.decrypt(cryptedHash[8:])

	return decryptedHash