當前位置: 首頁>>代碼示例>>Python>>正文


Python DES.MODE_ECB屬性代碼示例

本文整理匯總了Python中Crypto.Cipher.DES.MODE_ECB屬性的典型用法代碼示例。如果您正苦於以下問題:Python DES.MODE_ECB屬性的具體用法?Python DES.MODE_ECB怎麽用?Python DES.MODE_ECB使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在Crypto.Cipher.DES的用法示例。


在下文中一共展示了DES.MODE_ECB屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: decrypt_secret

# 需要導入模塊: from Crypto.Cipher import DES [as 別名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [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: runTest

# 需要導入模塊: from Crypto.Cipher import DES [as 別名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 別名]
def runTest(self):
        from Crypto.Cipher import DES
        from binascii import b2a_hex

        X = []
        X[0:] = [b('\x94\x74\xB8\xE8\xC7\x3B\xCA\x7D')]
        
        for i in range(16):
            c = DES.new(X[i],DES.MODE_ECB)
            if not (i&1): # (num&1) returns 1 for odd numbers 
                X[i+1:] = [c.encrypt(X[i])] # even
            else:
                X[i+1:] = [c.decrypt(X[i])] # odd

        self.assertEqual(b2a_hex(X[16]),
            b2a_hex(b('\x1B\x1A\x2D\xDB\x4C\x64\x24\x38'))) 
開發者ID:mortcanty,項目名稱:earthengine,代碼行數:18,代碼來源:test_DES.py

示例3: __decryptSecret

# 需要導入模塊: from Crypto.Cipher import DES [as 別名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [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

示例4: decryptSecret

# 需要導入模塊: from Crypto.Cipher import DES [as 別名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [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

示例5: SamDecryptNTLMHash

# 需要導入模塊: from Crypto.Cipher import DES [as 別名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [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

示例6: SamEncryptNTLMHash

# 需要導入模塊: from Crypto.Cipher import DES [as 別名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [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

示例7: decrypt_secret

# 需要導入模塊: from Crypto.Cipher import DES [as 別名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [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 = hashdump.str_to_key(block_key)

        des = DES.new(des_key, DES.MODE_ECB)
        enc_block = enc_block + "\x00" * int(abs(8 - len(enc_block)) % 8)
        decrypted_data += des.decrypt(enc_block)

        j += 7
        if len(key[j:j + 7]) < 7:
            j = len(key[j:j + 7])

    (dec_data_len,) = struct.unpack("<L", decrypted_data[:4])
    return decrypted_data[8:8 + dec_data_len] 
開發者ID:virtualrealitysystems,項目名稱:aumfor,代碼行數:24,代碼來源:lsasecrets.py

示例8: __decryptHash

# 需要導入模塊: from Crypto.Cipher import DES [as 別名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [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 
開發者ID:eth0izzle,項目名稱:cracke-dit,代碼行數:20,代碼來源:secretsdump.py

示例9: ChallengeResponse

# 需要導入模塊: from Crypto.Cipher import DES [as 別名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 別名]
def ChallengeResponse(self, Challenge, PasswordHash):
    # Generate the NTResponse the client sends the AP
    # This is the response part asleap/JtR/hashcat crack

    ZPasswordHash = PasswordHash+b'\x00\x00\x00\x00\x00'

    des = DES.new(self.__expand_DES_key(ZPasswordHash[0:7]),DES.MODE_ECB)
    one = des.encrypt(Challenge)
    des = DES.new(self.__expand_DES_key(ZPasswordHash[7:14]),DES.MODE_ECB)
    two = des.encrypt(Challenge)
    des = DES.new(self.__expand_DES_key(ZPasswordHash[14:21]),DES.MODE_ECB)
    tre = des.encrypt(Challenge)

    Response = one+two+tre

    return Response 
開發者ID:sensepost,項目名稱:understanding-eap,代碼行數:18,代碼來源:eap.py

示例10: calcKCV

