Docsity

Malware Analysis and Incident Forensics Theory, Appunti di Sistemi Informatici

Toggle sidebar
bg1
October 2017: all 3 billion accounts managed by Yahoo! had probably been compromised in an earlier breach.
•
September 2017: The Equifax data breach exposes extremely sensitive data from >160 million consumers
Hackers exploited a known vulnerability in an unpatched server
○
A 2015 internal audit revealed issues on which Equifax didn’t act effectively
○
•
August 2016:
An hacker group named “Shadow Brokers” sets up an auction for a SW pkg.
○
They claim the pag contains several advanced tools for system penetration
○
○
The auction goes on for a few weeks with no success
What was the real purpose of it?
▪
The SW is released publicly (14/4/17)
▪
Contains executable code for several attacks, a few of which were previously unknown (0-day)
▪
○
The SW structure makes the claim about the source credible
○
•
May 2017: Wannacry spreads infecting thousands of PCs
uses EternalBlue, an exploit leaked from NSA
○
spreads widely, but shows little care in its design
○
Extremely advanced technologies are within easy reach of any criminal with enough budget
○
•
Lockbit
Ransomware-as-a-Service since 2019
○
Third iteration of the software platform
○
Triple extortion tactic
through encryption
1.
threat to publish sensitive data
2.
create pressure using tactics like chasing third parties
3.
○
Business oriented
Bug bounty program
▪
Customer care
▪
○
•
Persistence
Malware installs itself in the system
○
It performs actions to guarantee its survivability to
Reboots
▪
inspections
▪
○
Often modifies OS configuration
○
Changes are hidden
○
•
Introduction
martedì 24 settembre 2024
10:00
Malware Analysis Page 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Anteprima parziale del testo

Scarica Malware Analysis and Incident Forensics Theory e più Appunti in PDF di Sistemi Informatici solo su Docsity!

  • October 2017 : all 3 billion accounts managed by Yahoo! had probably been compromised in an earlier breach.

September 2017 : The Equifax data breach exposes extremely sensitive data from >160 million consumers

○ Hackers exploited a known vulnerability in an unpatched server

○ A 2015 internal audit revealed issues on which Equifax didn’t act effectively

August 2016:

○ An hacker group named “Shadow Brokers” sets up an auction for a SW pkg.

○ They claim the pag contains several advanced tools for system penetration

○ Source: The Equation Group (allegedly tied to NSA)

The auction goes on for a few weeks with no success

▪ What was the real purpose of it?

▪ The SW is released publicly (14/4/17)

▪ Contains executable code for several attacks, a few of which were previously unknown (0-day)

○ The SW structure makes the claim about the source credible

May 2017 : Wannacry spreads infecting thousands of PCs

○ uses EternalBlue, an exploit leaked from NSA

○ spreads widely, but shows little care in its design

○ Extremely advanced technologies are within easy reach of any criminal with enough budget

Lockbit

○ Ransomware-as-a-Service since 2019

○ Third iteration of the software platform

Triple extortion tactic

1. through encryption

2. threat to publish sensitive data

3. create pressure using tactics like chasing third parties

Business oriented

▪ Bug bounty program

▪ Customer care

Persistence

○ Malware installs itself in the system

It performs actions to guarantee its survivability to

▪ Reboots

▪ inspections

○ Often modifies OS configuration

○ Changes are hidden

Introduction

martedì 24 settembre 2024 10:

Uniqueness (“single-instance”)

○ Malware is often incompatible with itself

Multiple concurrent executions are meaningless

▪ Sometimes even dangerous for malware itself

▪ Think about two ransomware instances competing for the same resources

○ Start-up checks guarantee the execution of a single copy

Targeting

○ Malware is sometimes designed to attack specific targets

The sample will check if it landed on the correct target:

▪ Region/language information

▪ HW/SW characteristics of the machine

▪ Presence of specific configuration

▪ External devices

▪ Presence of known documents

Obfuscation & evasion

Malware will try to hide its presence and its effects

▪ It may inject code in other processes to conceal its real identity

▪ It may mangle its internal code to hide easily discoverable hints of its malicious nature

▪ It may leverage techniques to hamper the possibility to correctly analyze its behavior

The typical goal is to stay undercover while acting on the infected machine for as long as possible - > With

exceptions: think about ransomware

Fingerprinting & beaconing

○ Malware will inspect the infected system and collect information about it

○ Information can be used to “publicize” its presence to a remote server

