WMI - A FRONT DOOR FOR MALWARES

34
Windows Management instrumentation – A Front Door for malwares Santhosh Kumar

Transcript of WMI - A FRONT DOOR FOR MALWARES

Page 1: WMI - A FRONT DOOR FOR MALWARES

Windows Management instrumentation – A Front Door for malwares

Santhosh Kumar

Page 2: WMI - A FRONT DOOR FOR MALWARES

Whoami

• Love to Break things apart. • Hobby Hacker.• Spoke at Various conferences including

DEFCON las Vegas, OWASP Appsec USA 2014, Bsides Las Vegas.

• Second time here.

Page 3: WMI - A FRONT DOOR FOR MALWARES

Outline

• WM … What? • WMI malwares Timeline.• WMI Architecture• WQL• WMI providers.• WMI Eventing• Demo• Defenses

Page 4: WMI - A FRONT DOOR FOR MALWARES

WM…what?

• System Management both remote and locally.• Deployed way back in NT4 and Windows 98/95.• Used to access registry,File System,network etc.• Eventing,Remoting and Remote Code execution • Endless possibilities.• Various tools support.• Own Query language.

Page 5: WMI - A FRONT DOOR FOR MALWARES

Why Should i care?

Page 6: WMI - A FRONT DOOR FOR MALWARES

WMI malware Timeline

• MS10-061 – Windows printer spooler • Attackers Dropped a MOF file to gain RCE.• Microsoft patched it in KB2347290 Update

http://poppopret.blogspot.in/2011/09/playing-with-mof-files-on-windows-for.html

Page 7: WMI - A FRONT DOOR FOR MALWARES

Hammertoss APT (2015)

• Heavy reliance upon WMI and PowerShell ƒ

• Custom WMI class creation ƒ • WMI repository used to store payloads of

arbitrary size ĥ Results of commands added to WMI

object properties • https://www2.fireeye.com/rs/848-DID-242/i

mages/rpt-apt29-hammertoss.pdf

Page 8: WMI - A FRONT DOOR FOR MALWARES

Syndicasec (2013-2015)

• 2 stage infection. • creates a TimerInstruction to raise a

custom event• Eventfilter is created to link to the

timerinstruction and EvilProviders• Everytime it is linked the consumer is

executed leaving to RCEhttp://www.welivesecurity.com/2013/05/23/syndicasec-in-the-sin-bin/

Page 9: WMI - A FRONT DOOR FOR MALWARES

WMI architecture

• https://msdn.microsoft.com/en-us/library/aa394553(v=vs.85).aspx

Page 10: WMI - A FRONT DOOR FOR MALWARES

Interaction with WMI

Page 11: WMI - A FRONT DOOR FOR MALWARES

Interaction with wmi

Page 12: WMI - A FRONT DOOR FOR MALWARES

Interaction with wmi

Page 13: WMI - A FRONT DOOR FOR MALWARES

winrm

Page 14: WMI - A FRONT DOOR FOR MALWARES

Interaction with wmi

• .net• Vbscript• Jscript• C/C++ via IWbem COM API • More utilities • http://passing-the-hash.blogspot.in/2013/0

4/missing-pth-tools-writeup-wmic-wmis-curl.html

Page 15: WMI - A FRONT DOOR FOR MALWARES

WQL• Similar like SQL.Query for WMI objects,classes and

Namespaces.• Three types of query• Data Query• Event Query• Schema Query• Useful for RECON• https://msdn.microsoft.com/en-us/library/aa392902(v=vs.

85).aspx

Page 16: WMI - A FRONT DOOR FOR MALWARES

WMI Recon

• Find installed Antivirus

Page 17: WMI - A FRONT DOOR FOR MALWARES

WMI recon

• Find the Security Updates installed on the system

• Find if it is a VM

Page 18: WMI - A FRONT DOOR FOR MALWARES

WMI providers

• Form the core working of WMI• Contains a DLL & MOF file for each

provider• Have the own listing of GUID for each

provider• %windir%\System32\Wbem• Sometimes there can be a custom wmi

providers

Page 19: WMI - A FRONT DOOR FOR MALWARES

Malicous WMI providers• EvilWMIProvider by Casey Smith (@subTee) –

https://github.com/subTee/EvilWMIProvider • Invoke-WmiMethod -Class Win32_Evil -Name

ExecShellcode -ArgumentList @(0x90, 0x90, 0x90), $null

• EvilNetConnectionWMIProvider by Jared Atkinson (@jaredcatkinson) – https://github.com/jaredcatkinson/EvilNetConnectionWMI

• Invoke-WmiMethod -Class Win32_NetworkConnection - Name RunPs -ArgumentList 'whoami' , $null – Get-WmiObject -Class Win32_NetworkConnection

Page 20: WMI - A FRONT DOOR FOR MALWARES

WMI eventing• Wmi can be used to monitor any type of Operating

system events.• Classified as two types• Intrinsic events• Extrinsic events• 3 requirement to define a event filter• Filter,consumer and binding• http://blogs.technet.com/b/heyscriptingguy/archive/2012/06/08/an-insider-s-guide-to-using-wmi-e

