Technical Analysis of CVE-2019-0708
Technical Analysis of CVE-2019-0708

Microsoft patch Tuesday, May (2019) comes with a patch for critical RDP RCE Vulnerability, CVE-2019-0708 Remote Code Execution Vulnerability exists in Remote Desktop Services (RDP) pre-authentication and requires no user interaction Microsoft described it as โWormableโ so we could see new Wannacry hit the world! unfortunately, the world as we know it is not safe as we think and the threats are bigger than public ips within known internet scanners like shodan.io , censys.io etc

I think the threat is more than that number! we have RDP services running over other ports, as well the number itself is not kinda live number, however from my own internet scanner โFalcon-Clawโ data comes from crawlers in last 24h shows that 8057271 RDP Host is online on last 24h however itโs not blog about is my scanner is better then shodan or not.

so the attack scope is really huge and the world as we know kinda in risk since thereโs a lot of critical environments their vulnerable system exposed to the internet so however letโs get in and understanding the bug! in this blog we will analysis the patch and diff some dlls and try to understand whatโs going on !
as most security researchers I have been trying some stuff with RDP since itโs good money! for example zerodium pay around 1m$ for an exploit like this ! so itโs really good money, however, I will go with normal patch analysis process but in fact, I already skipped a lot of stuff since I already know what I am looking for
BTW we will find soon some threat hunting guys catch the exploit in the next few weeks! if they didnโt already!
Security Updates
Microsoft delivers updates in 2 formats
- exe format for XP/2K3 Systems
- msu (standalone update) format for Windows 7 +
however, I will pick โWindows 7 for x64-based Systems Service Pack 1โ update for analysis since I will talk about how we can extract patched dlls, exe, and drivers from the downloaded update from Microsoft
KB4499175 Analysis
KB4499175 which is I am going to analysis it, we will extract the files and we will kinda pick up only interesting stuff since the update patches other bugs as well, and weโre just interested in RDP stuff as well maybe network drivers and Dlls if thereโs any
Extract the Patch
it would be mess if you tried to extract it with expand.exe so however, I will suggest a PowerShell Tool for extract the patch files however I have been using this tool for a while since the output is really good organizedย PatchExtract125.ps1ย you can pass the msu file via -Patch , and try to do it in empty folder !
./PatchExtract125.ps1 -Patch downloaded_update.msu

Get-ChildItem -Recurse -Filter *.dll|Export-Csv -Path all_dlls.csv
Get-ChildItem -Recurse -Filter *.sys|Export-Csv -Path all_sys.csv
Get-ChildItem -Recurse -Filter *.exe|Export-Csv -Path all_exe.csv
Drivers Quick Look
Our scope is RDP โ Pre Auth we will take look on drivers first maybe we will start from there so starting taking notes about each driver functions and how itโs work and trying to put interesting drivers on the list to perform diff however I donโt know if thereโs a list to know about drivers functionality etc all what I see on the internet is just websites telling you hey do you hate blue screen ? so just google the driver name wonโt gain you anything but you can try this one for example
peauth.sys site:microsoft.com
keep your research only in Microsoft blogs etc you will get useful information also keep try harder cuz maybe when youโre trying to understand a bug or a patch maybe you can get another one!
From 0 to Diff
So the scope kinda huge but we still need to hunt for a quick thing to save the time, I already saw blogs written in Chinese about diffing termdd.sys and they found kinda good stuff! but I wasnโt sure and I still not sure if the exploit can land there! but

sending simple unauthenticated RDP network packet , it will land in 2 places, termdd.sys and ICAAPI.dll, but ICAAPI.dll not touched on this patchโฆ itโs just โDLL Interface to TermDD Device Driverโ

Limited Choices
so now weโre front of tremdd.sys so as I think this how the normal RDP Packet Landing on the endpoint

tremdd.sys probably got the vulnerable function
ICAAPI.dll
before we even think about diff tremdd.sys since once you diff it wonโt take too much to spot the vulnerability but it will take too much time to hit a breakpoint within or near the vulnerable function so itโs a good idea I think to reverse ICAAPI.dll and understand the execution flaw it would be much easy for you to write the exploit!

the dll begin called by โsvchost.exeโ I am not sure if this one is the latest version of that dll but 22 kb wonโt take too much time to reverse, but keep it away now and letโs diff the driver because thatโs all what we got in the patch so letโs give it a priority
Diff termdd.sys
Usingย diaphoraย and IDA Pro, I started to take look inside termdd.sys

_ReconnectStack
My first thoughts came to _ReconnectStack Function since I saw video coming from โsomewhereโ exploiting the bug and seems like the attacker made kinda reconnect operation after executing the exploit script and just popped up a shell on next connect

on the right side is the patched code ! so once you call _ReconnectStack and go with the condition will just call โIcaRebindVirtualChannelsโ instead of going throw find the channel and โ_IcaBindChannelโ so letโs take this function in our count as well, I mean they did it for a reason! maybe itโs exploitable also, but I found other interesting patched function calling IcaBindChannel

IcabindBirtualChannels
Before we look at the vulnerable function weโre going to look at the patched one that will give us an idea about what weโre looking for

Patched Channel number controlled
The patch trying to set channel number to 31, but if the channel name is equal โMS_T120โ then it will set it to something else, and always highlight controlled parameters by the program if youโre looking in the patched side because once youโre front of vulnerable code you will know what youโre looking for so thatโs why I highlighted channel number and you will understand more when you see the vulnerable code .

r8d reg should be 31
testing eax and set r8d to rbp offet -2 which is probably a default integer coming from the (char_p โ 1) and thatโs if channel name is not equal MS_T120 ,
simply means that this parameter would be 31 or other int coming from (char_p โ 1) โrbp-2โ so itโs kinda controlled parameter now, itโs time to take look into the vulnerable function
patching a critical bug like this one with stricmp i donโt think itโs a good idea in general maybe itโs secure!

pass channel number directly

r8d reg is the channel number
So now we know our controlled parameter itโs time to check _IcaBindChannel Looking for memory corruption or something to exploit
Articles from the workshop




