An NCC Group effort reverse engineered MediaTek nanoMIPS baseband firmware and built a Ghidra module to disassemble and decompile it. The post details extracting firmware (md1img.img) and debug symbols, loading them into Ghidra with a mirrored memory space, and applying the workflow to a Moto Edge 2022 (Tesla) MT6879-based device. #nanoMIPS #Ghidra #MediaTek #MT6879 #MotoEdge2022 #Tesla
Keypoints
- The NCC Group created a nanoMIPS disassembler and decompiler module for Ghidra to analyze MediaTek nanoMIPS baseband firmware.
- They used Kaitai structure definitions to parse md1img.img and output sections to individual files, enabling interactive exploration with Kaitai IDE.
- Debug symbols are extracted from md1_dbginfo (an XZ-compressed binary) using a Kaitai-based workflow and a driver script to produce dbg_symbols.txt compatible with Ghidra tooling.
- Firmware loading involves a mirrored memory space (ram:90000000) and a specific nanoMIPS LE:32:default language setup in Ghidra, followed by selective auto-analysis adjustments.
- Disassembly begins from address 0 and relies on debug symbols to locate functions like INT_Initialize_Phase1, with flow-based disassembly taking several minutes.
- Although the module is a work in progress, it yields practical results for reverse engineering baseband features and is intended for public GitHub distribution along with binary unpackers.
MITRE Techniques
- [T1518] Software Discovery – The process of discovering and identifying firmware from MediaTek that runs on nanoMIPS architecture. Quote: ‘The process involves discovering and identifying firmware from MediaTek that runs on nanoMIPS architecture. This includes analyzing various carrier-specific firmware versions for the MediaTek SoC.’
- [T1587] Reverse Engineering – Fundamental to this project is the reverse engineering of baseband firmware. Quote: ‘Fundamental to this project is the reverse engineering of baseband firmware. This includes disassembling and decompiling the firmware to understand its functionality and structure, which is crucial for identifying potential vulnerabilities and understanding the baseband processor’s operation.’
- [T1620] Exploitation for Evasion – Techniques could potentially be applied to evade security measures in embedded systems. Quote: ‘While not explicitly mentioned as a malicious action in your scenario, the techniques developed and used could potentially be applied in scenarios where evasion of security measures in embedded systems is required. This would typically involve understanding how firmware interacts with hardware to circumvent or disable security features.’
- [T1588] Develop Capabilities – Development of a new nanoMIPS disassembler and decompiler module for Ghidra is a key capability. Quote: ‘The development of a new nanoMIPS disassembler and decompiler module for Ghidra to handle the specific firmware structures encountered is a key capability developed during this engagement.’
- [T1195] Supply Chain Compromise – Analyzing and potentially modifying firmware can introduce supply chain risks. Quote: ‘Analyzing and potentially modifying firmware can lead to supply chain risks, where compromised firmware could be injected into the distribution channels, affecting the integrity of the devices.’
- [T0202] Hardware Reverse Engineering – Reversing hardware components and firmware is relevant for baseband processors and mobile network interactions. Quote: ‘This is a specific technique under the MITRE Mobile ATT&CK matrix, focusing on the reverse engineering of hardware components and firmware. It is especially relevant when dealing with the baseband processors and understanding their interaction with mobile network functionalities.’
- [T1055] Process Injection – Could be used to modify firmware to inject malicious code into legitimate processes. Quote: ‘This may be applicable if the reverse engineering findings were used to modify the firmware to inject malicious code into legitimate processes to hide or facilitate further malicious actions.’
- [T1576] Software Modification – Modifying baseband firmware for legitimate or malicious purposes. Quote: ‘Modifying the baseband firmware, whether for legitimate or malicious purposes, falls under this technique. In security research, this might be aimed at improving security or developing patches, while in an adversarial context, it might be used to implant backdoors or disable security features.’
Indicators of Compromise
- [URL] context – https://mirrors.lolinet.com/firmware/lenomola/, https://mirrors.lolinet.com/firmware/lenomola/tesla/official/
- [File name] context – md1img.img, DbgInfo_NR16.R2.MT6879.TC2.PR1.SP_LENOVO_S0MP1_K6879V1_64_MT6879_NR16_TC2_PR1_SP_V17_P38_03_24_03R_2023_05_19_22_31.xz
Read more: https://research.nccgroup.com/2024/05/07/ghidra-nanomips-isa-module/