Command-Line Interface Execution
Overview
Command-Line Interface (CLI) Execution is a technique used by adversaries to run commands or scripts directly on a target system through a command-line environment. It plays a critical role in multiple stages of the attack lifecycle by enabling attackers to execute arbitrary code, manipulate system configurations, and control compromised hosts. This technique is favored for its flexibility, stealth, and ability to leverage native system tools.
Attack Objective
- Gain control over a system by executing commands or scripts
- Supports multiple attack lifecycle stages including Initial Access, Execution, Persistence, Privilege Escalation, Defense Evasion, Lateral Movement, Command & Control, and Exfiltration
- Advances attacker position by enabling direct interaction with the system to perform various malicious activities
How the Technique Works
Adversaries use CLI Execution to run commands or scripts within a command-line shell or interpreter available on the target system. This can involve executing built-in operating system commands, scripting languages, or custom payloads. The technique leverages native command interpreters such as Windows Command Prompt, PowerShell, Unix/Linux shells, or cloud-based CLI tools to perform actions without requiring additional software installation.
Common Methods & Variations
- Execution of shell commands via Windows CMD, PowerShell, Bash, or other shell environments
- Use of scripting languages like PowerShell, Python, or batch scripts for automation and complex tasks
- On-premises execution on endpoints and servers, cloud environment CLI tools for cloud resource manipulation, and identity-related command-line tools
- Living-off-the-land techniques leveraging legitimate system utilities versus deploying custom or third-party tools
Indicators of Compromise (IOCs)
- Unusual or unauthorized command-line activity in system and security logs
- Execution of uncommon or suspicious commands and scripts
- Creation or modification of files and processes initiated via CLI
- Network connections or data transfers initiated by command-line processes
Detection Strategies
- Monitoring command-line process creation events and command-line arguments through endpoint detection and response (EDR) tools
- Behavioral analysis to identify anomalous command patterns or sequences
- Correlation of CLI activity with other telemetry such as authentication logs, file system changes, and network traffic
Mitigation & Prevention
- Implement application control and restrict execution of unauthorized command-line interpreters and scripts
- Enforce least privilege principles to limit user and process permissions for command execution
- Use endpoint protection solutions to monitor and block suspicious CLI activity
- Apply security policies to disable or restrict scripting environments where not required
Response Considerations
- Immediately contain affected systems to prevent further command execution
- Investigate command-line logs and related artifacts to determine scope and intent
- Identify and remediate persistence mechanisms or backdoors established via CLI
- Harden systems by reviewing and tightening command execution policies and user privileges
Related Techniques
- Process Injection – to execute commands within other process contexts
- Scheduled Task/Job – for persistence via command-line scheduled executions
- Remote Services – enabling command execution on remote systems
- Credential Access – to obtain credentials for authenticated CLI sessions
Mapping & References
- MITRE ATT&CK Techniques: T1059 (Command and Scripting Interpreter)
- Public research and advisories on living-off-the-land binaries and scripts
- Incident reports highlighting CLI usage in lateral movement and persistence