○ This phase is sometimes referred to as “beaconing”

Communication

Malware often interacts with external Command & Control services to

▪ receive instructions and commands

▪ update its internal components

▪ exfiltrate data

Communication may use an impressively heterogeneous set of methodologies

▪ Direct links

▪ Cloud data storage

▪ Social networks

▪ Network services (e.g., DNS)

○ Data on channels is often obfuscated

Advanced static analysis

Reverse-engineering the malware code with a disassembler - > we are interested in the behaviour of the

malware

□ Complex, requires understanding of assembly code and how such code interacts with the OS.

Dynamic Analysis

Run the malware and monitor its effects

○ Use a virtual machine and take snapshots

Most of the time malwares understand if it is run in a controlled environment, so it will stop its execution or it will show

an execution that is completely different from the real one

Tools : RegShot, Process Monitor, Process Hacker, CaptureBAT, debuggers,…

○ RAM Analysis: Mandant Redline and Volatility

There are two types of dynamic analysis

Basic dynamic analysis

□ Easy but requires a safe test environment

□ Not effective on all malware

Advanced Dynamic Analysis

□ Run code in a debugger.

□ Examines internal state of a running malicious executable and how such state evolves.

  • Backdoor: Allows attacker to control the system
  • Botnet: All infected computers receive instructions from the same Command-and-Control (C&C) server

Downloader

○ Malicious code that exists only to download other malicious code

○ Used when attacker first gains access

  • Information-stealing malware: Sniffers, keyloggers, password hash grabbers

Launcher

○ Malicious program used to launch other malicious programs

Often uses non-traditional techniques to ensure stealth or greater access to a system

Rootkit

○ Malware that conceals the existence of other code

Designed to deeply hide in the infected machine to evade detection

▪ User-level

▪ Kernel-level

▪ Bootkits

○ Usually paired with a backdoor or other functionalities

Scareware

○ Frightens user into buying something

○ Ask for Ransom

  • Spam-sending malware: Attacker rents machine to spammers
  • Worms or viruses: Malicious code that can copy itself and infect additional computers

Persistence

○ The malware installs itself in the system

It performs actions to guarantee its survivability to

▪ Reboots

▪ inspections

○ Often modifies the OS configuration

○ Changes are hidden

Malware has to be sure to persist in a machine also after a reboot - > for example it can be executed at boot time, but

also it can be installed in the BIOS od the pc, so that it can survive in a computer also after the factory reset of the

machine

Uniqueness

○ Malware is often incompatible with itself

Multiple concurrent executions are meaningless

▪ Or sometimes dangerous for the malware itself

▪ Think about two ransomware instances competing for the same resources

○ Checks at startup guarantee the execution of a single copy

There cannot be two executions of the same malware on the same machine - > check if it's already running and if it is,

quit

Environment checks / Targeting

○ Malware is designed to work in appropriate environment

Checks at startup if specific execution conditions are met

Checks at startup if specific execution conditions are met

Time/date

□ To avoid easy identification of the malware

□ Some malwares execute only in the weekend or during night time

▪ Localization

▪ Availability of specific resources

▪ Presence of other processes

Obfuscation and evasion

○ Malware will try to hide its presence and its effects to stay undetected as long as possible

It may inject code in other processes to conceal its real identity

○ It may mangle its internal code to hide easily discoverable hints of its malicious nature

○ It may leverage techniques to hamper the possibility to correctly analyse its behaviour

Fingerprinting & beaconing

Malware will inspect the infected system and collect information about it

○ Information can be used to “publicize” its presence to a remote server

Communication

Malware often interacts with external command & control services to

▪ receive instructions and commands

▪ update its internal components

▪ exfiltrate data

○ Communication may use heterogeneous links types

○ Data on channels is often obfuscated

Techniques:

○ Antivirus scanning

○ Hashes

A file’s strings, functions, and headers

An obvious first step

○ Malware can easily change its signature and fool the antivirus

○ VirusTotal is convenient, but using it may alert attackers that they’ve been caught

VirusTotal has the right of storing the virus, so if it contains private information of the enterprise is not so good - >

moreover, you don't want to alert attacker when you caught the malware before it does something to the machine,

since if the malware is on VirusTotal, this means that someone has found it

Search function is really useful, since you can attach the hash of a specific malware, so that you can check if it is a mass

malware or a targeted malware (for phishing emails) - > The search history is not available to other uses, so if the search

is successful this means that someone uploaded the malware on the website (it is probably a mass malware), otherwise

