SlideShare a Scribd company logo
Practical Malware Analysis
Ch 11: Malware Behavior
Last revised 11-9-21
Downloaders and Launchers
Downloaders
• Download another piece of malware


– And execute it on the local system


• Commonly use the Windows API
URLDownloadtoFileA, followed by a
call to WinExec
Launchers (aka Loaders)
• Prepares another piece of malware for
covert execution


– Either immediately or later


– Stores malware in unexpected places, such as
the .rsrc section of a PE file
Backdoors
Backdoors
• Provide remote access to victim machine


• The most common type of malware


• Often communicate over HTTP on Port 80


– Network signatures are helpful for detection


• Common capabilities


– Manipulate Registry, enumerate display
windows, create directories, search files, etc.
Reverse Shell
• Infected machine calls out to attacker,
asking for commands to execute
Windows Reverse Shells
• Basic


– Call CreateProcess and manipulate
STARTUPINFO structure


– Create a socket to remote machine


– Then tie socket to standard input, output,
and error for cmd.exe


– CreateProcess runs cmd.exe with its
window suppressed, to hide it
Windows Reverse Shells
• Multithreaded


– Create a socket, two pipes, and two threads


– Look for API calls to CreateThread and
CreatePipe


– One thread for stdin, one for stdout
RATs


(Remote Administration Tools)
• Ex: Poison Ivy
Botnets
• A collection of compromised hosts


– Called bots or zombies
Botnets v. RATs
• Botnet contains many hosts; RATs control
fewer hosts


• All bots are controlled at once; RATs
control victims one by one


• RATs are for targeted attacks; botnets are
used in mass attacks
Credential Stealers
Credential Stealers
• Three types


–Wait for user to log in and steal
credentials


–Dump stored data, such as password
hashes


–Log keystrokes
GINA Interception
• Windows XP's Graphical Identification and
Authentication (GINA)


– Intended to allow third parties to customize
logon process for RFID or smart cards


– Intercepted by malware to steal credentials


• GINA is implemented in msgina.dll


– Loaded by WinLogon executable during logon


• WinLogon also loads third-party customizations
in DLLs loaded between WinLogon and GINA
GINA Registry Key
• HKLMSOFTWAREMicrosoftWindows
NTCurrentVersionWinlogonGinaDLL


• Contains third-party DLLs to be loaded by WinLogon


• Malware adds an extra item here
MITM Attack
• Malicious DLL must export all functions
the real msgina.dll does, to act as a MITM


– More than 15 functions


– Most start with Wl
x

–Good indicator


–Malware DLL exporting a lot of Wlx
functions is probably a GINA interceptor
WlxLoggedOutSAS
• Most exports simply call through to the real
functions in msgina.dll


• At 2, the malware logs the credentials to the
file %SystemRoot%system32driverstcpudp.sys
GINA is Gone
• No longer used in Windows Vista and later


• Replaced by Credential Providers


• Link Ch 11c
Custom Credential Provider Rootkit on
Windows 7
• Two sets of login buttons


• Only steals passwords from second set


• Code is provided to filter out the original set
Hash Dumping
Hash Dumping
• Windows login passwords are stored as LM
or NTLM hashes


– Hashes can be used directly to authenticate
(pass-the-hash attack)


– Or cracked offline to find passwords


• Pwdump and Pass-the-Hash Toolkit


– Free hacking tools that provide hash dumping


– Open-source


– Code re-used in malware


– Modified to bypass antivirus
Pwdump
• Injects a DLL into LSASS (Local Security
Authority Subsystem Service)


– To get hashes from the SAM (Security Account
Manager)


– Injected DLL runs inside another process


– Gets all the privileges of that process


– LSASS is a common target


• High privileges


• Access to many useful API functions
Pwdump
• Injects lsaext.dll into lsass.exe


– Calls GetHash, an export of lsaext.dll


– Hash extraction uses undocumented Windows
function calls


