def decrypt_data(data):
    if data is None:
        return None

    key = derive_key(128, data[:0x20])[:0x20]
    iv = derive_key(128, data[0x10:0x30])[:0x10]
    cipher = AES.new(key, AES.MODE_CBC, iv)

    def pad(s):
        return s + (-len(s) % 16) * bytes([-len(s) % 16])

    data = pad(data[0x30:])
    data = cipher.decrypt(data)

    if len(data) >= 8:
        size, _ = struct.unpack_from('=II', data)
        signature = data[size+0x08:size+0x68]
        data = data[:size+0x08]
        try:
            verifier.verify(SHA384.new(data), signature)
        except ValueError:
            log.warning('[!] WARNING: Bad public key signature (incorrect bot key?)')
        data = data[0x08:]

    return data
Beispiel #2
0
def rsa_verify(pubkey, received_message, signature):
    h = SHA384.new(received_message)
    verifier = pss.new(pubkey)
    try:
        verifier.verify(h, base64.b64decode(signature))
        return True
    except ValueError:
        return False
Beispiel #3
0
def do_hmac(key, value):
    value = value.encode('utf-8')
    # Let's only encode if its not a byte
    try:
        key = key.encode('utf-8')
    except AttributeError:
        pass

    h = HMAC.new(key, value, digestmod=SHA384.new())
    return h.hexdigest()
Beispiel #4
0
def pycrypto():
    import Crypto
    from Crypto.Hash import MD2
    from Crypto.Hash import MD4
    from Crypto.Hash import MD5
    from Crypto.Hash import SHA
    from Crypto.Hash import SHA224
    from Crypto.Hash import SHA256
    from Crypto.Hash import SHA384
    from Crypto.Hash import SHA512
    from Crypto.Hash import HMAC

    Crypto.Hash.MD2.new()  # Noncompliant
    MD2.new()  # Noncompliant
    MD4.new()  # Noncompliant
    MD5.new()  # Noncompliant
    SHA.new()  # Noncompliant
    SHA224.new()  # Noncompliant
    SHA256.new()  # Noncompliant
    SHA384.new()  # Noncompliant
    SHA512.new()  # Noncompliant
    HMAC.new(b"\x00")  # Noncompliant
Beispiel #5
0
def cryptodome():
    import Cryptodome
    from Cryptodome.Hash import MD2
    from Cryptodome.Hash import MD4
    from Cryptodome.Hash import MD5
    from Cryptodome.Hash import SHA1
    from Cryptodome.Hash import SHA224
    from Cryptodome.Hash import SHA256
    from Cryptodome.Hash import SHA384
    from Cryptodome.Hash import SHA512
    from Cryptodome.Hash import HMAC

    Cryptodome.Hash.MD2.new()  # Noncompliant
    MD2.new()  # Noncompliant
    MD4.new()  # Noncompliant
    MD5.new()  # Noncompliant
    SHA1.new()  # Noncompliant
    SHA224.new()  # Noncompliant
    SHA256.new()  # OK
    SHA384.new()  # OK
    SHA512.new()  # OK
    HMAC.new(b"\x00")  # OK
Beispiel #6
0
def verify(message, signature, pub_key, hash="SHA256"):
    signer = PKCS1_v1_5.new(pub_key)
    if (hash == "SHA512"):
        digest = SHA512.new()
    elif (hash == "SHA384"):
        digest = SHA384.new()
    elif (hash == "SHA256"):
        digest = SHA256.new()
    elif (hash == "SHA1"):
        digest = SHA.new()
    else:
        digest = MD5.new()
    digest.update(message)
    return signer.verify(digest, signature)
Beispiel #7
0
def sign(message, priv_key, hash="SHA256"):
    priv_key = importKey(priv_key)
    signer = PKCS1_v1_5.new(priv_key)

    if (hash == "SHA512"):
        digest = SHA512.new()
    elif (hash == "SHA384"):
        digest = SHA384.new()
    elif (hash == "SHA256"):
        digest = SHA256.new()
    elif (hash == "SHA1"):
        digest = SHA.new()
    else:
        digest = MD5.new()
    digest.update(message)
    return signer.sign(digest)
Beispiel #8
0
def sign(message, priv_key, hashAlg="SHA-256"):
    global hash_type
    hash_type = hashAlg
    signer = PKCS1_v1_5.new(priv_key)
    if (hash_type == "SHA-512"):
        digest = SHA512.new()
    elif (hash_type == "SHA-384"):
        digest = SHA384.new()
    elif (hash_type == "SHA-256"):
        digest = SHA256.new()
    elif (hash_type == "SHA-1"):
        digest = SHA.new()
    else:
        digest = MD5.new()
    digest.update(message)
    return signer.sign(digest)
Beispiel #9
0
def sha2(value):
    return SHA384.new(data=value).hexdigest()
Beispiel #10
0
def rsa_sign(key, message):
    h = SHA384.new(message)
    signature = pss.new(key).sign(h)
    return base64.b64encode(signature)
Beispiel #11
0
def do_hmac(key, value):
    h = HMAC.new(key, value, digestmod=SHA384.new())
    return h.hexdigest()
            if len(listaMsg) < 50:
                mensaje = linea.lstrip("Msg = ")
                listaMsg.append(mensaje.rstrip("\n"))
            else:
                break
    archivo.close()
    return listaMsg


#--------------------------- SHA-2 384 -----------------------------------------
#HASH
#print("\n *****************SHA2-384********************* ")
datos = leeArchivoSHA("SHA384ShortMsg.rsp") + leeArchivoSHA(
    "SHA384LongMsg.rsp")
listaTmpoSHA384 = []  #Lista de tiempos SHA-2 384
h = SHA384.new()
for i in range(0, 50):
    for dato in datos:
        timeI = time()
        h.update(bytearray.fromhex(dato))
        timeF = time()
        listaTmpoSHA384.append(timeF - timeI)
        #print(h.hexdigest())

#--------------------------- SHA-2 512 -----------------------------------------
#HASH
#print("\n *****************SHA2-512********************* ")
datos = leeArchivoSHA("SHA512ShortMsg.rsp") + leeArchivoSHA(
    "SHA512LongMsg.rsp")
listaTmpoSHA512 = []  #Lista de tiempos SHA-2 512
h = SHA512.new()