we are the first ones to receive that malware (it is probably a targeted malware)

Hashing

○ MD5 or SHA- 1

Condenses a file of any size down to a fixed-length fingerprint

Uniquely identifies a file

▪ There are MD5 collisions but they are not common

▪ Collision: two different files with the same hash

○ De-facto standard way of uniquely identifying samples

sample vs. malware

Sample: executable file of the malware which due to compilation can be very different from another sample of the

same malware, even if they have the same behavior

▪ Signature/hash is obtained from the sample

▪ Signatures are fragile, since it's easy for an attacker to make them not useful

○ Most operating systems provide md5 as a standard utility

○ If you use Windows you may prefer a GUI-wrapped version

Hash uses

  • What happen when you double click an executable file in Windows?
  • The OS (actually the loader) looks in the file to understand what to do.

What’s in the file?

○ Code

○ Data

○ Other resources

○ Metadata

  • All these information need to be organised to be correctly interpreted by the loader

The Portable Execution (PE) File Format

Used by Windows executable files, object code, and DLLs

▪ Very convenient - > A single file format for several different usage scenarios

Means that you treat EXEs and DLLs in a very similar way

○ A data structure that contains the information necessary to Windows for file loading

○ Almost every file executed on Windows is in PE format

○ Starts with MS-DOS header+stub - > just for compatibility

○ The PE headers contain metadata used to correctly load and execute the file

File content is structured in “sections”

▪ Each section contains a specific kind of data

▪ Section table describes the sections - > it's a table of contents

○ Usually at least two sections are present

The sections that are most commonly present in an executable are:

Executable Code Section , named .text (Microsoft) or CODE (Borland)

Data Sections , named .data , .rdata , or .bss (Microsoft) or DATA (Borland) - > usually if the code is packed, it si not in the

Executable Code Section, but it's in the Data Section

▪ Resources Section , named .rsrc

▪ Export Data Section , named .edata - > functionalities available for other codes

▪ Import Data Section , named .idata - > functionalities available from other codes

Debug Information Section , named .debug

□ Information used by programmers to understand how the code was compiled

□ They are deleted by the compilers, so when we do reverse engineering they are not available anymore

□ They are used for correct mapping between assembly and code, but typically they are not available for malware analysis

The names are actually irrelevant as they are ignored by the OS and are present only for the convenience of the programmer - > Means

you can find very different names (e.g. packers use their names)

DOS Header + Stub

○ The DOS header occupies the first 64 bytes of the file

It's there in case the program is run from DOS, so DOS can recognise it as a valid executable and run the DOS stub ○

○ The DOS stub usually just prints a string like "This program must be run under Microsoft Windows"

○ Example

offset where PE header is going to

start since DOS stub has not a fixed

dimension

Every file that starts

with MZ in Windows

is an executable file

File Execution in Windows

martedì 8 ottobre 2024 10:

  • PE Header

○ Signature + File Header

○ Optional Headers

○ Section Table: One of these (40 bytes) for each section defined in the file

Sections

The size of all headers + section

table. You can also use this value

as the file offset of the first

section in the PE file

Overall size of the PE image

in memory. It's the sum of

all headers and sections

aligned to SectionAlignment.

says to which offset we can find the first section of the

file

There could be sections that are defined in file, but are

empty and they are declared to be larger in memory

since they are used to store data

Example: Services.exe vs Services.ex_ (malware)

Common dlls

Kernel32.dll: This is a very common DLL that contains core functionality, such as access and manipulation of memory, files and

hardware

▪ Advapi32.dll: This DLL provides access to advanced core Windows components such as the Service Manager and Registry

User32.dll: This DLL contains all the user-interface components, such as buttons, scrollbars, and components for controlling and

responding to user actions

▪ Gdi32.dll : This DLL contains functions for displying and manipulating graphics

Ntdll.dll:

□ This DLL is the intergface to the Windows kernel

□ Executables generally do not import this file directly, alothough it is always imported indirectly by Kernel32.dll

If an executable imports this file, it means that the author intended to use functionality not normally available to Windows

programs

□ Some tasks, such as hiding functionality or manipulating processes, will use this interface

Malware are programs that are executed on complex environment that have necessarily to interact with the operating

system to perform its activities, since the OS has a lot of barriers about what a program can actually do on a machine

WSock32.dll and Ws2_32.dll:

□ These are networking DLLs

□ A program that accesses either of these most likely connects to a network or performs network-related tasks

