Microsoft DirectShow - Arbitrary Memory Overwrite (MS13-056)








The Microsoft DirectShow application programming interface (API) is a media-streaming architecture for Microsoft Windows. Using DirectShow, your applications can perform high-quality video and audio playback or capture.  


DirectShow in Microsoft Windows XP SP2 and SP3, Windows Server 2003 SP2, Windows Vista SP2, Windows Server 2008 SP2 and R2 SP1, Windows 7 SP1, Windows 8, and Windows Server 2012 allows remote attackers to execute arbitrary code via a crafted GIF file, aka "DirectShow Arbitrary Memory Overwrite Vulnerability." 

Disclosure Timeline

2013-03-20 - Vulnerability reported to vendor
2013-07-09 - Coordinated public release of advisory


Microsoft's DirectShow API is vulnerable to arbitrary memory overwrite when reading specially crafted GIF files. I have attached a GIF which triggers the vulnerability. To open it you can use Media Player Classic which utilizes DirectShow API to render GIF files. I tested it on Windows XP SP3 and Windows 7 SP1 Spanish version. The corresponding output from WindDbg in Windows XP is:

ModLoad:    72c90000 72c98000      C:\WINDOWS\system32\msacm32
ModLoad:   77bb0000 77bc5000       C:\WINDOWS\system32\MSACM32.dll
ModLoad:   77ba0000 77ba7000       C:\WINDOWS\system32\midimap.dll
ModLoad:   73e60000 73e64000       C:\WINDOWS\system32\KsUser.dll
ModLoad:   60830000 608bc000       C:\WINDOWS\system32\qedit.dll
ModLoad:   75ed0000 75ef1000        C:\WINDOWS\system32\MSVFW32.dll

(bd0.bf4): Access violation - code c0000005 (first chance) First chance exceptions are reported before any exception handling.

This exception may be expected and handled.

eax=ff414141 ebx=fffffa60 ecx=00000000 edx=fea57028 esi=fea57028 edi=000000ef
eip=60864094 esp=0274ec0c ebp=0274ed3c iopl=0         nv up ei ng nz ac pe cy
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010297


60864094 8902            mov     dword ptr [edx],eax  ds:0023:fea57028=????????

The issue occurs inside qedit.dll when trying to read GIF header data, in CImgGif::ReadImage+0x288. This writes in memory position edx=fea57028 the value eax=ff414141 both of them controlled by the user. eax=fea57028 can be modified in the GIF file in the position 0x32C corresponding to NW corner of frame at 0, 0 and eax=ff414141 can be modified in the position 0x307 corresponding to Global Color Table. With these two values controlled by an attacker, arbitrary code execution could be achieved, with the privileges of the user running the application (in this case MPC).