vents-and-powershell.aspx

Page 21: WMI - A FRONT DOOR FOR MALWARES

Intrinsic Events

• Intrinsic events are system classes included in every namespace

• Monitor any changes to the class or namespace

• Should be executed within the polling interval

• https://technet.microsoft.com/en-us/library/ee156572.aspx

Page 22: WMI - A FRONT DOOR FOR MALWARES

Extrinsic Events

• Use to monitor resources which is not included in CIM repository

ROOT\CIMV2:Win32_ComputerShutdownEvent ROOT\CIMV2:Win32_IP4RouteTableEvent ROOT\CIMV2:Win32_ProcessStartTrace ROOT\CIMV2:Win32_ModuleLoadTrace ROOT\CIMV2:Win32_ThreadStartTrace ROOT\CIMV2:Win32_VolumeChangeEvent ROOT\CIMV2:Msft_WmiProvider* ROOT\DEFAULT:RegistryKeyChangeEvent ROOT\DEFAULT:RegistryValueChangeEvent

Page 23: WMI - A FRONT DOOR FOR MALWARES

Event Filter• Define which event to trigger• WMI query • Intrinsic Query • SELECT * FROM __InstanceOperationEvent WITHIN 30

WHERE ((__CLASS = "__InstanceCreationEvent" OR __CLASS = "__InstanceModificationEvent") AND TargetInstance ISA "CIM_DataFile") AND (TargetInstance.Extension = "doc") OR (TargetInstance.Extension = "docx")

• Extrinsic Query • SELECT * FROM Win32_VolumeChangeEvent WHERE

EventType = 2

Page 24: WMI - A FRONT DOOR FOR MALWARES

Event Consumer

• Define what to do when event is called.• These are the standard event consumers:

LogFileEventConsumer ActiveScriptEventConsumer NTEventLogEventConsumer SMTPEventConsumer CommandLineEventConsumer

Page 25: WMI - A FRONT DOOR FOR MALWARES

WMIGHOST apt• Targeting indian Users mainly military, energy and government

policy.• Infection via spear phishing attempt• Drops a unclassified government file like this

Page 26: WMI - A FRONT DOOR FOR MALWARES

WMIGHOST (2014-2015)

• India US strategic dialouge press release.doc” (000150415302D7898F56D89C610DE4A9).

• Then drops if successful dw20.exe and gupdate.exe

https://github.com/ytisf/theZoo/tree/master/malwares/Binaries/WMIGhost

Password:infected

Page 27: WMI - A FRONT DOOR FOR MALWARES

ShadowNet APT• This was detected this year during the tibetian uprising

day.• Group modified the toolchain to add WMI script for

gathering information and exfiltration.• Multi Layer C&C server and identifies victim using

encoded strings

Registrant Name: Kasong Dolma Registrant Street: New York Registrant City:New York Registrant State/Province:guangdong Registrant Postal Code:10001 Registrant Country:CN Registrant Phone:+1.9175608889 Registrant Email: [email protected]

Page 28: WMI - A FRONT DOOR FOR MALWARES

WMI OFFENSIVE TOOLS

Page 29: WMI - A FRONT DOOR FOR MALWARES

DEMO

• Acts like a Shell using WMI as C&C.• Uses Namespaces for Storing the data.• Uses Base64 encoding to store the data in

the namespace to avoid firewall and endpoints

• Decodes Base64 data on attacker machine

Page 30: WMI - A FRONT DOOR FOR MALWARES

Defenses

• Don’t enable WMI Remoting? • More strict Firewall Rules• permanent WMI event subscriptions • Custom Event logs.

Page 31: WMI - A FRONT DOOR FOR MALWARES

Books

Page 32: WMI - A FRONT DOOR FOR MALWARES
Page 33: WMI - A FRONT DOOR FOR MALWARES

References• http://www.trendmicro.com/cloud-content/us/pdfs/security-intelligence/white-papers/wp__und

erstanding-wmi-malware.pdf• http://www.welivesecurity.com/2013/05/23/syndicasec-in-the-sin-bin/• https://github.com/ytisf/theZoo/tree/master/malwares/Binaries/WMIGhost• https://www2.fireeye.com/rs/848-DID-242/images/rpt-apt29-hammertoss.pdf• http://2014.hackitoergosum.org/slides/day1_WMI_Shell_Andrei_Dumitrescu.pdf• https://msdn.microsoft.com/en-us/library/aa394582(v=vs.85).aspx• https://msdn.microsoft.com/en-us/library/bg126473(v=vs.85).aspx• https://msdn.microsoft.com/en-us/library/aa394554(v=vs.85).aspx• http://blogs.technet.com/b/heyscriptingguy/archive/2012/06/08/an-insider-s-guide-to-using-

wmi-events-and-powershell.aspx• http://www.codeproject.com/Articles/28226/Creating-WMI-Permanent-Event-Subscriptions-

Using-M• http://ytisf.github.io/theZoo/• https://dl.mandiant.com/EE/library/MIRcon2014/

MIRcon_2014_IR_Track_There's_Something_About_WMI.pdf•

Page 34: WMI - A FRONT DOOR FOR MALWARES