Command Execution (TA0002) Techniques
Introduction
Investigating command execution on a network, particularly in Windows workstations and servers, is crucial to understanding the extent and impact of a security incident. This process involves identifying and analysing the commands that an attacker executes after gaining access.
Understanding Common Command Execution Sources
Command-Line Interface (CLI): Windows Command Prompt, PowerShell, and Unix/Linux terminals.
Scripts: Batch files, PowerShell scripts, VBS scripts, etc.
Scheduled Tasks: Tasks that execute commands at specified times.
Remote Execution Tools: Tools like PsExec or remote desktop applications.
Application Execution: Applications that execute system command
Collecting Data
System Logs: Collect and examine Windows Event Logs, primarily focusing on the Security, System, and Application logs.
Command History: In Windows, check PowerShell and Command Prompt history. PowerShell logs can be found in Event Viewer under "Windows Logs" > "Application and Services Logs" > "Windows PowerShell".
Scheduled Tasks and Startup Programs: Check for any unknown or modified scheduled tasks and startup programs that could execute commands.
Analysing Execution Artifacts
Prefetch Files: Analyse Prefetch files in Windows to identify executed programs.
Registry Analysis: Examine registry keys associated with command execution, like Run, RunOnce, and PowerShell's Transcription logging.
File System Analysis: Check the creation and modification dates of suspicious files.
Shellbags: Analyse shellbags for evidence of command execution via Windows Explorer.
Command-Line Interface (CLI): Windows Command Prompt, PowerShell, and Unix/Linux terminals.
Scripts: Batch files, PowerShell scripts, VBScripts, etc.
Scheduled Tasks: Tasks that execute commands at specified times.
Remote Execution Tools: Tools like PsExec or remote desktop applications.
Application Execution: Applications that execute system command
Memory Forensics
Use tools like Volatility to analyse memory dumps for evidence of recently executed commands or processes.
Network Traffic Analysis
Check for Command & Control Traffic: Analyse network traffic logs for any signs of command and control communication, which might indicate remote execution of commands.
Data Exfiltration: Look for patterns or large data transfers that might indicate data being collected and sent out.
Analysis of Command Execution
Windows Command Line Logs: Windows logs command line activity in Event ID 4688. These logs show the command line process creation events.
PowerShell Logging: Review PowerShell script block logging (Event ID 4104), module logging, and transcription logs for executed commands.
Bash History (for Unix/Linux): Analyse the .bash_history file for executed commands.
Scheduled Tasks Analysis: Investigate the Windows Task Scheduler and cron jobs (for Unix/Linux) for any scheduled tasks running commands.
Remote Execution Tools Logs: Examine logs from tools like PsExec or remote desktop software
User Account and Authentication Logs
Review logs related to user authentication and account usage, particularly focusing on any elevation of privileges or use of administrative accounts.
Correlation and Timeline Analysis
Correlate the gathered data to build a timeline of events, which will help you understand the sequence and scope of the executed commands.
Malware and Script Analysis
If any scripts or malware are found, analyse them to determine their functionality and the commands they execute.
Interviews and Internal Investigations
Talk to relevant personnel who might provide insights into usual and unusual command executions, especially in the case of internal threats.
Reporting and Documentation
Document all findings, methodologies, and evidence in a detailed report for future reference and potential legal proceedings.
Investigating command execution requires a thorough analysis of various data sources, including system logs, memory, and network traffic. Each step, from data collection to detailed analysis and reporting, is crucial in understanding the scope and impact of the executed commands. Maintaining an updated knowledge of forensic tools and techniques is essential for effective investigation in the ever-evolving landscape of cybersecurity threats.
Using KQL to Investigate Command Execution Activities in an Environment Using Defender/Sentinel
Note: While there are other methods and tools for investigating these kinds of attacks, the goal is to tackle them from a beginner's point of view without utilising intricate KQL queries that a Level 1 SOC analyst wouldn't find difficult to comprehend. Other areas on the site will demonstrate the same process using other tools, such as Splunk, Velociraptor, or Eric Zimmerman Tools.
Execution techniques involve adversaries running malicious code on a target system. These techniques are crucial in the attack chain as they enable the adversary to execute their payloads, gain persistence, escalate privileges, and move laterally within the network.
1. T1059 - Command and Scripting Interpreter
Objective: Detect the use of command and scripting interpreters to execute malicious commands or scripts.
Detect PowerShell Script Execution
Purpose: Identify instances of PowerShell being used to execute scripts.
Detect CMD.exe Execution
Purpose: Monitor for the use of the command prompt to run commands.
Identify the Use of Python Scripts
Purpose: Detect execution of Python scripts on the system.
Monitor for VBScript Execution
Purpose: Identify the execution of VBScript files.
Detect Bash Script Execution via WSL
Purpose: Monitor for the use of Bash scripting via the Windows Subsystem for Linux (WSL).
Identify JavaScript Execution via Node.js
Purpose: Detect the execution of JavaScript files using Node.js.
Detect PowerShell Command with Encoded Parameters
Purpose: Identify obfuscated PowerShell commands using encoded parameters.
Monitor for Scripting Engine Execution via Office Macros
Purpose: Detect the use of Office applications to execute scripts.
Detect WMI Command Execution
Purpose: Identify the use of Windows Management Instrumentation (WMI) to execute commands.
Monitor for JScript Execution via MSHTA
Purpose: Detect the execution of JScript or VBScript using the MSHTA utility.
2. T1047 - Windows Management Instrumentation
Objective: Detect the use of WMI to execute commands or scripts remotely on the target system.
Detect Remote WMI Execution
Purpose: Identify the use of WMI to remotely execute processes.
Monitor WMI Commands Creating New Processes
Purpose: Detect WMI commands that create new processes on the system.
Identify WMI Execution via PowerShell
Purpose: Monitor for WMI usage through PowerShell.
Detect Suspicious WMI Execution with Credentials
Purpose: Identify WMI execution using specific credentials, which may indicate lateral movement.
Monitor for WMI Execution from Non-Admin Accounts
Purpose: Detect WMI execution by non-administrative accounts.
Identify WMI Execution to Start Services
Purpose: Monitor for WMI commands used to start services.
Detect WMI Execution for File Transfer
Purpose: Identify WMI usage for file transfers.
Monitor for WMI Execution of Suspicious Scripts
Purpose: Detect the execution of scripts through WMI.
Identify WMI Execution to Modify Registry
Purpose: Monitor for WMI commands that modify the Windows registry.
Detect WMI Execution of DLL Files
Purpose: Identify the use of WMI to execute DLL files.
3. T1203 - Exploitation for Client Execution
Objective: Detect exploitation attempts targeting client applications to execute malicious code.
Detect Exploitation Attempts in Web Browsers
Purpose: Identify exploitation attempts targeting web browsers.
Monitor for Office Application Exploits
Purpose: Detect exploitation attempts in Microsoft Office applications.
Identify Adobe Reader Exploitation
Purpose: Monitor for exploitation of Adobe Reader.
Detect Exploitation via Email Clients
Purpose: Identify exploitation attempts targeting email clients.
Monitor for PDF Exploitation Attempts
Purpose: Detect exploitation attempts involving PDF files.
Detect Exploitation via Media Players
Purpose: Monitor for exploitation attempts targeting media players.
Identify Java Application Exploitation
Purpose: Detect exploitation attempts in Java applications.
Monitor for Flash Player Exploitation
Purpose: Identify exploitation attempts in Adobe Flash Player.
Detect Exploitation via Browsing History
Purpose: Monitor for exploitation attempts using browsing history.
Identify Exploitation Using Document Macros
Purpose: Detect the use of macros in document exploitation.
4. T1106 - Native API
Objective: Detect the use of native Windows APIs to execute malicious code or commands.
Detect Use of Windows API Calls
Purpose: Identify processes making direct API calls.
Monitor for Execution via CreateProcess API
Purpose: Detect execution of processes using the CreateProcess API.
Identify Use of LoadLibrary API
Purpose: Monitor for the loading of dynamic link libraries (DLLs) using the LoadLibrary API.
Detect Memory Allocation via VirtualAlloc
Purpose: Identify memory allocation attempts using the VirtualAlloc API.
Monitor for Remote Thread Injection via CreateRemoteThread
Purpose: Detect remote thread injection using the CreateRemoteThread API.
Identify API Calls for Process Injection
Purpose: Detect the use of APIs commonly associated with process injection.
Detect API Calls for Code Execution
Purpose: Monitor for API calls used to execute code.
Identify Use of API for Privilege Escalation
Purpose: Detect API usage for privilege escalation.
Monitor for API Calls Modifying System Files
Purpose: Identify attempts to modify system files via API calls.
Detect API Calls for Network Communications
Purpose: Monitor for API calls initiating network communications.
5. T1202 - Indirect Command Execution
Objective: Detect the use of indirect methods to execute commands, such as through application features, scripting, or automated tasks.
Detect Execution via Scheduled Tasks
Purpose: Identify the creation of scheduled tasks for command execution.
Monitor for Execution via Registry Autorun
Purpose: Detect the use of registry autorun keys for indirect command execution.
Identify Execution via Office Macros
Purpose: Monitor for command execution via Office macros.
Detect Execution via Task Scheduler
Purpose: Identify the use of Task Scheduler for indirect command execution.
Monitor for Execution via WMI Event Subscriptions
Purpose: Detect the use of WMI event subscriptions for command execution.
Identify Execution via Application Debugging
Purpose: Monitor for command execution using application debugging tools.
Detect Execution via Service Binary
Purpose: Identify the modification of service binaries for command execution.
Monitor for Execution via COM Object Hijacking
Purpose: Detect the use of COM objects for indirect command execution.
Identify Execution via Autorun.inf Files
Purpose: Monitor for the use of autorun.inf files for command execution.
Detect Execution via Remote Desktop Services
Purpose: Identify command execution through Remote Desktop Services.
6. T1072 - Software Deployment Tools
Objective: Detect the use of software deployment tools to execute malicious code on multiple systems.
Detect Execution via SCCM
Purpose: Monitor for the use of System Center Configuration Manager (SCCM) for command execution.
Monitor for Execution via Ansible
Purpose: Identify the use of Ansible for software deployment and command execution.
Identify Execution via Puppet
Purpose: Detect the use of Puppet for executing commands on systems.
Detect Execution via Chef
Purpose: Monitor for command execution using Chef.
Monitor for Execution via SaltStack
Purpose: Identify the use of SaltStack for command execution.
Detect Execution via PowerShell DSC
Purpose: Monitor for the use of PowerShell Desired State Configuration (DSC) for command execution.
Identify Execution via GPO Scripts
Purpose: Detect the use of Group Policy Object (GPO) scripts for executing commands.
Monitor for Execution via Remote Software Installation
Purpose: Identify remote software installations used for command execution.
Detect Execution via Orchestrator Runbooks
Purpose: Monitor for the use of Orchestrator Runbooks to execute commands.
Identify Execution via Custom Deployment Scripts
Purpose: Detect custom deployment scripts used for executing commands on multiple systems.
7. T1117 - Regsvr32
Objective: Detect the use of regsvr32.exe to execute DLLs or scripts, potentially as part of a living-off-the-land attack.
Detect Regsvr32 Execution
Purpose: Identify instances where regsvr32.exe is used to execute DLLs or scripts.
Monitor for Regsvr32 with Suspicious Parameters
Purpose: Detect regsvr32 executions with suspicious command-line parameters.
Identify Regsvr32 Executing Remote Files
Purpose: Monitor for regsvr32 executing remote files.
Detect Regsvr32 Used for Script Execution
Purpose: Identify regsvr32 executions that involve running scripts.
Monitor for Regsvr32 with Unusual DLLs
Purpose: Detect regsvr32 used to execute unusual or suspicious DLLs.
Identify Regsvr32 Executing from Non-Standard Locations
Purpose: Monitor for regsvr32 executing from non-standard locations.
Detect Regsvr32 with Network Connectivity
Purpose: Identify regsvr32 executions that involve network connectivity.
Monitor for Regsvr32 Execution by Non-Admin Accounts
Purpose: Detect regsvr32 usage by non-administrative accounts.
Identify Regsvr32 with High Privileges
Purpose: Monitor for regsvr32 executions with elevated privileges.
Detect Regsvr32 Used in Conjunction with UAC Bypass
Purpose: Identify regsvr32 executions associated with UAC bypass techniques.
8. T1086 - PowerShell
Objective: Detect the use of PowerShell for executing commands and scripts, which is often used in attacks.
Detect PowerShell Script Execution
Purpose: Identify instances where PowerShell is used to execute scripts.
Monitor for Obfuscated PowerShell Commands
Purpose: Detect obfuscated PowerShell commands.
Identify PowerShell Commands Downloading Files
Purpose: Monitor for PowerShell commands that download files from the internet.
Detect PowerShell Commands Executing Encoded Commands
Purpose: Identify PowerShell executions with encoded commands.
Monitor for PowerShell Execution with Admin Privileges
Purpose: Detect PowerShell commands executed with administrative privileges.
Identify PowerShell Execution from Office Applications
Purpose: Detect PowerShell commands executed from Office applications.
Detect PowerShell Commands Modifying the Registry
Purpose: Monitor for PowerShell commands that modify the Windows registry.
Monitor for PowerShell Commands Invoking WMI
Purpose: Identify PowerShell commands that invoke WMI.
Detect PowerShell Commands Executing System Commands
Purpose: Monitor for PowerShell commands that execute system commands.
Identify PowerShell Execution via Script Block Logging
Purpose: Detect PowerShell execution using script block logging.
Last updated