▪ Wininet.dll : This DLL contains higher-level networking functions that implement protocols such as FTP, HTTP and NTP

Examples:

Keylogger

□ Imports User32.dll and uses the function SetWindowsHookEx which is a popular way keyloggers receive keyboard inputs

□ It exports LowLevelKeyboardProc and LowLevelMouseProc to send the data elsewhere

□ It uses RegisterHotKey to define a special keystroke like Ctrl+Shift+P to harvest the collected data

A packed program

□ Very few functions

□ All you see is the unpacker

  • Exports

□ Virtual Size: RAM

□ Size of Raw Data: DISK

□ For .text section, normally equal, or nearly equal

Packed executables show Virtual Size much larger than Size of

Raw Data for .text section

means that the code is

not there, so the code

is compressed and it is

in another memory

location

▪ Imports and Exports

Exports

○ which functions in our program have to be used by another program, so need to be exported to be used by external programs

○ DLLs export functions

○ EXEs import functions

○ Both exports and imports are listed in the PE header

○ Exports should be rare in EXEs (but reality is sometimes different)

Time Date Stamp

○ Shows when this executable was compiled

○ Older programs are more likely to be known to antivirus software

But sometimes the date is wrong

All Delphi programs show June 19, 1992

▪ Date can also be faked

Resource Hacker

○ Lets you browse the .rsrc section

○ Strings, icons, and menus

  • Running malware deliberately, while monitoring the results
  • Requires a safe environment
  • Must prevent malware from spreading to production machines
  • Real machines can be airgapped – no network connection to the Internet or to other machines

Static analysis can reach a dead-end, due to

○ Obfuscation

○ Packing

○ Examiner has exhausted the available static analysis techniques

  • Dynamic analysis will show you exactly what the malware does, but it is not entirely true
  • Main goal: understand the malware behaviour

Approaches:

Diffing

▪ Take a snapshot of a clean system state and a snapshot of a compromised system state

Compare before and after

Used when we capture more or less all artifacts

▪ Pro: Artifacts can be observed easily

▪ Con: Can miss evidence that is created during malware activities and erased purposely by malware

▪ Tools : regshot, autoruns

System Monitoring

From a clean system state, record every individual change on system and network traffic that appear after execution of the

suspicious file

▪ gives information about what a single process does at execution (creation and elimination of the artifacts)

▪ Pro : Can collect all manifested changes

▪ Con: Often too much information and need to weed out irrelevant data

Tools: procmon, Wireshark

API Tracing

▪ Hook and record important API calls made by the suspicious process

is the dynamic counter part of looking on import table in static analysis - > means using a tool that injects in the code that we

want to monitor some hooks, so that when the program is executed and performs the API call, the call is traces and locked

Pros:

□ Provides visibility into activity beyond the typical file/process/registry/network shown by other tools

□ Gets you a little closer to the type of interpretation that is required when doing static analysis.

Cons:

□ Often too much of information and need to weed out irrelevant data

□ API-specific interpretation can take a lot of time, but still less than static analysis

Tools: WinApiOverride, Rohitab API Monitor

Debugging

▪ Set breakpoints inside the suspicious file to stop its execution at a given location and inspect its state

most powerful tool in the toolbox since we can see everything that the malware does and we can change the execution of

the malware at runtime - > used only in the part of the malware that we are not able to understand with simpler tools, since it

requires a lot of time to be performed

▪ Pro: Provides a superset of the functionality of an API monitor

Cons:

□ Typically must be be done in conjunction with some basic static analysis and assembly reading

□ Malware will often change its behavior or refuse to run when being debugged, which requires a work-around.

▪ Tools: IDA Pro Debugger, OllyDbg, Immunity Debugger, WinDbg

Limits you need to be aware of:

○ in general, single path (execution trace) is examined

analysis environment possibly not invisible ○

○ analysis environment possibly not comprehensive

○ scalability issues

  • How do you technically perform it?

○ Classification schemes are hardly coherent

Real Machines

Disadvantage s

▪ No Internet connection, so parts of the malware may not work

▪ Can be difficult to remove malware, so re-imaging the machine will be necessary

○ Advantage: Some malware detects virtual machines and won't run properly in one

Virtual Machines

○ The most common method

This protects the host machine from the malware

▪ VM-escape attacks are theoretically possible

▪ I don’t know about real malware implementing it

“naïf” VM usage is way more dangerous

○ You can easily “snapshot” the VM and revert back to a clean state at the end of each analysis job.

