Skip to content
Memory corruption Write-up Advanced

Exploiting MediaTek's Download Agent

A heap overflow exists in the XML (V6) Download Agent's file download handler, where a filename is expanded for XML escaping into a fixed 512-byte buffer without bounds checking. An attacker with host-side control of the USB download protocol could overflow the heap and, by corrupting free-list pointers, gain arbitrary code execution on patched V6 devices.

blog.r0rt1z2.com

Published on blog.r0rt1z2.com

Reverse Engineering

Roger Ortiz, on blog.r0rt1z2.com

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 XML escaping routine allocates a fixed 512-byte buffer and expands special characters (such as ampersands) without any bounds checking, so a long filename overflows the heap.

Impact

The overflow could corrupt free-list pointers to give a write-what-where primitive and ultimately arbitrary code execution on V6 devices patched against Carbonara; the text notes the overflow is only 172 bytes and that most of the oversized filename is padding.

What the attacker needed

Host-side control of the USB download protocol; a V6 Download Agent target; physical USB access to the device

How it was found

  1. Send the all-in-one signature command with a normal filename and file data
  2. Send a second all-in-one signature command with an overly long filename full of special characters
  3. Send a second all-in-one file
  4. Intentionally trigger an error by not sending the expected acknowledgement

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 Download Agent is a small program that runs on a phone's chip to handle flashing over USB. When it received a filename, it made the name longer by replacing certain characters with longer codes, but it wrote the result into a fixed-size box without checking the length, so a long name spilled into neighbouring memory. By carefully controlling what got overwritten, an attacker could take over the program.

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.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.