Full Report
The beginning of the article goes through dumping the firmware from a serial flash chip and accessing UART interface. In the UART interface, they noticed that the Linux OS was not giving any output. To fix this, they modified some UBoot settings to turn on the output. They popped them into a limited but not root shell, limiting their initial capabilities. Now, time for a chain of vulnerabilities! In the sonia binary, they found a super simple unauthenticated stack buffer overflow. The systems has ASLR enabled, stack canaries and the write is via a strcpy, which limits the amount of NULL bytes we can write. Luckily, there is no PIE. By using a partial overwrite of the stack address (3 bytes), we don't need to break ASLR. In some cases, the 4th byte will be NULL and we will write to that with our NULL byte then. I'm guessing they brute forced this 1/256 chance. This really limits our exploitation though. We can't write bytes after our address or any null bytes before that. The authors used this exploit to open up a new attack surface: the Image Quality Service (IQ). By calling the function sonia!thread_listen_handle, an unauthenticated listener is created that will loop infinitely. Neat! Within the IQ functionality, they found a heap out-of-bounds read that returns information directly to the caller. Typically, this is used for an ASLR leak, but the authors had a better idea. In a separate service (DHIP) on the same binary, there are several unauthenticated commands like resetPassword that require a special 8-byte Auth Code with secrets known to the device and technican. By using the heap leak, the secrets for the string can be leaked by continually calling checkAuthCode! Wow, that's a pretty neat exploit and usage of an information leak! The DHIP service contains an authenticated buffer overflow as well - it's a stack-based overflow into a stack buffer in JSON parsing. Now that we have leaked the password reset information, we have authenticated access to the service. The overflow occurs in a strncpy, which doesn't allow the writing of nullbytes with [ being overwritten with nullbytes after the overflow occurs. The bug above allows writing a single pointer so the gadget must be chosen wisely and then overwrite the return address of the function. At 0x002C0A2C, there is a gadget that will execute arbitrary bash commands from a single provided stack buffer input. I'm slightly confused on how this works alongside ASLR but they say it does :) They had to do some shenanigans to force this not to crash after this point too. Now, we have a command execution on the system! For whatever reason, this wasn't enough for them - they wanted the ability to execute arbitrary binaries. Since the kernel had ELF binary signature verification, this wasn't directly possible though. LD_PRELOAD can be used to load a library in an approved command to easily circumvent this protection though. Overall, it is a super interesting blog post on the exploitation of this device. The usage of pre-existing functions to exploit the binary twice instead of a traditional ROP chain is cool to see. Additionally, the heap OOB read to leak secrets is a rare feat as well. To me, this means that binary exploitation will never die but the tricks may become different. I was curious about the order in which the bugs were found and got a response from the author. They found the RCE bug first to allow for better debugging. Then, they wanted an auth bypass, which led to them finding the overflow and OOB read in the IQ stack. Upon realizing this wasn't hittable code, they found a way to turn it on. So, they effectively did this in reverse!
Analysis Summary
# Vulnerability: Multi-Stage Chain Exploitation of the 'Sonia' Binary
## CVE Details
- **CVE ID:** Not specified in context (Typically tracked under vendor-specific advisories for the targeted IoT/Camera firmware).
- **CVSS Score:** Estimated 9.8 (Critical) based on the chain resulting in Unauthenticated Remote Code Execution (RCE).
- **CWE:**
- CWE-121: Stack-based Buffer Overflow
- CWE-125: Out-of-bounds Read
- CWE-287: Improper Authentication
## Affected Systems
- **Products:** IoT devices utilizing the `sonia` binary and DHIP service (common in certain IP camera/NVR firmware).
- **Versions:** Specific versions are not listed, but affect builds where the `sonia` binary lacks PIE (Position Independent Executable) protections and contains the Image Quality (IQ) service.
- **Configurations:** Systems with UART access enabled/accessible and those running the DHIP service with `resetPassword` functionality.
## Vulnerability Description
This exploit involves a sophisticated three-stage chain:
1. **Initial Stack Overflow:** A `strcpy` vulnerability in the `sonia` binary. Despite ASLR and stack canaries, the lack of PIE allows for a partial (3-byte) overwrite of the stack address. This is used to redirect execution to the `sonia!thread_listen_handle` function.
2. **Attack Surface Expansion & Info Leak:** The first overflow enables the **Image Quality (IQ) Service** listener. An Out-of-Bounds (OOB) heap read within this service is then used to leak internal secrets (8-byte Auth Codes) required for the **DHIP service**.
3. **Authenticated RCE:** Using the leaked secrets, the attacker gains authenticated access to the DHIP service. A second stack-based overflow occurs during JSON parsing (`strncpy`). By overwriting a return address to a specific gadget at `0x002C0A2C`, the attacker executes arbitrary bash commands.
## Exploitation
- **Status:** PoC demonstrated by researchers.
- **Complexity:** High (Requires memory corruption, brute-forcing a partial overwrite, and chaining multiple service flaws).
- **Attack Vector:** Network (once the initial listener is triggered) and Physical (initial firmware dumping/UART access for research).
## Impact
- **Confidentiality:** Total (Ability to leak device secrets and arbitrary heap data).
- **Integrity:** Total (Arbitrary command execution and ability to bypass ELF signature verification via `LD_PRELOAD`).
- **Availability:** Total (Potential for persistent system compromise or bricking).
## Remediation
### Patches
- Users should update to the latest firmware version provided by the manufacturer. (Specific version numbers were not provided in the source text).
### Workarounds
- **Disable UART:** Ensure physical debug interfaces are disabled or password-protected.
- **Network Segmentation:** Place IoT devices on isolated VLANs to prevent unauthorized access to the `sonia` and DHIP service ports.
- **Disable DHIP:** If the service is not required for operation, disable it via configuration.
## Detection
- **IOCs:**
- Unexpected listening ports appearing (specifically triggered by the `sonia` binary).
- Multiple failed/repeated calls to `checkAuthCode` (indicative of secret brute-forcing or leak verification).
- Large JSON payloads containing shell-metacharacters or long strings in DHIP service requests.
- **Methods:** Monitor system logs for `sonia` process crashes (segfaults) which may occur during the 1/256 brute-force attempt of the partial stack overwrite.
## References
- **Vendor Advisory:** [Link Not Provided]
- **Research Blog:** hxxps[://]example[.]com/blog-post-on-sonia-exploitation (Source context)