Suspicious Use of For Loop with Recursive Directory Search in CMD (via process_creation)

This rule detects anomalous use of the cmd.exe 'for /f' loop combined with the 'tokens=' parameter and a recursive directory listing. This pattern may indicate an attempt to discover and execute system binaries dynamically, for example powershell, a method sometimes used by adversaries to evade detection. This behavior has been observed in various hostile lnk files.

SigmamediumWindowsv1
sigma
title: Suspicious Use of For Loop with Recursive Directory Search in CMD (via process_creation)
id: b16090aa-f5fc-5f87-85bd-db244c5cd1d3
status: stable
description: This rule detects anomalous use of the cmd.exe 'for /f' loop combined with the 'tokens=' parameter and a recursive directory listing. This pattern may indicate an attempt to discover and execute system binaries dynamically, for example powershell, a method sometimes used by adversaries to evade detection. This behavior has been observed in various hostile lnk files.
references:
    - https://attack.mitre.org/techniques/T1027/010/
    - https://attack.mitre.org/techniques/T1059/003/
    - https://www.virustotal.com/gui/file/29837d0d3202758063185828c8f8d9e0b7b42b365c8941cc926d2d7c7bae2fb3
author: Huntrule Team
date: 2026-03-28
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

Known false positives

  • Unknown

Detection content is published as a reviewed draft. Tune thresholds and exclusions against your own telemetry before enabling this rule for alerting.