Exemplo n.º 1
0
def decrypt(prx, meta, **kwargs):
    p = prx_header_8(prx)
    xorbuf = kirk.kirk7(meta['seed'], meta['key'])

    # calculate SHA1 of header
    h = SHA1.new()
    h.update(xorbuf[:0x14])
    h.update(p.vanity_area())
    h.update(p.kirk_block())
    h.update(p.kirk_metadata())
    h.update(p.elf_info())

    if h.digest() != p.sha1_hash():
        print("bad SHA1")
        return False

    # decrypt the kirk header
    header = xor(p.kirk_block(), xorbuf[0x14:0x84])
    header = kirk.kirk7(header, meta['key'])
    header = xor(header, xorbuf[0x20:])

    # prepare the kirk block
    block = header + p.kirk_metadata() + p.elf_info() + prx[0x150:]

    # do the decryption
    return kirk.kirk1(block)
Exemplo n.º 2
0
def decrypt(prx, meta, **kwargs):
    xorbuf = expand_seed(meta['seed'], meta['key'])

    # check if range contains nonzero
    if any(x != 0 for x in prx[0xD4:0xD4 + 0x30]):
        return False

    p = prx_header_9(prx)

    print(meta['pubkey'])
    print(p.prx_ecdsa().hex())

    # check ECDSA signature
    # kirk.kirk11(bytes.fromhex(meta['pubkey']), p.prx_ecdsa(
    # ), prx[4:0x104] + b'\x00'*0x28 + prx[0x12C:])

    h2 = SHA1.new()
    h2.update(prx[4:0x104] + b'\x00' * 0x28 + prx[0x12C:])
    print(h2.hexdigest())

    # decrypt the header information
    p.decrypt_header(meta['key'])

    # calculate SHA1 of header
    h = SHA1.new()
    h.update(p.tag())
    h.update(xorbuf[:0x10])
    h.update(b'\x00' * 0x58)
    h.update(p.btcnf_id())
    h.update(p.kirk_aes_key())
    h.update(p.kirk_cmac_key())
    h.update(p.kirk_cmac_header_hash())
    h.update(p.kirk_cmac_data_hash())
    h.update(p.kirk_metadata())
    h.update(p.elf_info())

    # sanity check that our SHA1 actually matches
    if h.digest() != p.sha1_hash():
        return False

    # decrypt the kirk block
    header = xor(p.kirk_block(), xorbuf[0x10:0x50])
    header = kirk.kirk7(header, meta['key'])
    header = xor(header, xorbuf[0x50:])

    # prepare the kirk block
    block = header + b'\x00' * 0x30
    block = set_kirk_cmd_1(block)
    block = block + p.kirk_metadata() + b'\x00'*0x10 + \
        p.elf_info() + prx[0x150:]

    return kirk.kirk1(block)
Exemplo n.º 3
0
def decrypt(prx, meta):
    xorbuf = expand_seed(meta['seed'], meta['key'])

    # check if range contains nonzero
    if any(x != 0 for x in prx[0xD4:0xD4 + 0x38]):
        return False

    p = prx_header_6(prx)

    # decrypt the header information
    p.decrypt_header(meta['key'])

    # calculate SHA1 of header
    h = SHA1.new()
    h.update(p.tag())
    h.update(xorbuf[:0x10])
    h.update(b'\x00' * 0x38)
    h.update(p.kirk_ecdsa_data_sig_end())
    h.update(p.btcnf_id())
    h.update(p.kirk_aes_key())
    h.update(p.kirk_ecdsa_header_sig())
    h.update(p.kirk_ecdsa_data_sig_begin())
    h.update(p.kirk_metadata())
    h.update(p.elf_info())

    if h.digest() != p.sha1_hash():
        print("bad SHA1")
        return False

    # decrypt the kirk header
    header = xor(p.kirk_block(), xorbuf[0x10:0x50])
    header = kirk.kirk7(header, meta['key'])
    header = xor(header, xorbuf[0x50:])

    # prepare the kirk block
    block = header + p.kirk_ecdsa_data_sig_end() + b'\x00' * 0x10
    block = set_kirk_cmd_1(block)
    block = set_kirk_cmd_1_ecdsa(block)
    block = block + p.kirk_metadata() + b'\x00'*0x10 + \
        p.elf_info() + prx[0x150:]

    # do the decryption
    return kirk.kirk1(block)
Exemplo n.º 4
0
        __ROR4__(keys[0], ror_cnt),
        bitrev32(__ROR4__(keys[1], ror_cnt)),
        __ROR4__(keys[2], ror_cnt) ^ keys[3],
        __ROR4__(keys[3], ror_cnt)
    ]

    return bytearray(b''.join([x.to_bytes(4, 'little') for x in xor_key]))


with open(args.input, 'rb') as rf:
    with open(args.output, 'wb') as of:
        while True:
            block = bytearray(rf.read(0x1000))
            if not block:
                break

            if args.xor:
                key = getXorKey(args.xor)

                for i in range(16):
                    block[i] ^= key[i]

            block[0x62] = 0

            block = kirk1(block)

            address, size, entry, sum = struct.unpack('<IIII', block[:16])
            data = block[16:16 + size]

            of.write(data)