Description
The unnamed function at 0x80bb148 is used to copy data into a buffer and lacks a destination length check. This function is called in two places - by process_fmt() and fmt_cell_combine(). The call by process_fmt() is reachable using a w3r_format element (0x13) in a wk3 file, where user-controlled data from the file is copied into a stack variable. The call by fmt_cell_combine() was not investigated.
ushort process_fmt(byte *buf,ushort buflen,ushort param_3)
{
[...]
char local_404 [1024];
[...]
uVar3 = FUN_080bb148(local_404,buf + 4,buflen - 4);
dst src len
Both buf and buflen are controllable. The included exploit demonstrates this by overwriting the return address to point to a jmp esp gadget, where the payload causes the process to exit with a return value of 3 (I had originally intended to submit this to BGGP3, but missed the deadline!)
A pull request will be provided containing a proposed fix.
Base64 encoded exploit.wk3 - AAAFAAAQBAAREwAVAAAAAAD+/v7+/zMzMzO8yhIIQM2AMw==
[edit: reduced exploit size from 38 to 34 bytes]
This was discovered using Ghidra and AFL++'s QEMU mode, and was inspired by this tweet.