Exploiting: Buffer overflow in Xiongmai DVRs
A buffer overflow in the RTSP server of Xiongmai DVRs allows an attacker to overwrite the link register and control the program counter, leading to remote code execution. The exploit bypasses ASLR by using a non-PIE binary and a gadget that moves a pointer to the attacker's data into the argument register before calling system().
Published on blog.ret2.me
As part of my work at FortNet I’ve had the chance to research some embedded devices. This provided a good chance to learn more about the ARM architecture and the differences between ARM and x86 exploitation.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The RTSP server uses strncpy to copy a user-supplied length of data into a fixed 2048-byte stack buffer without checking the length, causing a stack buffer overflow.
Impact
An attacker could execute arbitrary commands on the device, potentially leading to full compromise, though a watchdog may reboot the device after failed attempts and mass exploitation is unlikely without version disclosure.
What the attacker needed
Network access to the DVR's RTSP port; knowledge of the firmware version
The fix
The vulnerability was fixed by Xiongmai, and updated firmware is available for affected devices.
How it was found
- Connect to the DVR's RTSP port (554) and send an OPTIONS request with an overly long CSeq header.
- Observe the crash and use a debugger to confirm control of the program counter.
- Determine the offset to the link register by sending a random pattern and finding the overwritten value.
- Identify a gadget in the non-PIE binary that moves the R9 register (pointing to the request data) into R0 and calls system().
- Craft a payload with the command at the start, padding to the offset, and the gadget address to execute the command.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A DVR is a device that records video from security cameras. The software that handles video streaming (RTSP) had a bug: it copied too much data into a small memory area, letting an attacker overwrite important control information. This could let an attacker run their own commands on the device.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.