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!

ICAAPI.dllb

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