UNIT 4 Malware Functionality
UNIT 4 Malware Functionality
Malware can include viruses, trojans, adware, spyware, botnets, worms, rootkits, and
ransomware. The goals of a particular malware sample determine how it works. For
example, malware designed to serve unwanted advertisements to users works very
differently from ransomware, which encrypts files on infected systems.
Viruses: Viruses are among the oldest forms of malware and operate by infecting files or
programs. They attach themselves to executable files and replicate when the infected file is
executed. Viruses can cause various types of damage, including corrupting files, deleting
data, or spreading to other systems via infected files or removable media like USB drives.
Worms: Unlike viruses, worms can spread independently without needing to attach
themselves to files. They exploit vulnerabilities in network protocols or software to
propagate across networks and infect other devices. Worms can rapidly replicate and
consume network bandwidth, leading to congestion and slowdowns. They are notorious for
their ability to self-propagate, making them a significant threat to interconnected systems
and large-scale networks.
Trojans: Trojans are named after the Trojan horse from Greek mythology, as they disguise
themselves as legitimate software to deceive users. Once a Trojan is executed, it can
perform a variety of malicious actions, such as creating backdoors for remote access,
stealing sensitive information like login credentials or financial data, or installing additional
malware components. Trojans are commonly distributed through phishing emails, fake
software downloads, or compromised websites.
Ransomware: Ransomware has gained prominence in recent years due to its devastating
impact on individuals and organizations. It encrypts files on a victim's system using strong
cryptographic algorithms, rendering the data inaccessible. Attackers then demand a ransom
payment, usually in cryptocurrency, in exchange for a decryption key. Ransomware can
spread rapidly across networks and has targeted various sectors, including healthcare,
finance, and government, causing significant financial losses and operational disruptions.
Spyware: Spyware is designed to covertly monitor and gather information about a user's
activities without their knowledge or consent. It can capture keystrokes, record browsing
habits, take screenshots, and access sensitive data stored on the infected device. The stolen
information is often used for identity theft, espionage, or targeted advertising. Spyware can
enter systems through malicious downloads, deceptive advertisements, or bundled with
legitimate software.
Rootkits: Rootkits are stealthy malware designed to conceal their presence and activities on
an infected system. They operate at a low level of the operating system, intercepting system
calls and manipulating data to evade detection by security software. Rootkits can provide
attackers with privileged access to the system, allowing them to control the system
remotely, steal sensitive information, or launch further attacks. Removing rootkits often
requires specialized tools and expertise due to their sophisticated nature.
Keyloggers: Keyloggers are designed to capture and record keystrokes typed by users,
including usernames, passwords, credit card numbers, and other sensitive information. They
can operate at the system level, capturing keystrokes before they are encrypted or
processed by applications. Keyloggers can be deployed through infected email attachments,
malicious downloads, or compromised websites, posing a significant risk to user privacy and
security.
Fileless Malware: Fileless malware operates in system memory without leaving traces on
disk, making it challenging to detect and analyze using traditional antivirus solutions. Fileless
techniques leverage legitimate system tools and processes to execute malicious actions,
such as PowerShell scripts, Windows Management Instrumentation (WMI), or memory
injection techniques. This type of malware can evade signature-based detection and
requires advanced security measures, such as behavioral analysis and endpoint detection
and response (EDR) solutions, to detect and mitigate effectively.
Downloader
A downloader, in the context of malware functionality, refers to a type of malicious
software component whose primary purpose is to download and install additional malware
or payloads onto a compromised system. Downloaders are often used as a first-stage
infection vector, allowing attackers to gain initial access to a system and then deploy more
advanced malware for various malicious activities.
Initial Compromise: Downloaders are typically part of a multi-stage attack strategy. The
initial compromise may occur through various means such as phishing emails, malicious
links, exploit kits, or compromised websites. Once a system is compromised, the
downloader component is executed, either automatically or by user interaction, initiating
the download and installation of additional malicious payloads.
Stealth and Persistence: Downloaders are designed to operate stealthily to avoid detection
by security measures such as antivirus software or intrusion detection systems (IDS). They
may use obfuscation techniques, encryption, or polymorphism to conceal their malicious
intent and evade detection. Additionally, downloaders may establish persistence
mechanisms to ensure that the downloaded malware remains active and can survive system
reboots or security scans.
Payload Execution and Installation: Once the downloader retrieves the malicious payload
from the C&C server, it executes the payload on the compromised system. This can involve
dropping and executing an executable file, injecting code into legitimate processes,
modifying system settings, creating registry entries, or downloading and executing
additional components. The installed malware then carries out its specific malicious
activities based on the attacker's objectives.
Post-Exploitation Activities: In addition to downloading and installing malware, some
downloaders may perform post-exploitation activities such as privilege escalation, lateral
movement within the network, data exfiltration, or tampering with security settings to
maintain persistence and evade detection. These activities are aimed at achieving the
attacker's goals, whether they involve stealing sensitive data, conducting reconnaissance, or
preparing the compromised system for further attacks.
Backdoor
Backdoors in malware functionality are covert methods or mechanisms used by malicious
software (malware) to create unauthorized access points in compromised systems,
networks, or applications. These backdoors serve as hidden entry points that allow attackers
to bypass normal security controls, gain unauthorized access, and execute malicious
activities without being detected. Let's delve into the specifics of backdoors in malware
functionality:
Creation and Insertion: Malware authors intentionally design and insert backdoors into
their malicious software to provide persistent access and control over compromised
systems. These backdoors can be implemented in various ways, such as creating hidden user
accounts, installing remote access tools (RATs), adding malicious scripts or code snippets, or
exploiting vulnerabilities in software or systems.
Insider Threats: In some cases, insiders with privileged access may intentionally or
unintentionally introduce backdoors into systems or networks. This insider threat could be
malicious insiders seeking to harm the organization or negligent employees falling victim to
social engineering attacks.
Network Monitoring: Employ network intrusion detection systems (IDS) and traffic analysis
tools to detect suspicious communication patterns or connections to known malicious
domains/IP addresses associated with backdoors.
Endpoint Security: Use endpoint detection and response (EDR) solutions to monitor system
activity, detect unauthorized changes, and identify malicious processes or behaviors
indicative of backdoor presence.
Regular Security Updates: Keep software, operating systems, and firmware up to date with
the latest security patches to mitigate vulnerabilities that could be exploited to implant
backdoors.
Access Controls: Implement strong access controls, least privilege principles, and
multifactor authentication (MFA) to limit unauthorized access and prevent backdoor
exploitation.
User Education: Educate users about cybersecurity best practices, phishing threats, and the
importance of avoiding suspicious downloads or email attachments to reduce the risk of
backdoor infections.
Credential Stealers
Credential stealers, also known as password stealers or credential harvesting malware, are
a type of malicious software designed to covertly capture sensitive login credentials,
authentication tokens, and other authentication information from compromised systems.
These credentials are typically used by attackers to gain unauthorized access to online
accounts, financial information, email accounts, and other valuable resources. Here's a
detailed exploration of credential stealers in malware functionality:
Keylogging: Recording keystrokes entered by the user, including usernames, passwords, and
other sensitive information.
Clipboard Hijacking: Monitoring and capturing data copied to the clipboard, which may
include passwords or other credentials.
Browser Credential Theft: Extracting stored passwords and login tokens from web browsers'
password managers or cookies.
Persistence mechanisms
Registry Persistence:
Run Key: Malware can create entries in the Windows Registry under the "Run" or
"RunOnce" keys. These keys specify programs or scripts to run automatically when the
system boots or when a user logs in.
Service Registration: Malware may register itself as a Windows service, allowing it to start
automatically with system boot and run in the background without user interaction.
Startup Folder:
Startup Folder Shortcut: Malware can place a shortcut or executable file in the Startup
folder of the Start menu. When the user logs in, the shortcut or executable is executed
automatically.
Scheduled Tasks:
Task Scheduler: Malware can create scheduled tasks using the Windows Task Scheduler.
These tasks can be set to run at specific times, intervals, or triggers, ensuring persistence
and stealthy execution.
Bootkit and Rootkit Techniques:
Boot Sector Modification: Bootkits modify the master boot record (MBR) or boot sector of
the hard drive to execute malicious code during the boot process, ensuring that the
malware runs before the operating system.
Kernel-Level Hooks: Rootkits insert hooks into the kernel of the operating system,
intercepting system calls and API functions to hide the presence of malware and maintain
persistence.
File System Persistence:
Hidden Files and Directories: Malware can create hidden files or directories in system
folders (e.g., System32) to evade detection and maintain persistence.
Alternate Data Streams (ADS): ADS allows malware to hide data within legitimate files
without altering their size or appearance, providing a stealthy persistence mechanism.
Autostart Services:
Browser Extensions/Plugins: Malware can install malicious browser extensions or plugins
that run automatically when the browser starts, enabling persistent behavior and data
collection.
System Services: Malware may create autostart services that run in the background,
providing continuous access and control over the compromised system.
Fileless Execution:
Memory-Based Execution: Malware can execute directly from memory without leaving
traces on disk. This technique leverages scripting languages (e.g., PowerShell, JavaScript) or
memory injection to load and execute malicious code in the system's memory space,
avoiding detection by traditional file-based antivirus solutions.
Living-off-the-Land Binaries (LOLBins): Malware may abuse legitimate system tools and
binaries, such as PowerShell, Windows Management Instrumentation (WMI), or Windows
Script Host (WSH), to execute malicious commands or scripts without needing to drop
executable files on disk.
File-Based Execution:
Executable Droppers: Launchers can use executable droppers or downloaders to deliver and
execute malware payloads on the compromised system. These droppers often masquerade
as legitimate files or software updates to trick users into running them.
Trojanized Documents: Malware can be embedded within document files (e.g., Word
documents, PDFs) using macros, exploits, or embedded scripts. When the user opens the
document, the malware is launched and executed.
Exploit Kits:
Drive-By Downloads: Malware can exploit vulnerabilities in web browsers, plugins, or
operating systems to silently download and execute malicious payloads when a user visits a
compromised or malicious website. This method requires no user interaction and can occur
in the background without the user's knowledge.
Malvertising: Malware may be distributed via malicious advertisements (malvertising)
displayed on legitimate websites. Clicking on these ads or visiting compromised web pages
can trigger the execution of malware.
Social Engineering:
Phishing Attacks: Malware launchers are often distributed through phishing emails that trick
users into clicking on malicious links, downloading infected attachments, or visiting fake
login pages. Once clicked or opened, the malware is executed, initiating the infection
process.
Fake Software Updates: Malware may masquerade as legitimate software updates or
security patches, prompting users to download and install them. In reality, these updates
contain malicious code that launches the malware upon installation.
Remote Execution:
Remote Code Execution (RCE): Attackers can exploit vulnerabilities in network services,
protocols, or applications to remotely execute malicious commands or scripts on targeted
systems. This can be achieved through exploitation of buffer overflows, SQL injection, or
other security weaknesses.
Command-and-Control (C&C) Communication: Malware may receive commands from
remote C&C servers to execute specific actions or download additional payloads, allowing
attackers to remotely control and launch malicious activities on compromised systems.
Steganography:
Hidden Payloads: Malware launchers may hide malicious code or payloads within seemingly
innocuous files, images, or documents using steganography techniques. These hidden
payloads can be extracted and executed by the launcher without raising suspicion.
Anti-AV and Anti-Analysis Techniques:
Code Obfuscation: Malware launchers obfuscate their code to evade detection by antivirus
(AV) software and static analysis tools. This includes using encryption, packing, or
polymorphic techniques to modify the malware's appearance and behavior dynamically.
Dynamic Analysis Evasion: Malware may incorporate techniques to detect and evade
sandbox environments or virtualized analysis systems, delaying or altering their malicious
behavior until deployed in a real-world environment.
Process Injection
Process injection is a technique used by malware to inject malicious code or payloads into
legitimate processes running on a compromised system. This method allows malware to
execute its malicious activities within the context of trusted processes, evading detection by
security mechanisms and increasing its chances of persistence and stealth. Here's an in-
depth look at process injection in malware functionality:
Objective:
The primary objective of process injection is to execute malicious code or payloads within
the memory space of a legitimate process.
By injecting into trusted processes, malware can avoid raising suspicion, bypass security
controls, and blend in with normal system activities.
Common Techniques:
DLL Injection: Malware injects a dynamic link library (DLL) into the address space of a target
process. This injected DLL contains malicious code that is executed within the context of the
target process.
Code Injection: Malware directly injects executable code into the memory space of a target
process, bypassing the need for a separate DLL. This code can perform various malicious
actions, such as data theft, system manipulation, or network communication.
Thread Injection: Malware creates a new thread within a target process and injects
malicious code into that thread's execution context. This allows the malware to execute
concurrently with the legitimate process without raising suspicion.
Advantages:
Stealth and Evasion: Process injection helps malware evade detection by antivirus software
and intrusion detection systems (IDS) because the malicious code executes within legitimate
processes, making it harder to distinguish from normal behavior.
Persistence: Injected malware can maintain persistence by injecting into processes that start
automatically with system boot or user login, ensuring that the malicious activities continue
even after system reboots.
Privilege Escalation: Process injection can be used to escalate privileges by injecting code
into processes running with higher privileges than the malware itself.
Process Replacement
Process replacement is a technique employed by malware to replace a legitimate process
with malicious code or a malicious executable. This method allows the malware to execute
its malicious activities under the guise of a trusted process, making detection and analysis
more challenging. Here's a detailed look at process replacement in malware functionality:
Objective:
The primary objective of process replacement is to replace a legitimate process running on
the system with malicious code or a malicious executable file.
By replacing trusted processes, malware can execute its malicious activities without raising
suspicion or triggering security alerts.
Common Techniques:
Executable Replacement: Malware replaces the executable file of a legitimate process with
its malicious executable. When the legitimate process is launched, it inadvertently executes
the malicious code instead.
Memory Patching: Malware modifies the memory of a running process to inject and execute
malicious code. This can involve injecting code directly into the process's memory space or
modifying existing code to redirect execution flow to the malicious code.
Process Hollowing: Malware creates a new suspended instance of a legitimate process,
replaces its memory contents with malicious code, and resumes execution. This technique
leaves the original process intact but executes the malicious code within the context of the
replaced process.
Advantages:
Stealth and Evasion: Process replacement allows malware to operate stealthily by leveraging
trusted processes. This makes it harder for security tools to detect and analyze malicious
activities.
Persistence: Replaced processes can be configured to start automatically with system boot
or user login, ensuring that the malware remains active and persistent on the compromised
system.
Privilege Escalation: Malware can execute within processes running with higher privileges,
potentially allowing it to escalate privileges and gain deeper access to the system.
Techniques and Variants:
Image File Execution Options (IFEO) Injection: Malware leverages the Windows IFEO registry
key to replace the executable of a target process with a malicious executable. This
technique is often used in conjunction with debuggers or other tools to trigger the
replacement.
Hooking: Malware uses hooking techniques, such as API hooking or function hooking, to
intercept and modify the behavior of legitimate processes, effectively replacing their
functionality with malicious actions.
AppInit_DLLs Injection: Malware injects a malicious dynamic link library (DLL) into processes
by modifying the AppInit_DLLs registry key. When processes start, they inadvertently load
and execute the injected DLL, allowing the malware to run within their context.
Detection and Mitigation:
Behavior Monitoring: Implement behavior-based detection mechanisms that monitor for
suspicious process behavior, such as unexpected code modifications, memory injections, or
abnormal process activity.
Memory Integrity Checks: Use memory integrity tools that detect unauthorized
modifications to process memory, such as integrity checks on process images and
executable files.
Application Whitelisting: Use application whitelisting to allow only trusted processes and
binaries to run, preventing unauthorized replacements and executions of malicious code.
Endpoint Detection and Response (EDR): Deploy EDR solutions that provide visibility into
process activity, memory modifications, and code injection techniques used in process
replacement attacks.
Access Controls: Implement strict access controls and least privilege principles to limit the
ability of malware to replace processes or modify system files.
Hook Injection
Hook injection, also known as API hooking, is a technique used by malware to intercept and
modify the behavior of legitimate functions or APIs (Application Programming Interfaces) in
software applications or the operating system. This method allows malware to control and
manipulate the flow of execution, capture sensitive information, bypass security
mechanisms, and execute malicious actions. Here's an in-depth look at hook injection in
malware functionality:
The primary objective of hook injection is to intercept and modify the behavior of functions
or APIs called by legitimate applications or the operating system.
By hooking into these functions, malware can redirect execution flow, capture data,
manipulate system calls, or inject malicious code into running processes.
Inline Hooking: Malware modifies the beginning of a function's code in memory to redirect
execution to a malicious code stub before or after executing the original function. This
technique is known as inline hooking.
Import Address Table (IAT) Hooking: Malware modifies the Import Address Table of a
process to redirect calls to legitimate APIs to malicious functions or code snippets. This
technique is often used for intercepting system calls and API functions.
Function Pointer Hooking: Malware intercepts and modifies function pointers, often found
in object-oriented programming or callback mechanisms, to redirect program flow and
execute malicious code.
Stealth and Evasion: Hook injection allows malware to operate stealthily by intercepting
and modifying function calls without altering the original code or executable files. This
makes it harder for security tools to detect malicious activities.
Data Capture: Malware can capture sensitive information, such as passwords, keystrokes,
network traffic, or system events, by intercepting function calls related to data processing or
communication.
Privilege Escalation: Hook injection can be used to escalate privileges by intercepting and
modifying system calls related to access control, process management, or security
mechanisms.
Inline vs. Detour Hooks: Inline hooks modify the original function code directly, while detour
hooks redirect execution to a separate code segment containing the malicious behavior.
Detour hooks are often used for more complex hooking scenarios and to avoid detection by
integrity checks.
Detours and Asynchronous Procedure Call (APC) injection are techniques used in software
manipulation, often for malicious purposes like malware injection or modifying application
behavior:
Detours:
Objective: Detours involve redirecting the execution flow of a program by intercepting and
redirecting function calls to custom code. Malware uses detours to inject malicious
functionality into processes without modifying the original code.
Techniques:
Inline Detours: Malware modifies the code of a target function directly in memory to
redirect execution to a custom code segment before or after executing the original function.
Import Address Table (IAT) Detours: Malware modifies the Import Address Table of a
process to redirect calls to legitimate APIs or functions to custom code, allowing it to
intercept and modify system calls or application behavior.
Advantages:
Stealth: Detours allow malware to operate stealthily by intercepting and modifying function
calls without altering the original code or executable files, making it harder for security tools
to detect malicious activities.
Custom Behavior: Malware can introduce custom behavior, such as data capture,
manipulation, or injection, by intercepting and redirecting specific function calls.
Detection and Mitigation:
Behavior-based detection mechanisms can monitor for suspicious detouring behavior, such
as unexpected function redirection or code modifications.
Memory integrity checks can detect unauthorized modifications to process memory, such as
changes to function pointers or code segments.
APC Injection (Asynchronous Procedure Call Injection):
Objective: APC injection involves injecting custom code or payloads into the address space
of a target process using Asynchronous Procedure Calls (APCs). Malware uses APC injection
to execute malicious code within the context of a legitimate process.
Techniques:
QueueUserAPC: Malware leverages the QueueUserAPC function in Windows to queue an
APC to a target thread within a process. The queued APC is then executed within the
context of the target thread.
APC Queuing: Malware can inject custom APCs into the APC queue of a target process,
causing the malicious code to execute asynchronously when the target thread processes
APCs.
Advantages:
Execution Context: APC injection allows malware to execute code within the context of a
trusted process, making it harder to detect and analyze by security tools.
Persistence: Injected APCs can persist and execute even after system reboots or process
terminations, ensuring the longevity of malicious activities.
Detection and Mitigation:
Behavior monitoring and anomaly detection can detect abnormal APC behavior, such as
unexpected APC injections or unusual thread activity.
Memory monitoring and integrity checks can identify unauthorized modifications to process
memory, including changes related to APC queueing and execution.
Combination and Sophistication:
Malware often combines detours, APC injection, and other advanced techniques to achieve
sophisticated functionality and evade detection.
These techniques may be used in conjunction with rootkit features, code obfuscation, and
anti-analysis measures to enhance stealth and resilience against security measures.