• Attackers may change the name of the
GetHash function
Pwdump Variant
• Uses these libraries


– samsrv.dll to access the SAM


– advapi32.dll to access functions not already
imported into lsass.exe


– Several Sam functions


– Hashes extracted by SamIGetPrivateDat
a

– Decrypted with SystemFunction025 and
SystemFunction02
7

• All undocumented functions
CNIT 126 11. Malware Behavior
Pass-the-Hash Toolkit
• Injects a DLL into lsass.exe to get hashes


– Program named whosthere-alt


• Uses different API functions than Pwdump
Ch 11a
Keystroke Logging
• Kernel-Based Keyloggers


– Difficult to detect with user-mode
applications


– Frequently part of a rootkit


– Act as keyboard drivers


– Bypass user-space programs and protections
Keystroke Logging
• User-Space Keyloggers


– Use Windows API


– Implemented with hooking or polling


• Hooking


– Uses SetWindowsHookEx function to notify malware
each time a key is pressed


– Details in next chapter


• Polling


– Uses GetAsyncKeyState & GetForegroundWindow
to constantly poll the state of the keys
Polling Keyloggers
• GetAsyncKeyStat
e

– Identifies whether a key is pressed or
unpressed


• GetForegroundWindo
w

– Identifies the foreground window


– Loops through all keys, then sleeps briefly


– Repeats frequently enough to capture all
keystrokes
CNIT 126 11. Malware Behavior
Identifying Keyloggers in Strings Listings
• Run Strings


• Terms like these will
be visible
Persistence Mechanisms
Three Persistence Mechanisms
1. Registry modifications, such as Run key


• Other important registry entries:


– AppInit_DLLs


– Winlogon Notify


– ScvHost DLLs


2. Trojanizing Binaries


3. DLL Load-Order Hijacking
Registry Modifications
• Run key


– HKEY_LOCAL_MACHINE SOFTWARE
Microsoft Windows CurrentVersion Run


– Many others, as revealed by Autoruns


• ProcMon shows all registry modifications
when running malware (dynamic analysis)


• Can detect all these techniques
Process Monitor
AppInit DLLs
• AppInit_DLLs are loaded into every process
that loads User32.dll


– This registry key contains a space-delimited list
of DLLs


– HKEY_LOCAL_MACHINE SOFTWARE
Microsoft Windows NT CurrentVersion
Windows


– Many processes load them


– Malware often calls DLLMain to check which
process it is in before launching payload
AppInit DLLs Security
• Beginning with Windows Vista,
AppInit_DLLs are disabled by default.


• Beginning with Windows 7, the AppInit_DLL
infrastructure supports code signing.


• Starting with Windows 8, the entire
AppInit_DLL functionality is disabled
when Secure Boot is enabled, regardless of
code signing or registry settings


• From Wikipedia
Winlogon Notify
• Notify value in


– HKEY_LOCAL_MACHINE SOFTWARE
Microsoft Windows


– These DLLs handle winlogon.exe events


– Malware tied to an event like logon, startup,
lock screen, etc.


– It can even launch in Safe Mode
SvcHost DLLs
• Svchost is a generic host process for services
that run as DLLs


• Many instances of Svchost are running at once


• Groups defined at


– HKEY_LOCAL_MACHINE SOFTWARE Microsoft
Windows NT CurrentVersion Svchost


• Services defined at


– HKEY_LOCAL_MACHINE System
CurrentControlSet Services ServiceName
Process Explorer
• Shows many
services running in
one svchost
process


• This is the netsvcs
group
CNIT 126 11. Malware Behavior
ServiceDLL
• All svchost.exe DLL contain a Parameters
key with a ServiceDLL value


– Malware sets ServiceDLL to location of
malicious DLL
Groups
• Malware usually adds itself to an existing
group


– Or overwrites a non-vital service


– Often a rarely used service from the netsvcs
group


