Buffer Overflow in PHP of the AirMax Products
A filename normalisation routine in the AirMax upload handler miscalculates the length passed to a memory move when a filename contains both a backslash and a forward slash, so the copy runs past the end of the buffer. An attacker sending a crafted multipart upload filename could overflow heap memory, though the author judges arbitrary code execution unlikely but possible.
- Fixed in 55 days
- Paid in 4 months
- Disclosed after 9 months
#Vulnerability
The function static int ub_normalize_filename(char* filename) (implemented by the patch 430-smart-post-upload.patch in the file uploadbuffer.c on the SDK.UBNT.v5.5) have the following code:
static int ub_normalize_filename(char* filename)
{
char *fwd_slash;
char *back_slash;
size_t size;
/**
* Some comments removed
*/
if (filename == 0)
{
return -1;
}
size = strlen(filename);
fwd_slash = strrchr(filename, '/');
back_slash = strrchr(filename, '\\');
if ((fwd_slash == 0) ||
(back_slash == 0))
{
/* No slashes or backslashes */
return 0;
}
if ((back_slash - filename == size - 1) ||
(fwd_slash - filename == size - 1))
{
return -1; /* 'Empty filename ???' */
}
/* Move file part from last backslash to last forwardslash,
Copy including ending string \0 */
memmove(fwd_slash + 1, back_slash + 1, size - (back_slash - filename));
return 0;
}
Manipulating the filename value of a HTTP POST (like in the report 73480), it's possible to cause a buffer overflow with the following value filename="\asdfasdfasdfasdfsdfgdsfg/a". The Pointers will point to the following locations:
\asdfasdfasdfasdfsdfgdsfg/a\0
^ ^ ^
-back_slash | |
| -End of String
|
-fwd_slash
The memmove will write to fwd_slash + 1 the content of back_slash + 1 (until the end of the String), what will copy string off the bounds.
\asdfasdfasdfasdfsdfgdsfg/aasdfasdfasdfasdfsdfgdsfg/a
^ ^
-Init |
-End of String
#Consequences
It's possible to cause a buffer overflow, but it's unlikely the vulnerability to result in a arbitrary code execution (but possible), once it's allocated in a the heap memory (function ub_parse_disposition, file uploadbuffer.c, I think).
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the length argument to the memory move is computed from the position of the last backslash rather than the distance between the two slash positions, so the copy extends beyond the end of the string.
Impact
The overflow corrupts heap memory; the author considers arbitrary code execution unlikely but possible.
What the attacker needed
Network access to the device upload endpoint; ability to send a crafted multipart POST
How it was found
- Send an HTTP POST with a multipart body whose filename field contains a leading backslash, a long run of characters, then a forward slash and a short tail.
- The upload handler passes that filename to the normalisation function.
- The function locates the last backslash and last forward slash and moves the tail of the string to just after the forward slash.
- Because the length is wrong, the move writes past the end of the allocated buffer.
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 report has not been written yet. The Original tab links to the source.
When a file is uploaded, the device tidies up the filename by moving part of the text around in memory. The code that decides how much text to move gets the length wrong when the name contains both kinds of slash, so it copies more characters than fit and spills past the buffer. This could overflow heap memory, and arbitrary code execution is unlikely but possible.
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.