Command Execution via ForFiles

Detects attempts to execute a command via the forfiles Windows utility. Adversaries may use this utility to proxy execution via a trusted parent process.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2025/02/03"
  3integration = ["endpoint", "windows", "system", "m365_defender", "sentinel_one_cloud_funnel", "crowdstrike"]
  4maturity = "production"
  5updated_date = "2026/05/04"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10Detects attempts to execute a command via the forfiles Windows utility. Adversaries may use this utility to proxy
 11execution via a trusted parent process.
 12"""
 13from = "now-9m"
 14index = [
 15    "endgame-*",
 16    "logs-crowdstrike.fdr*",
 17    "logs-endpoint.events.process-*",
 18    "logs-m365_defender.event-*",
 19    "logs-sentinel_one_cloud_funnel.*",
 20    "logs-system.security*",
 21    "logs-windows.forwarded*",
 22    "logs-windows.sysmon_operational-*",
 23    "winlogbeat-*",
 24]
 25language = "eql"
 26license = "Elastic License v2"
 27name = "Command Execution via ForFiles"
 28note = """## Triage and analysis
 29
 30### Investigating Command Execution via ForFiles
 31
 32### Possible investigation steps
 33
 34- Identify the user account that performed the action and whether it should perform this kind of action.
 35- Contact the account owner and confirm whether they are aware of this activity.
 36- Investigate other alerts associated with the user/host during the past 48 hours.
 37- Validate the activity is not related to planned patches, updates, network administrator activity, or legitimate software installations.
 38- Assess whether this behavior is prevalent in the environment by looking for similar occurrences across hosts.
 39
 40### False positive analysis
 41
 42- This is a dual-use tool, meaning its usage is not inherently malicious. Analysts can dismiss the alert if the administrator is aware of the activity, no other suspicious activity was identified.
 43
 44### Response and Remediation
 45
 46- Initiate the incident response process based on the outcome of the triage.
 47- Isolate the involved host to prevent further post-compromise behavior.
 48- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
 49- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
 50- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
 51- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
 52"""
 53
 54setup = """## Setup
 55
 56This rule is designed for data generated by [Elastic Defend](https://www.elastic.co/security/endpoint-security), which provides native endpoint detection and response, along with event enrichments designed to work with our detection rules.
 57
 58Setup instructions: https://ela.st/install-elastic-defend
 59
 60### Additional data sources
 61
 62This rule also supports the following third-party data sources. For setup instructions, refer to the links below:
 63
 64- [CrowdStrike](https://ela.st/crowdstrike-integration)
 65- [Microsoft Defender XDR](https://ela.st/m365-defender)
 66- [SentinelOne Cloud Funnel](https://ela.st/sentinel-one-cloud-funnel)
 67- [Sysmon Event ID 1 - Process Creation](https://ela.st/sysmon-event-1-setup)
 68- [Windows Process Creation Logs](https://ela.st/audit-process-creation)
 69"""
 70
 71references = ["https://lolbas-project.github.io/lolbas/Binaries/Forfiles/"]
 72risk_score = 47
 73rule_id = "3f7bd5ac-9711-44b4-82c1-fa246d829f15"
 74severity = "medium"
 75tags = [
 76    "Domain: Endpoint",
 77    "OS: Windows",
 78    "Use Case: Threat Detection",
 79    "Tactic: Defense Evasion",
 80    "Data Source: Elastic Endgame",
 81    "Data Source: Elastic Defend",
 82    "Data Source: Windows Security Event Logs",
 83    "Data Source: Microsoft Defender XDR",
 84    "Data Source: Sysmon",
 85    "Data Source: SentinelOne",
 86    "Data Source: Crowdstrike",
 87    "Resources: Investigation Guide",
 88]
 89timestamp_override = "event.ingested"
 90type = "eql"
 91
 92query = '''
 93process where host.os.type == "windows" and event.type == "start" and user.id != "S-1-5-18" and
 94 (process.name : "forfiles.exe" or ?process.pe.original_file_name == "forfiles.exe") and process.args : ("/c", "-c") and
 95 not process.args : ("-d", "/d", "cmd /c copy @file*", "cmd /c DEL /Q /F @*", "cmd /c del @*", "D:\\*")
 96'''
 97
 98
 99[[rule.threat]]
100framework = "MITRE ATT&CK"
101[[rule.threat.technique]]
102id = "T1202"
103name = "Indirect Command Execution"
104reference = "https://attack.mitre.org/techniques/T1202/"
105
106
107[rule.threat.tactic]
108id = "TA0005"
109name = "Defense Evasion"
110reference = "https://attack.mitre.org/tactics/TA0005/"

Triage and analysis

Investigating Command Execution via ForFiles

Possible investigation steps

  • Identify the user account that performed the action and whether it should perform this kind of action.
  • Contact the account owner and confirm whether they are aware of this activity.
  • Investigate other alerts associated with the user/host during the past 48 hours.
  • Validate the activity is not related to planned patches, updates, network administrator activity, or legitimate software installations.
  • Assess whether this behavior is prevalent in the environment by looking for similar occurrences across hosts.

False positive analysis

  • This is a dual-use tool, meaning its usage is not inherently malicious. Analysts can dismiss the alert if the administrator is aware of the activity, no other suspicious activity was identified.

Response and Remediation

  • Initiate the incident response process based on the outcome of the triage.
  • Isolate the involved host to prevent further post-compromise behavior.
  • Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
  • Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
  • Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
  • Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).

References

Related rules

to-top