• Detect this with dynamic analysis
monitoring the registry


– Or look for service functions like
CreateServiceA in disassembly
Ch 11b
Trojanized System Binaries
• Malware patches bytes of a system binary


• To force the system to execute the malware
the next time the infected binary is loaded


• DLLs are popular targets


• Typically the entry function is modified


• Jumps to code inserted in an empty portion of
the binary


• Then executes DLL normally
CNIT 126 11. Malware Behavior
DLL Load-Order Hijacking
KnownDLLs Registry Key
• Contains a list of specific DLL locations


• Overrides the search order for listed DLLs


• Makes them load faster, and prevents load-
order hijacking


• DLL load-order hijacking can only be used


– On binaries in directories other than System32


– That load DLLs in System32


– That are not protected by KnownDLLs
Example: explorer.exe
• Lives in Windows


• Loads ntshrui.dll from System32


• ntshrui.dll is not a known DLL


• Default search is performed


• A malicious ntshrui.dll in Windows will
be loaded instead
Many Vulnerable DLLs
• Any startup binary not found in System32
is vulnerable


• explorer.exe has about 50 vulnerable DLLs


• Known DLLs are not fully protected,
because


– Many DLLs load other DLLs


– Recursive imports follow the default search
order
DLL Load-Order Hijacking Detector
• Searches for DLLs that appear multiple
times in the file system, in suspicious
folders, and are unsigned


• From SANS (2015) (link Ch 11d)
Privilege Escalation
No User Account Control
• Most users run Windows XP as
Administrator all the time, so no privilege
escalation is needed to become
Administrator


• Metasploit has many privilege escalation
exploits


• DLL load-order hijacking can be used to
escalate privileges
Using SeDebugPrivilege
• Processes run by the user can't do
everything


• Functions like TerminateProcess or
CreateRemoteThread require System
privileges (above Administrator)


• The SeDebugPrivilege privilege was
intended for debugging


• Allows local Administrator accounts to
escalate to System privileges
• 1 obtains an access token
• 2 AdjustTokenPrivileges raises privileges to
System
Covering Its Tracks—


User-Mode Rootkits
User-Mode Rootkits
• Modify internal functionality of the OS


• Hide files, network connections,
processes, etc.


• Kernel-mode rootkits are more powerful


• This section is about User-mode rootkits
IAT (Import Address Table) Hooking
• May modify


– IAT (Import Address Table) or


– EAT (Export Address Table)


• Parts of a PE file


– In a DLL in RAM


– This technique is old and easily detected
IAT Hooking
Inline Hooking
• Overwrites the API function code


• Contained in the imported DLLs


• Changes actual function code, not
pointers


• A more advanced technique than IAT
hooking
Ch 11c

More Related Content

PDF
Practical Malware Analysis: Ch 9: OllyDbg
Sam Bowne
 
PDF
CNIT 126 4: A Crash Course in x86 Disassembly
Sam Bowne
 
PDF
CNIT 126: Ch 2 & 3
Sam Bowne
 
PPT
Practical Malware Analysis: Ch 7: Analyzing Malicious Windows Programs
Sam Bowne
 
PDF
Practical Malware Analysis: Ch 11: Malware Behavior
Sam Bowne
 
PDF
CNIT 126 6: Recognizing C Code Constructs in Assembly
Sam Bowne
 
PPTX
Practical Malware Analysis: Ch 2 Malware Analysis in Virtual Machines & 3: Ba...
Sam Bowne
 
PDF
Practical Malware Analysis: Ch 15: Anti-Disassembly
Sam Bowne
 
Practical Malware Analysis: Ch 9: OllyDbg
Sam Bowne
 
CNIT 126 4: A Crash Course in x86 Disassembly
Sam Bowne
 
CNIT 126: Ch 2 & 3
Sam Bowne
 
Practical Malware Analysis: Ch 7: Analyzing Malicious Windows Programs
Sam Bowne
 
