バッファオーバーフローの脆弱性が Lhaplus.exe の以下の似ているの function にあります。
sub_4B64C8()
{
...
...
struct HEADER *lzhHeader;
char *buffer;
char extendedHeaderType;
..
..
..
if(lzhHeader->headerLevel == 0)
{
...
}
else if(lzhHeader->headerLevel == 1)
{
...
}
else if(lzhHeader->headerLevel == 2)
{
readData(handle, 2, &(lzhHeader->fileCRC));
readData(handle, 1, &(lzhHeader->OSID));
...
}
else
{
...
}
if(lzhHeader->headerLevel == 1 || lzhHeader->headerLevel == 2)
{
buffer = allocateMem(0x100); // 256 bytes
// Extended header reading loop
while(true)
{
// Read Extended Header Size from LZH file
// LZHファイルから 「Extended Header Size」を読みます。
bytesread = readData(handle, 2, &(lzhHeader->extendedHeaderSize));
if(lzhHeader->extendedHeaderSize == 0 || bytesread == 0)
break;
readData(handle, 1, &extendedHeaderType);
if(bytesread == 0)
break;
clearMemory(buffer, 0x100);
// NOTE: "lzhHeader->extendedHeaderSize" is read from the LZH file
// and not sanitised.
// This causes a heap-based buffer overflow if the value of the extended
// header size is > 0x100.
// 「Extended Header Size」 > 256 のとき、バッファオーバーフローが発生します。
// Potential integer underflow can also occur due to the subtraction of 3
// from the extended header size value.
// 「Extended Header Size」 < 3 のとき、integer underflow が発生します。
// i.e Must check lzhHeader->extendedHeaderSize > 3 and <= 0x100
bytesread = readData(handle, lzhHeader->extendedHeaderSize - 3, buffer);
...
if(extendedHeaderType == 1)
{
...
}
else if(extendedHeaderType == 2)
{
...
}
}
}
...
}
By overwriting saved pointers on the heap using the
buffer overflow, it is possible to execute arbitrary code.