Windows CMD for /f Tokens= with Recursive Dir Listing
Flags cmd.exe for /f loops using tokens= with recursive dir enumeration in the command line and parent.
- Product
- windows
- Category
- process_creation
- Author
- Joseliyo Sanchez, @Joseliyo_Jstnk (SigmaHQ), DRL 1.1
- Published
- 2025-11-12
- Updated
- 2026-07-30
ATT&CK techniques
Execution → Defense EvasionRecon
Resource Dev
Initial Access
Execution
Persistence
Priv Esc
Defense Evasion
Cred Access
Discovery
Lateral Movement
Collection
C2
Exfiltration
Impact
What it detects
This rule flags process creation events where cmd.exe command lines include a for /f loop with tokens= and an in ( dir ... ) style recursive directory listing pattern. Such command-line composition can be used to dynamically enumerate files and drive subsequent actions, which is a common step in stealthy execution chains. The detection relies on Windows process creation telemetry capturing the full command line for both the process and its parent.
Reporting behind it
Detection content is published as a reviewed draft. Tune thresholds and exclusions against your own telemetry before enabling this rule for alerting.
title: Windows CMD for /f Tokens= with Recursive Dir Listing
id: b7cc34a9-c828-4522-a6c5-afee9cac05c7
status: experimental
description: This rule flags process creation events where cmd.exe command lines include a for /f loop with tokens= and an in ( dir ... ) style recursive directory listing pattern. Such command-line composition can be used to dynamically enumerate files and drive subsequent actions, which is a common step in stealthy execution chains. The detection relies on Windows process creation telemetry capturing the full command line for both the process and its parent.
references:
- https://www.virustotal.com/gui/file/29837d0d3202758063185828c8f8d9e0b7b42b365c8941cc926d2d7c7bae2fb3
- https://github.com/SigmaHQ/sigma/blob/master/rules/windows/process_creation/proc_creation_win_susp_cmd_for_loop_execution_with_recursive_directory_search.yml
author: Joseliyo Sanchez, @Joseliyo_Jstnk, Huntrule Team
date: 2025-11-12
tags:
- attack.execution
- attack.stealth
- attack.t1059.003
- attack.t1027.010
logsource:
category: process_creation
product: windows
detection:
selection_tokens:
CommandLine|contains|all:
- for /f
- tokens=
- in (
- dir
selection_tokens_parent:
ParentCommandLine|contains|all:
- for /f
- tokens=
- in (
- dir
condition: 1 of selection_*
falsepositives:
- Unknown
level: medium
license: DRL-1.1
related:
- id: 2782fbd8-b662-4eb5-9962-5bfbfb671e7b
type: derived