Practical Malware Analysis: Ch 11: Malware Behavior
Sam Bowne
 
CNIT 126 6: Recognizing C Code Constructs in Assembly
Sam Bowne
 
Practical Malware Analysis: Ch 2 Malware Analysis in Virtual Machines & 3: Ba...
Sam Bowne
 
Practical Malware Analysis: Ch 15: Anti-Disassembly
Sam Bowne
 

What's hot (20)

PDF
CNIT 126: 10: Kernel Debugging with WinDbg
Sam Bowne
 
PPTX
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly
Sam Bowne
 
PDF
CNIT 126: Ch 6: Recognizing C Constructs in Assembly
Sam Bowne
 
PDF
Practical Malware Analysis Ch12
Sam Bowne
 
PDF
CNIT 126 8: Debugging
Sam Bowne
 
PPTX
Practical Malware Analysis: Ch 6: Recognizing C Code Constructs in Assembly
Sam Bowne
 
PDF
CNIT 126 Ch 7: Analyzing Malicious Windows Programs
Sam Bowne
 
PDF
Practical Malware Analysis Ch 14: Malware-Focused Network Signatures
Sam Bowne
 
PDF
Practical Malware Analysis Ch13
Sam Bowne
 
PDF
Practical Malware Analysis: Ch 8: Debugging
Sam Bowne
 
PDF
CNIT 126 5: IDA Pro
Sam Bowne
 
PDF
CNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static Techniques
Sam Bowne
 
PDF
CNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic Analysis
Sam Bowne
 
PDF
CNIT 121: 17 Remediation Introduction (Part 1)
Sam Bowne
 
PDF
CNIT 126 9: OllyDbg
Sam Bowne
 
PDF
CNIT 126 12: Covert Malware Launching
Sam Bowne
 
PPTX
Practical Malware Analysis: Ch 5: IDA Pro
Sam Bowne
 
PDF
6 Scope & 7 Live Data Collection
Sam Bowne
 
PPTX
Metasploit
henelpj
 
PPTX
Introduction To Exploitation & Metasploit
Raghav Bisht
 
CNIT 126: 10: Kernel Debugging with WinDbg
Sam Bowne
 
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly
Sam Bowne
 
CNIT 126: Ch 6: Recognizing C Constructs in Assembly
Sam Bowne
 
Practical Malware Analysis Ch12
Sam Bowne
 
CNIT 126 8: Debugging
Sam Bowne
 
Practical Malware Analysis: Ch 6: Recognizing C Code Constructs in Assembly
Sam Bowne
 
CNIT 126 Ch 7: Analyzing Malicious Windows Programs
Sam Bowne
 
Practical Malware Analysis Ch 14: Malware-Focused Network Signatures
Sam Bowne
 
Practical Malware Analysis Ch13
Sam Bowne
 
Practical Malware Analysis: Ch 8: Debugging
Sam Bowne
 
CNIT 126 5: IDA Pro
Sam Bowne
 
CNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static Techniques
Sam Bowne
 
CNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic Analysis
Sam Bowne
 
CNIT 121: 17 Remediation Introduction (Part 1)
Sam Bowne
 
CNIT 126 9: OllyDbg
Sam Bowne
 
CNIT 126 12: Covert Malware Launching
Sam Bowne
 
Practical Malware Analysis: Ch 5: IDA Pro
Sam Bowne
 
6 Scope & 7 Live Data Collection
Sam Bowne
 
Metasploit
henelpj
 
Introduction To Exploitation & Metasploit
Raghav Bisht
 
Ad

Similar to CNIT 126 11. Malware Behavior (20)

PDF
CNIT 126 Ch 11: Malware Behavior
Sam Bowne
 
PDF
CNIT 126 7: Analyzing Malicious Windows Programs
Sam Bowne
 
PDF
Windows Threat Hunting
GIBIN JOHN
 
