Windows Internals
Understanding Windows internals is crucial for malware analysis, as it provides insight into system operations and helps identify malware behavior.
Windows Operating Modes
User Mode: Limited access; applications interact with the OS via APIs. Malware in user mode can manipulate files, registry settings, and attempt privilege escalation.
Kernel Mode: High privilege; unrestricted access to hardware and system functions. Kernel-mode malware can alter system behavior, intercept calls, and conceal itself.
Windows Architecture Overview
User-Mode Components
System Support Processes: Essential system processes like
winlogon.exe,smss.exe, andservices.exe.Service Processes: Background services, e.g., Windows Update and Task Scheduler.
User Applications: Standard applications use APIs routed via
NTDLL.DLLfor kernel interaction.Environment Subsystems: Provides environments for specific processes (e.g., Win32, POSIX).
Subsystem DLLs: Maps documented functions to native calls (e.g.,
kernelbase.dll,user32.dll).
Kernel-Mode Components
Executive: Manages OS aspects like I/O, object, security, and processes.
Kernel: Handles low-level functions like scheduling and synchronization.
Device Drivers: Enables hardware interaction.
Hardware Abstraction Layer (HAL): Standardizes hardware communication.
Win32k.sys: Manages the GUI and visual rendering.
Windows API Call Flow
Malware often uses Windows API calls to interact with system components for malicious tasks. Understanding API flow is key for detecting malware actions.
Example:
ReadProcessMemoryAPI, which allows reading other processes' memory.Call Flow: The function call goes from
kernel32.dll->NTDLL.DLL->NtReadVirtualMemory-> kernel syscall.The System Service Descriptor Table (SSDT) manages system service routines, mapping system calls to kernel functions.
The kernel validates access and performs the read, then transitions back to user mode with the requested data.
Portable Executable (PE) Format
Windows uses the PE format for executables, DLLs, etc. Knowledge of PE structure is essential for analyzing executables, identifying malicious code, and extracting IOCs.
Common PE Sections
.text: Executable code.
.data: Initialized global/static variables.
.rdata: Read-only data like constants and strings.
.pdata: Exception handling data.
.bss: Uninitialized data.
.rsrc: Embedded resources (icons, images).
.idata: Imported functions.
.edata: Exported functions.
.reloc: Relocation data for loading.
Analyzing PE sections reveals information about the code structure, imports, exports, and embedded resources.
Processes
A process represents an executing program with various system resources:
PID: Unique identifier for tracking.
Virtual Address Space: Memory space for code, data, stack, etc.
Executable Code: Instructions and resources on disk.
Handles Table: References for resources like files, devices.
Security Context: Access rights through tokens.
Threads: Units of execution within the process.
Understanding these helps track malware behavior, resource access, and memory management.
Dynamic-Link Library (DLL)
DLLs contain reusable functions and resources used by applications and malware alike. Malware may exploit DLL imports and exports for executing malicious actions.
Import Functions
Functions from external libraries, linked at runtime, facilitate system interactions.
Example of Malware Injection: Functions like
OpenProcess,VirtualAllocEx,WriteProcessMemory, andCreateRemoteThreadare used for injecting code into another process.
Export Functions
Functions that DLLs provide for other applications, acting as an interface for interaction.
Example:
Kernel32.dllexports, viewed via tools like CFF Explorer or x64dbg, provide insights into OS-level functions available to processes.
Last updated