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


Python ARC4.new方法代码示例

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


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

示例1: decrypt_secret

# 需要导入模块: from Crypto.Cipher import ARC4 [as 别名]
# 或者: from Crypto.Cipher.ARC4 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 ARC4 [as 别名]
# 或者: from Crypto.Cipher.ARC4 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 ARC4 [as 别名]
# 或者: from Crypto.Cipher.ARC4 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 ARC4 [as 别名]
# 或者: from Crypto.Cipher.ARC4 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 ARC4 [as 别名]
# 或者: from Crypto.Cipher.ARC4 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 ARC4 [as 别名]
# 或者: from Crypto.Cipher.ARC4 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 ARC4 [as 别名]
# 或者: from Crypto.Cipher.ARC4 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: test_MimiCommand

# 需要导入模块: from Crypto.Cipher import ARC4 [as 别名]
# 或者: from Crypto.Cipher.ARC4 import new [as 别名]
def test_MimiCommand(self):
        dce, rpctransport, pHandle, key = self.connect()
        from Crypto.Cipher import ARC4
        cipher = ARC4.new(key[::-1])
        command = cipher.encrypt('token::whoami\x00'.encode('utf-16le'))
        #command = cipher.encrypt('sekurlsa::logonPasswords\x00'.encode('utf-16le'))
        #command = cipher.encrypt('process::imports\x00'.encode('utf-16le'))
        request = mimilib.MimiCommand()
        request['phMimi'] = pHandle
        request['szEncCommand'] = len(command)
        request['encCommand'] = list(command)
        resp = dce.request(request)
        cipherText = ''.join(resp['encResult'])
        cipher = ARC4.new(key[::-1])
        plain = cipher.decrypt(cipherText)
        print '='*80
        print plain
        #resp.dump() 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:20,代码来源:test_mimilib.py

示例9: decrypt

# 需要导入模块: from Crypto.Cipher import ARC4 [as 别名]
# 或者: from Crypto.Cipher.ARC4 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

示例10: GSS_GetMIC

# 需要导入模块: from Crypto.Cipher import ARC4 [as 别名]
# 或者: from Crypto.Cipher.ARC4 import new [as 别名]
def GSS_GetMIC(self, sessionKey, data, sequenceNumber, direction = 'init'):
        GSS_GETMIC_HEADER = '\x60\x23\x06\x09\x2a\x86\x48\x86\xf7\x12\x01\x02\x02'
        token = self.MIC()

        # Let's pad the data
        pad = (4 - (len(data) % 4)) & 0x3
        padStr = chr(pad) * pad
        data += padStr
 
        token['SGN_ALG'] = GSS_HMAC
        if direction == 'init':
            token['SND_SEQ'] = struct.pack('>L', sequenceNumber) + '\x00'*4
        else:
            token['SND_SEQ'] = struct.pack('>L', sequenceNumber) + '\xff'*4

        Ksign = HMAC.new(sessionKey.contents, 'signaturekey\0', MD5).digest()
        Sgn_Cksum = MD5.new( struct.pack('<L',15) + str(token)[:8] + data).digest()
        Sgn_Cksum = HMAC.new(Ksign, Sgn_Cksum, MD5).digest()
        token['SGN_CKSUM'] = Sgn_Cksum[:8]

        Kseq = HMAC.new(sessionKey.contents, struct.pack('<L',0), MD5).digest()
        Kseq = HMAC.new(Kseq, token['SGN_CKSUM'], MD5).digest()
        token['SND_SEQ'] = ARC4.new(Kseq).encrypt(token['SND_SEQ'])
        finalData = GSS_GETMIC_HEADER + token.getData()
        return finalData 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:27,代码来源:gssapi.py

示例11: DecryptAttributeValue

# 需要导入模块: from Crypto.Cipher import ARC4 [as 别名]
# 或者: from Crypto.Cipher.ARC4 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

示例12: ComputeSessionKeyStrongKey

# 需要导入模块: from Crypto.Cipher import ARC4 [as 别名]
# 或者: from Crypto.Cipher.ARC4 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

示例13: decrypt_aes

# 需要导入模块: from Crypto.Cipher import ARC4 [as 别名]
# 或者: from Crypto.Cipher.ARC4 import new [as 别名]
def decrypt_aes(secret, key):
    """
    Based on code from http://lab.mediaservice.net/code/cachedump.rb
    """
    sha = SHA256.new()
    sha.update(key)
    for _i in range(1, 1000 + 1):
        sha.update(secret[28:60])
    aeskey = sha.digest()

    data = ""
    for i in range(60, len(secret), 16):
        aes = AES.new(aeskey, AES.MODE_CBC, '\x00' * 16)
        buf = secret[i : i + 16]
        if len(buf) < 16:
            buf += (16 - len(buf)) * "\00"
        data += aes.decrypt(buf)

    return data 
开发者ID:virtualrealitysystems,项目名称:aumfor,代码行数:21,代码来源:lsasecrets.py

示例14: decrypt_secret

# 需要导入模块: from Crypto.Cipher import ARC4 [as 别名]
# 或者: from Crypto.Cipher.ARC4 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 = 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

示例15: decrypt_hash

# 需要导入模块: from Crypto.Cipher import ARC4 [as 别名]
# 或者: from Crypto.Cipher.ARC4 import new [as 别名]
def decrypt_hash(edata, nlkm, ch, xp = True):
    if xp:
        hmac_md5 = HMAC.new(nlkm, ch)
        rc4key = hmac_md5.digest()

        rc4 = ARC4.new(rc4key)
        data = rc4.encrypt(edata)
    else:
        # based on  Based on code from http://lab.mediaservice.net/code/cachedump.rb
        aes = AES.new(nlkm[16:32], AES.MODE_CBC, ch)
        data = ""
        for i in range(0, len(edata), 16):
            buf = edata[i : i + 16]
            if len(buf) < 16:
                buf += (16 - len(buf)) * "\00"
            data += aes.decrypt(buf)
    return data 
开发者ID:virtualrealitysystems,项目名称:aumfor,代码行数:19,代码来源:domcachedump.py


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