PDF
CNIT 152: 12b Windows Registry
Sam Bowne
 
PDF
12 Investigating Windows Systems (Part 2 of 3)
Sam Bowne
 
PDF
CNIT 126: 10: Kernel Debugging with WinDbg
Sam Bowne
 
PDF
CNIT 152 12 Investigating Windows Systems (Part 2)
Sam Bowne
 
PDF
CNIT 152: 12 Investigating Windows Systems (Part 2 of 3)
Sam Bowne
 
PDF
CNIT 121: 12 Investigating Windows Systems (Part 3)
Sam Bowne
 
PDF
CNIT 152 12. Investigating Windows Systems (Part 3)
Sam Bowne
 
PDF
unit 2 confinement techniques.pdf
RohitGautam261127
 
PDF
CNIT 121: 12 Investigating Windows Systems (Part 2 of 3)
Sam Bowne
 
PPTX
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
Sam Bowne
 
PPTX
Malware Analysis Techniques &Incident Response.pptx
Gol D Roger
 
PPTX
Ch0 1
TylerDerdun
 
PPTX
Botnets Attacks.pptx
MuhammadRehan856177
 
PDF
Practical Malware Analysis: Ch 10: Kernel Debugging with WinDbg
Sam Bowne
 
PPT
Windows internals
Piyush Jain
 
PDF
Ch 6: The Wild World of Windows
Sam Bowne
 
PDF
CNIT 127 Ch 6: The Wild World of Windows
Sam Bowne
 
CNIT 126 Ch 11: Malware Behavior
Sam Bowne
 
CNIT 126 7: Analyzing Malicious Windows Programs
Sam Bowne
 
Windows Threat Hunting
GIBIN JOHN
 
CNIT 152: 12b Windows Registry
Sam Bowne
 
12 Investigating Windows Systems (Part 2 of 3)
Sam Bowne
 
CNIT 126: 10: Kernel Debugging with WinDbg
Sam Bowne
 
CNIT 152 12 Investigating Windows Systems (Part 2)
Sam Bowne
 
CNIT 152: 12 Investigating Windows Systems (Part 2 of 3)
Sam Bowne
 
CNIT 121: 12 Investigating Windows Systems (Part 3)
Sam Bowne
 
CNIT 152 12. Investigating Windows Systems (Part 3)
Sam Bowne
 
unit 2 confinement techniques.pdf
RohitGautam261127
 
CNIT 121: 12 Investigating Windows Systems (Part 2 of 3)
Sam Bowne
 
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
Sam Bowne
 
Malware Analysis Techniques &Incident Response.pptx
Gol D Roger
 
Botnets Attacks.pptx
MuhammadRehan856177
 
Practical Malware Analysis: Ch 10: Kernel Debugging with WinDbg
Sam Bowne
 
Windows internals
Piyush Jain
 
Ch 6: The Wild World of Windows
Sam Bowne
 
CNIT 127 Ch 6: The Wild World of Windows
Sam Bowne
 
Ad

More from Sam Bowne (20)

PDF
Introduction to the Class & CISSP Certification
Sam Bowne
 
PDF
Cyberwar
Sam Bowne
 
PDF
3: DNS vulnerabilities
Sam Bowne
 
PDF
8. Software Development Security
Sam Bowne
 
PDF
4 Mapping the Application
Sam Bowne
 
PDF
3. Attacking iOS Applications (Part 2)
Sam Bowne
 
PDF
12 Elliptic Curves
Sam Bowne
 
PDF
11. Diffie-Hellman
Sam Bowne
 
PDF
2a Analyzing iOS Apps Part 1
Sam Bowne
 
PDF
9 Writing Secure Android Applications
Sam Bowne
 
PDF
10 RSA
Sam Bowne
 