Oracle Virtual Box

Free

▪ Reads/Writes VMware disks

▪ Reasonable performance for the goals of this course

▪ You can take several snapshots and revert back to them if needed

Configuring Virtual Box

□ You can disable networking by disconnecting the virtual network adapter while the VM is running

Host-only networking allows network traffic to the host but not the Internet - > Disconnect the virtual cable, but not

deleting the network

More complex setup are possible

 Use ad-hoc networking to fake external services - > create a vm

that simulates the network

 host-only networking

Snapshots to:

▪ Protect a clean installation of the analysis environment

▪ Keep track of ongoing progresses during analysis

Hop instantly from job to job if you need to analyze several samples at the same time.

Risk of using a VM for Malware Analysis

▪ Malware may detect that it is in a VM and run differently

▪ Virtualization environments may have bugs: malware may crash or exploit it

▪ Malware may spread or affect the host (no real cases to report)

All the textbook samples are harmless

  • Most malware you will typically encounter is Windows based
  • Some old malware may not run without admin privileges
  • Internal safety protections need to be disabled to avoid malware samples to be automatically quarantined/deleted - > gpedit.msc

Launching DLLs

○ EXE files can be run directly, but DLLs can't

Use Rundll32.exe (included in Windows) - > rundll32.exe DLLname, Export arguments ○

○ The Export value is one of the exported functions you found in Dependency Walker, PEview, or PE Explorer.

○ Example: rip.dll has these exports: Install and Uninstall - > rundll32.exe rip.dll, Install

○ Some functions use ordinal values instead of names, like rundll32.exe xyzzy.dll, #

It's also possible to modify the PE header and convert a DLL into an EXE, or install it as a service: rundll32.exe ipr32x.dll,

InstallService ServiceName net start ServiceName

Process Monitor Tool

○ Monitors registry, file system, network, process, and thread activity

○ All recorded events are kept, but you can filter the display to make it easier to find items of interest

○ Don't run it too long or it will fill up all RAM and crash the machine

Filtering With Exclude

▪ One technique: hide normal activity before launching malware

▪ Right-click each Process Name and click Exclude

Most useful filters: Process Name, Operation, and Detail

○ Info on loaded DLLs is available following View - > Lower Pane View - > DLLs

Properties

○ Shows DEP and ASLR status

○ Verify button checks the disk file's Windows signature

○ But not the RAM image, so it won't detect process replacement

Detecting Malicious Documents

○ Open the document (e.g. PDF) on a system with a vulnerable application (e.g. an old version of Adobe Reader)

○ Watch Process Explorer to see if it launches a process

○ The Image tab of that process's Properties sheet will show where the malware is

  • The Registry
    • Services are pink
    • Processes are blue
    • New processes are green briefly
    • Terminated processes are red

Strings: Compare Image to Memory strings, if they are very

different, it can indicate process replacement

File System

Startup locations

□ For the logged-in user: %USERPROFILE%\Start Menu\Programs\Startup

□ For all users: %ALLUSERSPROFILE%\Start Menu\Programs\Startup

DLL search order hijacking

▪ Trojanizing system files

○ Master Boot Record (MBR)

Basic Input/Output System (BIOS) ○

Microsoft Windows Service

▪ Long-running executables without user interaction (like a *nix daemon)

Can be automatically started when the computer boots

▪ CreateService() Windows API is called to register a service

▪ Registered services can be found under the registry key HKLM\System\CurrentControlSet\Services

Svchost

○ C:\Windows\System32\svchost.exe is a generic host process for services that run from DLLs

○ Multiple instances are often running - > One instance contains a group of services

○ Groups are listed in the registry key HKLM\Software\Microsoft\Windows NT\CurrentVersion\Svchost

It is common to have malware name itself svchost.exe but run from somewhere other than C:\Windows\System32, e.g. C:

\Windows

○ Or alternatively they will just add a new DLL for the real svchost to run as a service

Using the tools

○ Procmon: Filter on the malware executable name and clear all events just before running it

○ Process Explorer

○ Regshot

Virtual Network with

ApateDNS (e.g. to redirect DNS Resolutions)

▪ InetSim

○ Monitoring with Ncat (included with Nmap)

○ Wireshark

Can save files from streams here too

□ Fools a Browser □ Fools Nmap

  • If Statements

Loops

○ For

While

○ While

  • Calling conventions: cdecl vs stdcall
    • Push/Mov into the stack
  • Switch