本文整理汇总了Python中Crypto.Hash.MD4.new方法的典型用法代码示例。如果您正苦于以下问题:Python MD4.new方法的具体用法?Python MD4.new怎么用?Python MD4.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Crypto.Hash.MD4
的用法示例。
在下文中一共展示了MD4.new方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_hbootkey
# 需要导入模块: from Crypto.Hash import MD4 [as 别名]
# 或者: from Crypto.Hash.MD4 import new [as 别名]
def get_hbootkey(sam_registry, bootkey):
sam_account_path = ["SAM", "Domains", "Account"]
sam_account_key = sam_registry.open_key(sam_account_path)
# Get the F value
F = sam_account_key.open_value("F").DecodedData
if not F:
return F
md5 = MD5.new()
md5.update(F[0x70:0x80] + aqwerty + bootkey + anum)
rc4_key = md5.digest()
rc4 = ARC4.new(rc4_key)
hbootkey = rc4.encrypt(F[0x80:0xA0])
return hbootkey
示例2: getHBootKey
# 需要导入模块: from Crypto.Hash import MD4 [as 别名]
# 或者: from Crypto.Hash.MD4 import new [as 别名]
def getHBootKey(self):
LOG.debug('Calculating HashedBootKey from SAM')
QWERTY = "!@#$%^&*()qwertyUIOPAzxcvbnmQQQQQQQQQQQQ)(*@&%\0"
DIGITS = "0123456789012345678901234567890123456789\0"
F = self.getValue(ntpath.join('SAM\Domains\Account','F'))[1]
domainData = DOMAIN_ACCOUNT_F(F)
rc4Key = self.MD5(domainData['Key0']['Salt'] + QWERTY + self.__bootKey + DIGITS)
rc4 = ARC4.new(rc4Key)
self.__hashedBootKey = rc4.encrypt(domainData['Key0']['Key']+domainData['Key0']['CheckSum'])
# Verify key with checksum
checkSum = self.MD5( self.__hashedBootKey[:16] + DIGITS + self.__hashedBootKey[:16] + QWERTY)
if checkSum != self.__hashedBootKey[16:]:
raise Exception('hashedBootKey CheckSum failed, Syskey startup password probably in use! :(')
示例3: __decryptSecret
# 需要导入模块: from Crypto.Hash import MD4 [as 别名]
# 或者: from Crypto.Hash.MD4 import new [as 别名]
def __decryptSecret(self, key, value):
# [MS-LSAD] Section 5.1.2
plainText = ''
encryptedSecretSize = unpack('<I', value[:4])[0]
value = value[len(value)-encryptedSecretSize:]
key0 = key
for i in range(0, len(value), 8):
cipherText = value[:8]
tmpStrKey = key0[:7]
tmpKey = self.__cryptoCommon.transformKey(tmpStrKey)
Crypt1 = DES.new(tmpKey, DES.MODE_ECB)
plainText += Crypt1.decrypt(cipherText)
key0 = key0[7:]
value = value[8:]
# AdvanceKey
if len(key0) < 7:
key0 = key[len(key0):]
secret = LSA_SECRET_XP(plainText)
return secret['Secret']
示例4: __decryptLSA
# 需要导入模块: from Crypto.Hash import MD4 [as 别名]
# 或者: from Crypto.Hash.MD4 import new [as 别名]
def __decryptLSA(self, value):
if self.__vistaStyle is True:
# ToDo: There could be more than one LSA Keys
record = LSA_SECRET(value)
tmpKey = self.__sha256(self.__bootKey, record['EncryptedData'][:32])
plainText = self.__cryptoCommon.decryptAES(tmpKey, record['EncryptedData'][32:])
record = LSA_SECRET_BLOB(plainText)
self.__LSAKey = record['Secret'][52:][:32]
else:
md5 = hashlib.new('md5')
md5.update(self.__bootKey)
for i in range(1000):
md5.update(value[60:76])
tmpKey = md5.digest()
rc4 = ARC4.new(tmpKey)
plainText = rc4.decrypt(value[12:60])
self.__LSAKey = plainText[0x10:0x20]
示例5: computeResponseNTLMv1
# 需要导入模块: from Crypto.Hash import MD4 [as 别名]
# 或者: from Crypto.Hash.MD4 import new [as 别名]
def computeResponseNTLMv1(flags, serverChallenge, clientChallenge, serverName, domain, user, password, lmhash='',
nthash='', use_ntlmv2=USE_NTLMv2):
if user == '' and password == '':
# Special case for anonymous authentication
lmResponse = ''
ntResponse = ''
else:
lmhash = LMOWFv1(password, lmhash, nthash)
nthash = NTOWFv1(password, lmhash, nthash)
if flags & NTLMSSP_NEGOTIATE_LM_KEY:
ntResponse = ''
lmResponse = get_ntlmv1_response(lmhash, serverChallenge)
elif flags & NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY:
md5 = hashlib.new('md5')
chall = (serverChallenge + clientChallenge)
md5.update(chall)
ntResponse = ntlmssp_DES_encrypt(nthash, md5.digest()[:8])
lmResponse = clientChallenge + '\x00'*16
else:
ntResponse = get_ntlmv1_response(nthash,serverChallenge)
lmResponse = get_ntlmv1_response(lmhash, serverChallenge)
sessionBaseKey = generateSessionKeyV1(password, lmhash, nthash)
return ntResponse, lmResponse, sessionBaseKey
示例6: decrypt
# 需要导入模块: from Crypto.Hash import MD4 [as 别名]
# 或者: from Crypto.Hash.MD4 import new [as 别名]
def decrypt(cls, key, keyusage, ciphertext):
if len(ciphertext) < 24:
raise ValueError('ciphertext too short')
cksum, basic_ctext = ciphertext[:16], ciphertext[16:]
ki = HMAC.new(key.contents, cls.usage_str(keyusage), MD5).digest()
ke = HMAC.new(ki, cksum, MD5).digest()
basic_plaintext = ARC4.new(ke).decrypt(basic_ctext)
exp_cksum = HMAC.new(ki, basic_plaintext, MD5).digest()
ok = _mac_equal(cksum, exp_cksum)
if not ok and keyusage == 9:
# Try again with usage 8, due to RFC 4757 errata.
ki = HMAC.new(key.contents, pack('<I', 8), MD5).digest()
exp_cksum = HMAC.new(ki, basic_plaintext, MD5).digest()
ok = _mac_equal(cksum, exp_cksum)
if not ok:
raise InvalidChecksum('ciphertext integrity failure')
# Discard the confounder.
return basic_plaintext[8:]
示例7: __decryptHash
# 需要导入模块: from Crypto.Hash import MD4 [as 别名]
# 或者: from Crypto.Hash.MD4 import new [as 别名]
def __decryptHash(self, rid, cryptedHash, constant, newStyle = False):
# Section 2.2.11.1.1 Encrypting an NT or LM Hash Value with a Specified Key
# plus hashedBootKey stuff
Key1,Key2 = self.__cryptoCommon.deriveKey(rid)
Crypt1 = DES.new(Key1, DES.MODE_ECB)
Crypt2 = DES.new(Key2, DES.MODE_ECB)
if newStyle is False:
rc4Key = self.MD5( self.__hashedBootKey[:0x10] + pack("<L",rid) + constant )
rc4 = ARC4.new(rc4Key)
key = rc4.encrypt(cryptedHash['Hash'])
else:
key = self.__cryptoCommon.decryptAES(self.__hashedBootKey[:0x10], cryptedHash['Hash'], cryptedHash['Salt'])[:16]
decryptedHash = Crypt1.decrypt(key[:8]) + Crypt2.decrypt(key[8:])
return decryptedHash
示例8: sha1
# 需要导入模块: from Crypto.Hash import MD4 [as 别名]
# 或者: from Crypto.Hash.MD4 import new [as 别名]
def sha1(self):
"""Get SHA1 hash
The SHA (Secure Hash Algorithm) hash functions were designed by the NSA.
SHA-1 is the most established of the existing SHA hash functions and it is
used in a variety of security applications and protocols. However, SHA-1's
collision resistance has been weakening as new attacks are discovered or improved.
Returns:
Chepy: The Chepy object.
Examples:
>>> Chepy("A").sha1().output
"6dcd4ce23d88e2ee9568ba546c007c63d9131c1b"
"""
self.state = hashlib.sha1(self._convert_to_bytes()).hexdigest()
return self
示例9: sha2_512_truncate
# 需要导入模块: from Crypto.Hash import MD4 [as 别名]
# 或者: from Crypto.Hash.MD4 import new [as 别名]
def sha2_512_truncate(self, truncate: int = 256):
"""Get SHA2-512/bits hash
The SHA-2 (Secure Hash Algorithm 2) hash functions were designed by the NSA. SHA-2
includes significant changes from its predecessor, SHA-1. The SHA-2 family consists of
hash functions with digests (hash values) that are 224, 256, 384 or 512 bits: SHA224,
SHA256, SHA384, SHA512. SHA-512 operates on 64-bit words. SHA-256 operates on 32-bit
words. SHA-384 is largely identical to SHA-512 but is truncated to 384 bytes. SHA-224
is largely identical to SHA-256 but is truncated to 224 bytes. SHA-512/224 and SHA-512/256
are truncated versions of SHA-512, but the initial values are generated using the method
described in Federal Information Processing Standards (FIPS) PUB 180-4.
Args:
truncate (int, optional): The bits to truncate by. Defaults to 256
Returns:
Chepy: The Chepy object.
"""
assert truncate in [256, 224], "Valid truncates are 256, 224"
h = SHA512.new(self._convert_to_bytes(), truncate=str(truncate))
self.state = h.hexdigest()
return self
示例10: hash_lm
# 需要导入模块: from Crypto.Hash import MD4 [as 别名]
# 或者: from Crypto.Hash.MD4 import new [as 别名]
def hash_lm(pw):
pw = pw[:14].upper()
pw = pw + ('\0' * (14 - len(pw)))
d1 = DES.new(str_to_key(pw[:7]), DES.MODE_ECB)
d2 = DES.new(str_to_key(pw[7:]), DES.MODE_ECB)
return d1.encrypt(lmkey) + d2.encrypt(lmkey)
示例11: hash_nt
# 需要导入模块: from Crypto.Hash import MD4 [as 别名]
# 或者: from Crypto.Hash.MD4 import new [as 别名]
def hash_nt(pw):
return MD4.new(pw.encode('utf-16-le')).digest()
示例12: decrypt_single_hash
# 需要导入模块: from Crypto.Hash import MD4 [as 别名]
# 或者: from Crypto.Hash.MD4 import new [as 别名]
def decrypt_single_hash(rid, hbootkey, enc_hash, lmntstr):
(des_k1, des_k2) = sid_to_key(rid)
d1 = DES.new(des_k1, DES.MODE_ECB)
d2 = DES.new(des_k2, DES.MODE_ECB)
md5 = MD5.new()
md5.update(hbootkey[:0x10] + struct.pack("<L", rid) + lmntstr)
rc4_key = md5.digest()
rc4 = ARC4.new(rc4_key)
obfkey = rc4.encrypt(enc_hash)
hash = d1.decrypt(obfkey[:8]) + d2.decrypt(obfkey[8:])
return hash
示例13: encrypt_single_hash
# 需要导入模块: from Crypto.Hash import MD4 [as 别名]
# 或者: from Crypto.Hash.MD4 import new [as 别名]
def encrypt_single_hash(rid, hbootkey, hash, lmntstr):
(des_k1, des_k2) = sid_to_key(rid)
d1 = DES.new(des_k1, DES.MODE_ECB)
d2 = DES.new(des_k2, DES.MODE_ECB)
enc_hash = d1.encrypt(hash[:8]) + d2.encrypt(hash[8:])
md5 = MD5.new()
md5.update(hbootkey[:0x10] + struct.pack("<L", rid) + lmntstr)
rc4_key = md5.digest()
rc4 = ARC4.new(rc4_key)
obfkey = rc4.encrypt(enc_hash)
return obfkey
示例14: __restore
# 需要导入模块: from Crypto.Hash import MD4 [as 别名]
# 或者: from Crypto.Hash.MD4 import new [as 别名]
def __restore(self):
# First of all stop the service if it was originally stopped
if self.__shouldStop is True:
LOG.info('Stopping service %s' % self.__serviceName)
scmr.hRControlService(self.__scmr, self.__serviceHandle, scmr.SERVICE_CONTROL_STOP)
if self.__disabled is True:
LOG.info('Restoring the disabled state for service %s' % self.__serviceName)
scmr.hRChangeServiceConfigW(self.__scmr, self.__serviceHandle, dwStartType = 0x4)
if self.__serviceDeleted is False:
# Check again the service we created does not exist, starting a new connection
# Why?.. Hitting CTRL+C might break the whole existing DCE connection
try:
rpc = transport.DCERPCTransportFactory(r'ncacn_np:%s[\pipe\svcctl]' % self.__smbConnection.getRemoteHost())
if hasattr(rpc, 'set_credentials'):
# This method exists only for selected protocol sequences.
rpc.set_credentials(*self.__smbConnection.getCredentials())
rpc.set_kerberos(self.__doKerberos, self.__kdcHost)
self.__scmr = rpc.get_dce_rpc()
self.__scmr.connect()
self.__scmr.bind(scmr.MSRPC_UUID_SCMR)
# Open SC Manager
ans = scmr.hROpenSCManagerW(self.__scmr)
self.__scManagerHandle = ans['lpScHandle']
# Now let's open the service
resp = scmr.hROpenServiceW(self.__scmr, self.__scManagerHandle, self.__tmpServiceName)
service = resp['lpServiceHandle']
scmr.hRDeleteService(self.__scmr, service)
scmr.hRControlService(self.__scmr, service, scmr.SERVICE_CONTROL_STOP)
scmr.hRCloseServiceHandle(self.__scmr, service)
scmr.hRCloseServiceHandle(self.__scmr, self.__serviceHandle)
scmr.hRCloseServiceHandle(self.__scmr, self.__scManagerHandle)
rpc.disconnect()
except Exception, e:
# If service is stopped it'll trigger an exception
# If service does not exist it'll trigger an exception
# So. we just wanna be sure we delete it, no need to
# show this exception message
pass
示例15: decryptAES
# 需要导入模块: from Crypto.Hash import MD4 [as 别名]
# 或者: from Crypto.Hash.MD4 import new [as 别名]
def decryptAES(key, value, iv='\x00'*16):
plainText = ''
if iv != '\x00'*16:
aes256 = AES.new(key,AES.MODE_CBC, iv)
for index in range(0, len(value), 16):
if iv == '\x00'*16:
aes256 = AES.new(key,AES.MODE_CBC, iv)
cipherBuffer = value[index:index+16]
# Pad buffer to 16 bytes
if len(cipherBuffer) < 16:
cipherBuffer += '\x00' * (16-len(cipherBuffer))
plainText += aes256.decrypt(cipherBuffer)
return plainText