Windows Malware Techniques

56
Windows Malware Techniques Lee Christensen @tifkin_

Transcript of Windows Malware Techniques

Page 1: Windows Malware Techniques

Windows Malware Techniques

Lee Christensen@tifkin_

Page 2: Windows Malware Techniques

C:\> whoami

Page 3: Windows Malware Techniques

PS C:\> ls env:\

Page 4: Windows Malware Techniques

Where are we going?• Windows user-land malware development and design• Techniques for Windows environments• Detection techniques• I probably will forget to mention some of these….

• Not focusing on • Kernel malware/rootkits, anti-forensics, AV-evasion

Page 5: Windows Malware Techniques

Why discuss malware development and design?

Page 6: Windows Malware Techniques

Malware Dev: Defensive Perspective• Understanding the code helps you design your defenses• Malware development has its own pyramid of pain

Page 7: Windows Malware Techniques
Page 8: Windows Malware Techniques

Defensive Perspective• Understanding the code helps you design your defense• Malware development has its own pyramid of pain• Gives insight into the future

Page 9: Windows Malware Techniques

Malware Dev: Offensive Perspective• Understanding of tools• Gives you control - easy to adapt• Offensive in Depth• Writing malware is fun!

Page 10: Windows Malware Techniques
Page 11: Windows Malware Techniques

A remote administration tool (RAT) is a piece of software that allows a remote "operator" to control a

system as if he has physical access to that system.

Page 12: Windows Malware Techniques

A Good RAT• <REMOVED>

Page 13: Windows Malware Techniques

Memory Residency and Modular Design

Page 14: Windows Malware Techniques

Approaches to Modularity• <REMOVED>

Page 15: Windows Malware Techniques

DLL injection• <REMOVED>

Page 16: Windows Malware Techniques

LoadLibrary• <REMOVED>

Page 17: Windows Malware Techniques

LoadLibrary demo

Page 18: Windows Malware Techniques

Reflective DLL injection• <REMOVED>

Page 19: Windows Malware Techniques

Reflective DLL demo

Page 20: Windows Malware Techniques

Modular Malware Demo

Page 21: Windows Malware Techniques
Page 22: Windows Malware Techniques

Beaconing Malware

Page 23: Windows Malware Techniques

Windows API HTTP Cheatsheet• <REMOVED>

Page 24: Windows Malware Techniques

WinInet Example

Page 25: Windows Malware Techniques

DNS• Why DNS?• Not montitored as often• Routed through a trusted host• Great for low and slow

• Size considerations• TXT records (255 bytes max)• A records (4 bytes max)

Page 26: Windows Malware Techniques

Defensive Interjection!• What can we do to detect poorly designed HTTP-based malware?

• How about DNS malware?

• Not all comms are beaconing

Page 27: Windows Malware Techniques

Internal Pivoting and Comms• Goals• Get remote execution• Blend in• Limit egress hosts

Page 28: Windows Malware Techniques

Execution

Page 29: Windows Malware Techniques

Pass the hash• Pass the hash• Toolkit• Windows Credential Editor• Metasploit• SMBExec• psexec

Page 30: Windows Malware Techniques

Oldies but Goodies:Living Off The Land

Page 31: Windows Malware Techniques

At.exe

net use \\<ip>\c$ /user:<username> <password>

at \\<ip> <time> c:\users\\<user>\appdata\local\microsoft\backdoor.exe

Page 32: Windows Malware Techniques

Schtasks.exe

schtasks /create /s <ip> /u <user> /p <password> /ru <runasuser> /tr c:\backdoor.exe /tn run /sc once /st <starttime>

Page 33: Windows Malware Techniques

Wmic.exe

wmic /node:<ip> /user:<user> /password:<password> process call create c:\backdoor.exe

Page 34: Windows Malware Techniques

Other ways…• RDP• VNC• PowerShell Remoting

Page 35: Windows Malware Techniques

Internal Comm Channels