# 需要導入模塊: from Crypto.Cipher import DES [as 別名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 別名]
def calcKCV(keyValue, zAES=False):
    """Calculate KCV for symmetric key.
keyValue - key values as string (DES, 3DES2k, 3DES3k, AES)
zAES     - True if key is AES (i.e. encrypt block of '01' instead of '00')

Return 3B-long string."""
    if zAES:
        assert len(keyValue) in (16, 24, 32), "Wrong length of AES key"
        block = '\x01'*16
        tkey = AES.new(keyValue, AES.MODE_ECB)
    else:
        assert len(keyValue) in (8, 16, 24), "Wrong length of (3)DES key"
        block = '\x00'*8
        if len(keyValue) == 8:
            tkey = DES.new(keyValue, DES.MODE_ECB)
        else:
            tkey = DES3.new(keyValue, DES.MODE_ECB)
    return tkey.encrypt(block)[:3] 
開發者ID:suma12,項目名稱:asterix,代碼行數:20,代碼來源:APDU.py

示例11: decrypt_single_hash

# 需要導入模塊: from Crypto.Cipher import DES [as 別名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [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] + 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 
開發者ID:HarmJ0y,項目名稱:ImpDump,代碼行數:15,代碼來源:hashdump.py

示例12: ds_decrypt_single_hash

# 需要導入模塊: from Crypto.Cipher import DES [as 別名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 別名]
def ds_decrypt_single_hash(rid, enc_hash):
    (des_k1,des_k2) = sid_to_key(rid)
    d1 = DES.new(des_k1, DES.MODE_ECB)
    d2 = DES.new(des_k2, DES.MODE_ECB)
    hash = d1.decrypt(enc_hash[:8]) + d2.decrypt(enc_hash[8:])
    return hash 
開發者ID:HarmJ0y,項目名稱:ImpDump,代碼行數:8,代碼來源:dshashdump.py

示例13: handshake

# 需要導入模塊: from Crypto.Cipher import DES [as 別名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 別名]
def handshake(key, chall):
    #https://tools.ietf.org/html/rfc6143#section-7.2.2
    #http://www.vidarholen.net/contents/junk/vnc.html
    #Truncate to 8 chars
    key = key[:8]
    # Convert to binary
    binary = (' '.join(format(ord(x), 'b') for x in key))
    binaryList = binary.split()
    count = 0
    #Add leading zeros
    for x in binaryList:
        binaryList[count] = ("0" * (8 - len(binaryList[count]))) + binaryList[count]
        count += 1

    # Function to mirror the byte
    def bitMirror(byte):
        return byte[::-1]
    flipkey = ""
    # turn back into binary
    for x in binaryList:
        flipkey += struct.pack('B', int(bitMirror(x), 2))
    #Pad with NULL bytes
    flipkey += "\x00" * (8 - len(flipkey))
    #Encryptwith DES
    des = DES.new(flipkey, DES.MODE_ECB)

    #challenge from server
    challenge = chall
#    challenge= chall.decode("hex")
    response = des.encrypt(challenge)
#    return ''.join(x.encode('hex') for x in response)
    return response 
開發者ID:dobin,項目名稱:ffw,代碼行數:34,代碼來源:proto_vnc.py

示例14: decrypt_des_ecb

# 需要導入模塊: from Crypto.Cipher import DES [as 別名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 別名]
def decrypt_des_ecb(key, data, iv=None):
    mode = DES.MODE_ECB
    if iv:
        cipher = DES.new(key, mode, iv)
    else:
        cipher = DES.new(key, mode)
    return cipher.decrypt(data) 
開發者ID:kevthehermit,項目名稱:RATDecoders,代碼行數:9,代碼來源:crypto.py

示例15: hash_lm

# 需要導入模塊: from Crypto.Cipher import DES [as 別名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [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) 
開發者ID:google,項目名稱:rekall,代碼行數:8,代碼來源:hashdump.py


注:本文中的Crypto.Cipher.DES.MODE_ECB屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。