[Paper Review] Keyshuffling Attack for Persistent Early Code Execution in the Nintendo 3DS Secure Bootchain
This paper presents a keyshuffling attack that enables persistent early code execution on the Nintendo 3DS by exploiting AES-128-ECB's deterministic decryption in the device's secure bootchain. By manipulating Key #2 in the encrypted keystore, the attack forces the boot ROM to load and execute a malicious payload from memory before the legitimate firmware runs, allowing extraction of hardware secrets and long-term system compromise.
We demonstrate an attack on the secure bootchain of the Nintendo 3DS in order to gain early code execution. The attack utilizes the block shuffling vulnerability of the ECB cipher mode to rearrange keys in the Nintendo 3DS's encrypted keystore. Because the shuffled keys will deterministically decrypt the encrypted firmware binary to incorrect plaintext data and execute it, and because the device's memory contents are kept between hard reboots, it is possible to reliably reach a branching instruction to a payload in memory. This payload, due to its execution by a privileged processor and its early execution, is able to extract the hash of hardware secrets necessary to decrypt the device's encrypted keystore and set up a persistent exploit of the system.
Motivation & Objective
- To demonstrate a practical attack that subverts the Nintendo 3DS secure bootchain to achieve early and persistent code execution.
- To exploit the deterministic nature of AES-128-ECB mode in the keysector decryption process to manipulate firmware execution flow.
- To leverage the boot ROM's behavior of loading FIRM1 on top of FIRM0 without clearing memory to install a malicious payload.
- To extract hardware secrets (e.g., OTP hash) via early execution and establish a persistent backdoor across reboots.
- To show that added security layers, such as the ARM9Loader encryption, can inadvertently weaken existing trust chains if improperly implemented.
Proposed method
- Exploiting AES-128-ECB's block-level determinism to shuffle keys in the encrypted keystore, causing predictable decryption of firmware to incorrect but executable code.
- Brute-forcing Key #2 to find a value that, when used to decrypt the 10.2.0 firmware binary, results in a branch instruction pointing 0x190 bytes beyond the end of the 8.1.0 firmware binary.
- Installing the crafted, encrypted Key #2 into the keystore and placing a custom payload at the calculated offset in the 10.2.0 firmware binary.
- Leveraging the boot ROM's fallback behavior: when FIRM0 fails signature verification, FIRM1 is loaded on top of it without memory clearing.
- Using the boot ROM’s use of keyslot 0x06 to decrypt both FIRM partitions, enabling the malicious payload to be loaded and executed before the ARM9 firmware runs.
- Executing the payload early in the boot process, before the ARM9 firmware clears the SHA_HASH register, to extract the OTP hash and establish persistence.
Experimental results
Research questions
- RQ1Can the deterministic behavior of AES-128-ECB in the 3DS keystore be exploited to redirect code execution to a malicious payload?
- RQ2Does the boot ROM’s behavior of loading FIRM1 on top of FIRM0 without clearing memory enable a persistent code execution vector?
- RQ3Can a crafted key in the keystore cause the ARM9 firmware binary to be decrypted to a malformed but executable state with a controlled jump target?
- RQ4Is it possible to extract hardware secrets like the OTP hash before the ARM9 firmware clears the SHA_HASH register?
- RQ5To what extent do additional encryption layers in a secure bootchain introduce new attack vectors if not properly audited?
Key findings
- The attack successfully achieves persistent early code execution on the Nintendo 3DS by exploiting AES-128-ECB's deterministic block decryption in the keystore.
- A specific Key #2 was brute-forced such that its decryption of the 10.2.0 firmware binary results in a branch instruction to a memory location 0x190 bytes beyond the end of the 8.1.0 firmware binary.
- The payload is reliably executed before the ARM9 firmware runs, due to the boot ROM loading FIRM1 on top of FIRM0 without clearing memory after a failed signature check.
- The attack allows extraction of the OTP hash from the SHA_HASH register before the ARM9 firmware clears it, enabling full key recovery.
- The implementation of the ARM9Loader in version 9.6.0 introduced a critical flaw by failing to verify Key #2, which was exploited to enable the keyshuffling attack.
- The attack demonstrates that new security measures, such as the ARM9Loader encryption layer, can weaken existing trust chains if not properly validated.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.