Page 36: Windows Malware Techniques

Named Pipe

A named pipe is a named, one-way or duplex pipe for communication between the pipe server and one or more pipe

clients. All instances of a named pipe share the same pipe name, but each instance has its own buffers and handles.

Page 37: Windows Malware Techniques

Named Pipe• <REMOVED>

Page 38: Windows Malware Techniques

Create a null SECURITY_DESCRIPTOR

<REMOVED>

Page 39: Windows Malware Techniques

Mail Slots• <REMOVED>

Page 40: Windows Malware Techniques

Named Pipes Demo

Page 41: Windows Malware Techniques

Attacking Active Directory

Page 42: Windows Malware Techniques

Detecting/Preventing Local Password Theft• Install KB2871997• Removes all plaintext creds from lsass except WDigest

• http://blogs.technet.com/b/srd/archive/2014/06/05/an-overview-of-kb2871997.aspx• Add admin accounts to "Protected Users" AD group

• Kerberos authentication only• No account delegation (can't steal tokens)• AES for pre-authentication process

• Restricted Admin mode for RDP• Plaintext password never sent to server• Network logons on (prevents token stealing)

Page 43: Windows Malware Techniques

Preventing Local Password Theft - cont• LSASS Protected Process (Windows 8.1/2012 R2 and above)• https://technet.microsoft.com/en-us/library/Dn408187.aspx• Can be bypassed by via a driver

• Honey tokens• Idea by Mark Baggett• https://github.com/SMAPPER/MimikatzHoneyToken• Alert on usage

Page 44: Windows Malware Techniques

Pass the hash Protections• KB2871997• Adds GPO to disable remote network logons from local accounts

• Local Adminstrator Password Solution (LAPS)• Restrict inter-machine communications

Page 45: Windows Malware Techniques

Dumping the Domain’s Hashes

Page 46: Windows Malware Techniques

Old School – Code Execution on DCDump them from LSASS (Traditional hashdump)lsadump::lsa /injectlsadump::lsa /patch /name:krbtgt

Meterpreterpost/windows/gather/credentials/domain_hashdump• Parses the ESE Database using the built-in JetAPI

Ntds.ditInvoke-NinjaCopyPowerForensics (@jaredatkinson)Shadow copiesNtdsutil

Page 47: Windows Malware Techniques

Detection• Acesss to ntds.dit == Domain wide access• Who has admin rights on DC's?

• Restrict logon rights of admin accounts (they don't need to be able to logon everywhere)• Who has admin rights on admin PC’s? • Who has access to backups?• Who has access to virtualization infrastructure?

• Shadow Copy events• Sysmon - Injections into lsass.exe, powershell.exe, ntdsutil.exe• Network traffic - ntds.dit is not a small file…

Page 48: Windows Malware Techniques

DCSync – New Hotness for grabbing domain hashesDemo

Page 49: Windows Malware Techniques

DCSync Detection• Follow Sean Metcalf (@PyroTek3)• Unofficial documenter of Mimikatz functionality

• At the moment, enable Auditing of Directory Service Access• https://support.microsoft.com/en-us/kb/232714• Demo

Page 50: Windows Malware Techniques
Page 51: Windows Malware Techniques

Golden Tickets

Page 52: Windows Malware Techniques

Golden Tickets• Event IDs: 4624 (logon), 4672 (admin logon), 4634 (logoff)• Account Domain field is blank (should be DOMAIN)• Account Domain field is FQDN (should be DOMAIN)

Page 53: Windows Malware Techniques

Pay attention to what your tools are doing!!!

Page 54: Windows Malware Techniques

Golden Tickets• Event IDs: 4624 (logon), 4672 (admin logon), 4634 (logoff)• Account Domain field is blank (should be DOMAIN)• Account Domain field is FQDN (should be DOMAIN)• Account Domain field is "eo.oe.kiwi :)"

Page 55: Windows Malware Techniques
Page 56: Windows Malware Techniques