PDF
12 Investigating Windows Systems (Part 1 of 3
Sam Bowne
 
PDF
9. Hard Problems
Sam Bowne
 
PDF
8 Android Implementation Issues (Part 1)
Sam Bowne
 
PDF
11 Analysis Methodology
Sam Bowne
 
PDF
8. Authenticated Encryption
Sam Bowne
 
PDF
7. Attacking Android Applications (Part 2)
Sam Bowne
 
PDF
7. Attacking Android Applications (Part 1)
Sam Bowne
 
PDF
5. Stream Ciphers
Sam Bowne
 
PDF
4. Block Ciphers
Sam Bowne
 
Introduction to the Class & CISSP Certification
Sam Bowne
 
Cyberwar
Sam Bowne
 
3: DNS vulnerabilities
Sam Bowne
 
8. Software Development Security
Sam Bowne
 
4 Mapping the Application
Sam Bowne
 
3. Attacking iOS Applications (Part 2)
Sam Bowne
 
12 Elliptic Curves
Sam Bowne
 
11. Diffie-Hellman
Sam Bowne
 
2a Analyzing iOS Apps Part 1
Sam Bowne
 
9 Writing Secure Android Applications
Sam Bowne
 
10 RSA
Sam Bowne
 
12 Investigating Windows Systems (Part 1 of 3
Sam Bowne
 
9. Hard Problems
Sam Bowne
 
8 Android Implementation Issues (Part 1)
Sam Bowne
 
11 Analysis Methodology
Sam Bowne
 
8. Authenticated Encryption
Sam Bowne
 
7. Attacking Android Applications (Part 2)
Sam Bowne
 
7. Attacking Android Applications (Part 1)
Sam Bowne
 
5. Stream Ciphers
Sam Bowne
 
4. Block Ciphers
Sam Bowne
 

Recently uploaded (20)

PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PPTX
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Virus sequence retrieval from NCBI database
yamunaK13
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 

CNIT 126 11. Malware Behavior

  • 1. Practical Malware Analysis Ch 11: Malware Behavior Last revised 11-9-21
  • 3. Downloaders • Download another piece of malware – And execute it on the local system • Commonly use the Windows API URLDownloadtoFileA, followed by a call to WinExec
  • 4. Launchers (aka Loaders) • Prepares another piece of malware for covert execution – Either immediately or later – Stores malware in unexpected places, such as the .rsrc section of a PE file
  • 6. Backdoors • Provide remote access to victim machine • The most common type of malware • Often communicate over HTTP on Port 80 – Network signatures are helpful for detection • Common capabilities – Manipulate Registry, enumerate display windows, create directories, search files, etc.
  • 7. Reverse Shell • Infected machine calls out to attacker, asking for commands to execute
  • 8. Windows Reverse Shells • Basic – Call CreateProcess and manipulate STARTUPINFO structure – Create a socket to remote machine – Then tie socket to standard input, output, and error for cmd.exe – CreateProcess runs cmd.exe with its window suppressed, to hide it
  • 9. Windows Reverse Shells • Multithreaded – Create a socket, two pipes, and two threads – Look for API calls to CreateThread and CreatePipe – One thread for stdin, one for stdout
  • 11. Botnets • A collection of compromised hosts – Called bots or zombies
  • 12. Botnets v. RATs • Botnet contains many hosts; RATs control fewer hosts • All bots are controlled at once; RATs control victims one by one • RATs are for targeted attacks; botnets are used in mass attacks
  • 14. Credential Stealers • Three types –Wait for user to log in and steal credentials –Dump stored data, such as password hashes –Log keystrokes
  • 15. GINA Interception • Windows XP's Graphical Identification and Authentication (GINA) – Intended to allow third parties to customize logon process for RFID or smart cards – Intercepted by malware to steal credentials • GINA is implemented in msgina.dll – Loaded by WinLogon executable during logon • WinLogon also loads third-party customizations in DLLs loaded between WinLogon and GINA
  • 16. GINA Registry Key • HKLMSOFTWAREMicrosoftWindows NTCurrentVersionWinlogonGinaDLL • Contains third-party DLLs to be loaded by WinLogon • Malware adds an extra item here
  • 17. MITM Attack • Malicious DLL must export all functions the real msgina.dll does, to act as a MITM – More than 15 functions – Most start with Wl x –Good indicator –Malware DLL exporting a lot of Wlx functions is probably a GINA interceptor
  • 18. WlxLoggedOutSAS • Most exports simply call through to the real functions in msgina.dll • At 2, the malware logs the credentials to the file %SystemRoot%system32driverstcpudp.sys
  • 19. GINA is Gone • No longer used in Windows Vista and later • Replaced by Credential Providers • Link Ch 11c
  • 20. Custom Credential Provider Rootkit on Windows 7 • Two sets of login buttons • Only steals passwords from second set • Code is provided to filter out the original set
  • 22. Hash Dumping • Windows login passwords are stored as LM or NTLM hashes – Hashes can be used directly to authenticate (pass-the-hash attack) – Or cracked offline to find passwords • Pwdump and Pass-the-Hash Toolkit – Free hacking tools that provide hash dumping – Open-source – Code re-used in malware – Modified to bypass antivirus
  • 23. Pwdump • Injects a DLL into LSASS (Local Security Authority Subsystem Service) – To get hashes from the SAM (Security Account Manager) – Injected DLL runs inside another process – Gets all the privileges of that process – LSASS is a common target • High privileges • Access to many useful API functions
  • 24. Pwdump • Injects lsaext.dll into lsass.exe – Calls GetHash, an export of lsaext.dll – Hash extraction uses undocumented Windows function calls • Attackers may change the name of the GetHash function
  • 25. Pwdump Variant • Uses these libraries – samsrv.dll to access the SAM – advapi32.dll to access functions not already imported into lsass.exe – Several Sam functions – Hashes extracted by SamIGetPrivateDat a – Decrypted with SystemFunction025 and SystemFunction02 7 • All undocumented functions
  • 27. Pass-the-Hash Toolkit • Injects a DLL into lsass.exe to get hashes – Program named whosthere-alt • Uses different API functions than Pwdump
  • 29. Keystroke Logging • Kernel-Based Keyloggers – Difficult to detect with user-mode applications – Frequently part of a rootkit – Act as keyboard drivers – Bypass user-space programs and protections
  • 30. Keystroke Logging • User-Space Keyloggers – Use Windows API – Implemented with hooking or polling • Hooking – Uses SetWindowsHookEx function to notify malware each time a key is pressed – Details in next chapter • Polling – Uses GetAsyncKeyState & GetForegroundWindow to constantly poll the state of the keys
  • 31. Polling Keyloggers • GetAsyncKeyStat e – Identifies whether a key is pressed or unpressed • GetForegroundWindo w – Identifies the foreground window – Loops through all keys, then sleeps briefly – Repeats frequently enough to capture all keystrokes
  • 33. Identifying Keyloggers in Strings Listings • Run Strings • Terms like these will be visible
  • 35. Three Persistence Mechanisms 1. Registry modifications, such as Run key • Other important registry entries: – AppInit_DLLs – Winlogon Notify – ScvHost DLLs 2. Trojanizing Binaries 3. DLL Load-Order Hijacking
  • 36. Registry Modifications • Run key – HKEY_LOCAL_MACHINE SOFTWARE Microsoft Windows CurrentVersion Run – Many others, as revealed by Autoruns • ProcMon shows all registry modifications when running malware (dynamic analysis) • Can detect all these techniques
  • 38. AppInit DLLs • AppInit_DLLs are loaded into every process that loads User32.dll – This registry key contains a space-delimited list of DLLs – HKEY_LOCAL_MACHINE SOFTWARE Microsoft Windows NT CurrentVersion Windows – Many processes load them – Malware often calls DLLMain to check which process it is in before launching payload
  • 39. AppInit DLLs Security • Beginning with Windows Vista, AppInit_DLLs are disabled by default. • Beginning with Windows 7, the AppInit_DLL infrastructure supports code signing. • Starting with Windows 8, the entire AppInit_DLL functionality is disabled when Secure Boot is enabled, regardless of code signing or registry settings • From Wikipedia
  • 40. Winlogon Notify • Notify value in – HKEY_LOCAL_MACHINE SOFTWARE Microsoft Windows – These DLLs handle winlogon.exe events – Malware tied to an event like logon, startup, lock screen, etc. – It can even launch in Safe Mode
  • 41. SvcHost DLLs • Svchost is a generic host process for services that run as DLLs • Many instances of Svchost are running at once • Groups defined at – HKEY_LOCAL_MACHINE SOFTWARE Microsoft Windows NT CurrentVersion Svchost • Services defined at – HKEY_LOCAL_MACHINE System CurrentControlSet Services ServiceName
  • 42. Process Explorer • Shows many services running in one svchost process • This is the netsvcs group
  • 44. ServiceDLL • All svchost.exe DLL contain a Parameters key with a ServiceDLL value – Malware sets ServiceDLL to location of malicious DLL
  • 45. Groups • Malware usually adds itself to an existing group – Or overwrites a non-vital service – Often a rarely used service from the netsvcs group • Detect this with dynamic analysis monitoring the registry – Or look for service functions like CreateServiceA in disassembly
  • 47. Trojanized System Binaries • Malware patches bytes of a system binary • To force the system to execute the malware the next time the infected binary is loaded • DLLs are popular targets • Typically the entry function is modified • Jumps to code inserted in an empty portion of the binary • Then executes DLL normally
  • 50. KnownDLLs Registry Key • Contains a list of specific DLL locations • Overrides the search order for listed DLLs • Makes them load faster, and prevents load- order hijacking • DLL load-order hijacking can only be used – On binaries in directories other than System32 – That load DLLs in System32 – That are not protected by KnownDLLs
  • 51. Example: explorer.exe • Lives in Windows • Loads ntshrui.dll from System32 • ntshrui.dll is not a known DLL • Default search is performed • A malicious ntshrui.dll in Windows will be loaded instead
  • 52. Many Vulnerable DLLs • Any startup binary not found in System32 is vulnerable • explorer.exe has about 50 vulnerable DLLs • Known DLLs are not fully protected, because – Many DLLs load other DLLs – Recursive imports follow the default search order
  • 53. DLL Load-Order Hijacking Detector • Searches for DLLs that appear multiple times in the file system, in suspicious folders, and are unsigned • From SANS (2015) (link Ch 11d)
  • 55. No User Account Control • Most users run Windows XP as Administrator all the time, so no privilege escalation is needed to become Administrator • Metasploit has many privilege escalation exploits • DLL load-order hijacking can be used to escalate privileges
  • 56. Using SeDebugPrivilege • Processes run by the user can't do everything • Functions like TerminateProcess or CreateRemoteThread require System privileges (above Administrator) • The SeDebugPrivilege privilege was intended for debugging • Allows local Administrator accounts to escalate to System privileges
  • 57. • 1 obtains an access token
  • 58. • 2 AdjustTokenPrivileges raises privileges to System
  • 60. User-Mode Rootkits • Modify internal functionality of the OS • Hide files, network connections, processes, etc. • Kernel-mode rootkits are more powerful • This section is about User-mode rootkits
  • 61. IAT (Import Address Table) Hooking • May modify – IAT (Import Address Table) or – EAT (Export Address Table) • Parts of a PE file – In a DLL in RAM – This technique is old and easily detected
  • 63. Inline Hooking • Overwrites the API function code • Contained in the imported DLLs • Changes actual function code, not pointers • A more advanced technique than IAT hooking