当前位置: 首页>>代码示例>>Python>>正文


Python DES.new方法代码示例

本文整理汇总了Python中Crypto.Cipher.DES.new方法的典型用法代码示例。如果您正苦于以下问题:Python DES.new方法的具体用法?Python DES.new怎么用?Python DES.new使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Crypto.Cipher.DES的用法示例。


在下文中一共展示了DES.new方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: decrypt_secret

# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import new [as 别名]
def decrypt_secret(secret, key):
    """Python implementation of SystemFunction005.

    Decrypts a block of data with DES using given key.
    Note that key can be longer than 7 bytes."""
    decrypted_data = ''
    j = 0   # key index
    for i in range(0,len(secret),8):
        enc_block = secret[i:i+8]
        block_key = key[j:j+7]
        des_key = str_to_key(block_key)

        des = DES.new(des_key, DES.MODE_ECB)
        decrypted_data += des.decrypt(enc_block)
        
        j += 7
        if len(key[j:j+7]) < 7:
            j = len(key[j:j+7])

    (dec_data_len,) = unpack("<L", decrypted_data[:4])
    return decrypted_data[8:8+dec_data_len] 
开发者ID:HarmJ0y,项目名称:ImpDump,代码行数:23,代码来源:lsasecrets.py

示例2: get_hbootkey

# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import new [as 别名]
def get_hbootkey(samaddr, bootkey):
    sam_account_path = ["SAM", "Domains", "Account"]

    root = get_root(samaddr)
    if not root: return None

    sam_account_key = open_key(root, sam_account_path)
    if not sam_account_key: return None

    F = None
    for v in values(sam_account_key):
        if v.Name == 'F':
            F = samaddr.read(v.Data.value, v.DataLength.value)
    if not F: return None

    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 
开发者ID:HarmJ0y,项目名称:ImpDump,代码行数:25,代码来源:hashdump.py

示例3: get_hbootkey

# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES 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 
开发者ID:google,项目名称:rekall,代码行数:20,代码来源:hashdump.py

示例4: getHBootKey

# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES 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! :(') 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:21,代码来源:secretsdump.py

示例5: __decryptSecret

# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES 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'] 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:24,代码来源:secretsdump.py

示例6: __decryptLSA

# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES 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] 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:20,代码来源:secretsdump.py

示例7: computeResponseNTLMv1

# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES 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 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:26,代码来源:ntlm.py

示例8: decryptSecret

# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import new [as 别名]
def decryptSecret(key, value):
    # [MS-LSAD] Section 5.1.2
    plainText = ''
    key0 = key
    for i in range(0, len(value), 8):
        cipherText = value[:8]
        tmpStrKey = key0[:7]
        tmpKey = transformKey(tmpStrKey)
        Crypt1 = DES.new(tmpKey, DES.MODE_ECB)
        plainText += Crypt1.decrypt(cipherText) 
        cipherText = cipherText[8:]
        key0 = key0[7:]
        value = value[8:]
        # AdvanceKey
        if len(key0) < 7:
            key0 = key[len(key0):]

    secret = LSA_SECRET_XP(plainText)
    return (secret['Secret']) 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:21,代码来源:crypto.py

示例9: SamDecryptNTLMHash

# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import new [as 别名]
def SamDecryptNTLMHash(encryptedHash, key):
    # [MS-SAMR] Section 2.2.11.1.1
    Block1 = encryptedHash[:8]
    Block2 = encryptedHash[8:]

    Key1 = key[:7]
    Key1 = transformKey(Key1)
    Key2 = key[7:14]
    Key2 = transformKey(Key2)

    Crypt1 = DES.new(Key1, DES.MODE_ECB)
    Crypt2 = DES.new(Key2, DES.MODE_ECB)

    plain1 = Crypt1.decrypt(Block1)
    plain2 = Crypt2.decrypt(Block2)

    return plain1 + plain2 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:19,代码来源:crypto.py

示例10: SamEncryptNTLMHash

# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import new [as 别名]
def SamEncryptNTLMHash(encryptedHash, key):
    # [MS-SAMR] Section 2.2.11.1.1
    Block1 = encryptedHash[:8]
    Block2 = encryptedHash[8:]

    Key1 = key[:7]
    Key1 = transformKey(Key1)
    Key2 = key[7:14]
    Key2 = transformKey(Key2)

    Crypt1 = DES.new(Key1, DES.MODE_ECB)
    Crypt2 = DES.new(Key2, DES.MODE_ECB)

    plain1 = Crypt1.encrypt(Block1)
    plain2 = Crypt2.encrypt(Block2)

    return plain1 + plain2 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:19,代码来源:crypto.py

示例11: decrypt

# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES 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:] 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:20,代码来源:crypto.py

示例12: DecryptAttributeValue

# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import new [as 别名]
def DecryptAttributeValue(dce, attribute):
    sessionKey = dce.get_session_key()
    # Is it a Kerberos Session Key?
    if isinstance(sessionKey, crypto.Key):
        # Extract its contents and move on
        sessionKey = sessionKey.contents

    encryptedPayload = ENCRYPTED_PAYLOAD(attribute)

    md5 = hashlib.new('md5')
    md5.update(sessionKey)
    md5.update(encryptedPayload['Salt'])
    finalMD5 = md5.digest()

    cipher = ARC4.new(finalMD5)
    plainText = cipher.decrypt(attribute[16:])

    #chkSum = (binascii.crc32(plainText[4:])) & 0xffffffff
    #if unpack('<L',plainText[:4])[0] != chkSum:
    #    print "RECEIVED 0x%x" % unpack('<L',plainText[:4])[0]
    #    print "CALCULATED 0x%x" % chkSum

    return plainText[4:]

# 5.16.4 ATTRTYP-to-OID Conversion 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:27,代码来源:drsuapi.py

示例13: ComputeSessionKeyStrongKey

# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import new [as 别名]
def ComputeSessionKeyStrongKey(sharedSecret, clientChallenge, serverChallenge, sharedSecretHash = None):
    # added the ability to receive hashes already

    if sharedSecretHash is None:
        M4SS = ntlm.NTOWFv1(sharedSecret)
    else:
        M4SS = sharedSecretHash

    md5 = hashlib.new('md5')
    md5.update('\x00'*4)
    md5.update(clientChallenge)
    md5.update(serverChallenge)
    finalMD5 = md5.digest()
    hm = hmac.new(M4SS) 
    hm.update(finalMD5)
    return hm.digest() 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:18,代码来源:nrpc.py

示例14: aes_encrypt

# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import new [as 别名]
def aes_encrypt(key, iv, content):
    """
    AES加密
    key,iv使用同一个
    模式cbc
    填充pkcs7
    :param key: 密钥
    :param content: 加密内容
    :return:
    """
    cipher = AES.new(key, AES.MODE_CBC, iv)
    # 处理明文
    content_padding = pkcs7padding(content)
    # 加密
    encrypt_bytes = cipher.encrypt(bytes(content_padding, encoding='utf-8'))
    # 重新编码
    result = str(base64.b64encode(encrypt_bytes), encoding='utf-8')
    return result 
开发者ID:PKUJohnson,项目名称:OpenData,代码行数:20,代码来源:util.py

示例15: aes_decrypt

# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import new [as 别名]
def aes_decrypt(key, iv, content):
    """
    AES解密
     key,iv使用同一个
    模式cbc
    去填充pkcs7
    :param key:
    :param content:
    :return:
    """
    cipher = AES.new(key, AES.MODE_CBC, iv)
    # base64解码
    encrypt_bytes = base64.b64decode(content)
    # 解密
    decrypt_bytes = cipher.decrypt(encrypt_bytes)
    # 重新编码
    result = str(decrypt_bytes, encoding='utf8')
    # 去除填充内容
    result = pkcs7unpadding(result)
    return result 
开发者ID:PKUJohnson,项目名称:OpenData,代码行数:22,代码来源:util.py


注:本文中的Crypto.Cipher.DES.new方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。