Unziploc PDF
Unziploc PDF
$whoami
Motivation
− eRecovery: downloads by itself the update via wifi (e.g. when the phone does not boot)
• Dedicated recovery environment (same kernel, but separate ramdisk with tools)
Update file format
• Format described at AOSP:
bootable/recovery/install/verifier.cpp
Update file signature
● Located in the comment field, transparent for a ZIP extractor
● signs the whole file except the comment size field
Signature verification
● Verifier gets the signature based on the footer fields
● Verifies that by going back “comment size” there is in fact a valid EOCD block
● Also checks integrity of the footer and finally the validity of the signature
− verifier code: where the comment size field points (the original, signed one)
− minzip code: the closest EOCD marker to the end of the ZIP file
• A gap can be made between the signature and the EOCD block
• Let’s smuggle a valid (offset-aligned) ZIP file into the gap
• Huawei used a modified version of the verifier, which didn’t have a check
https://android.googlesource.com/platform/bootable/recovery/+/refs/heads/android12-release/install/verifier.cpp
Unzip to RCE
• Once all checks are passed, the actual update is not carried out by
the /sbin/recovery executable itself!
− auth-token: the update server issues this for the recovery on an OTA update
=> create a “skipauth_pkg.tag” empty file in the update archive
− Firmware version must be applicable for the given device hw/sw revision
=> create a “SOFTWARE_VER_LIST.mbn” file filled with device prefixes
Triggering with Local Access
• Memory card (SD/NM card, USB Flash Drive) based update
• Trigger options:
2) during boot, button press combo to boot recovery + ”Update mode → Memory card/
OTG update mode”
• Automatically tries to mount external storage -> connecting a USB flash drive with
dload/update_sd_base.zip, recovery binary triggers automatically
• Note: this means that physical access (w/o knowing user unlock secret) is enough to
get code execution as root in recovery!
Triggering Remotely
• BUT: the query server returns CDN server URLs (update.dbankcdn.com) that are plain
HTTP!
• <base URL>/full/filelist.xml contains MD5 hashes of images - also served via HTTP
• Authentication token served via HTTPS – but it can be skipped with the “skipauth_pkg.tag”
file
• CVE-2021-40055
eRecovery HOTA
• Update query over HTTPS
• Recovery is allowed to access Wi-Fi (to support eRecovery OTA), so the attacker
update-binary can bring up Wi-Fi itself
• Recovery != Android
• Take over the kernel runtime, attack the platform from kernel
Escalation Via Kernel Route
Fastboot Unlock
• Known Secure Boot vulnerabilities [BH 2021]: needed USB path, patched
• Writable - but signed with an RSA key, public key burnt into Fastboot image
• https://labs.taszk.io/articles/post/exploiting_huaweis_npu_driver/
• Image rewrite needs reboot to take effect: how do we preserve code exec?
Kernel 0-day
• https://consumer.huawei.com/en/support/bulletin/2022/4/
DMSS entry address | index | range begin-end | (N)S: (non)secure R/W | AXI Master ID for (W)rite and (R)ead
0xffe82e30 19: 0x13000000 - 0x135fffff SR SW W00010020 R00010020
0xffe82e40 20: 0x13600000 - 0x192fffff SR SW W00010420 R00010420
• CVE-2021-39992
}
(DMA_2BITS_MASK << DMA_CH_CFG_SW);
...
}
• CVE-2021-37115: The modem can overwrite the SRAM of the LPMCU …. and
the LPMCU can rewrite ASI entries
• The modem EDMA can write all modem AND LPMCU memory
• The EDMA control registers are programmable by the kernel too (CVE-2021-37107)
• Fine print: need to have modem powered and overcome the limited memory
mapping view of the LPMCU
• Deriving FDE keys in Huawei TrustZone [See WOOT 2020 Busch et al.]
• Once we have code execution in the TEE, we can offline bruteforce the PIN
input and recover FDE keys
Demo
Disclosure Process
• Every reported bug fixed via Huawei OTA update (security bulletins: 2022
February, March, April)
Thank you!
Daniel Komaromy
[email protected]
Twitter: @kutyacica
Lorant Szabo
[email protected]
Twitter: @szabolor