Skip to content
WETNav

Execution · Windows · LOLBAS

forfiles.exe

ForFiles

Selects files by name, date or size and runs a command for each. The command it runs can be any process, so it is used as an indirect launcher that hides the real parent.

Legitimate use

Used in scripts to act on files that match a pattern, for example deleting old logs.

Worst caseMedium

Switches

/p<value>

The path to search.

Info
/m<value>

The file name pattern to match.

Info
/s

Searches subfolders.

Info
/c<value>

The command to run for each matched file. Any executable can go here.

Medium
/d<value>

Filters by last modified date.

Info

Command lines to worry about

  • Medium

    ForFiles used to launch another process

    forfiles runs a shell or script interpreter through its /c option. This hides the real parent and is a known indirect execution trick.

    Detection regexforfiles(\.exe)?\s+.*\/c\s+"?(cmd|powershell|pwsh|wscript|cscript|rundll32|mshta)

    T1202

Where it is recorded

  • Security4688Process creation with the full command line, when command-line auditing is enabled.
  • Sysmon1Process creation with command line, hashes and parent process.

Community detections

9 SigmaHQ rules for forfiles.exe. The explainer checks every pasted command line against all of them.

  • High
    Suspicious Child Process Of Manage Engine ServiceDesk

    Detects suspicious child processes of the "Manage Engine ServiceDesk Plus" Java web service

    T1102by Florian Roth (Nextron Systems)

  • High
    Suspicious Microsoft Office Child Process

    Detects a suspicious process spawning from one of the Microsoft Office suite products (Word, Excel, PowerPoint, Publisher, Visio, etc.)

    T1047T1204.002T1218.010by Florian Roth (Nextron Systems), Markus Neis, FPT.EagleEye Team, Vadim Khrykov, Cyb3rEng, Michael Haag, Christopher Peacock @securepeacock, @scythe_io

  • High
    Suspicious Microsoft OneNote Child Process

    Detects suspicious child processes of the Microsoft OneNote application. This may indicate an attempt to execute malicious embedded objects from a .one file.

    T1566T1566.001by Tim Rauch (Nextron Systems), Nasreddine Bencherchali (Nextron Systems), Elastic (idea)

  • High
    Suspicious Outlook Child Process

    Detects a suspicious process spawning from an Outlook process.

    T1204.002by Michael Haag, Florian Roth (Nextron Systems), Markus Neis, Elastic, FPT.EagleEye Team

  • High
    Suspicious Processes Spawned by Java.EXE

    Detects suspicious processes spawned from a Java host process which could indicate a sign of exploitation (e.g. log4j)

    by Andreas Hunkeler (@Karneades), Florian Roth

  • High
    Suspicious Serv-U Process Pattern

    Detects a suspicious process pattern which could be a sign of an exploited Serv-U service

    T1555by Florian Roth (Nextron Systems)

  • High
    Suspicious Shells Spawn by Java Utility Keytool

    Detects suspicious shell spawn from Java utility keytool process (e.g. adselfservice plus exploitation)

    by Andreas Hunkeler (@Karneades)

  • High
    Suspicious SYSTEM User Process Creation

    Detects a suspicious process creation as SYSTEM user (suspicious program or command line parameter)

    T1134T1003T1027by Florian Roth (Nextron Systems), David ANDRE (additional keywords)

  • Medium
    Forfiles Command Execution

    Detects the execution of "forfiles" with the "/c" flag. While this is an expected behavior of the tool, it can be abused in order to proxy execution through it with any binary. Can be used to bypass application whitelisting.

    T1059by Tim Rauch, Elastic, E.M. Anhaus (originally from Atomic Blue Detections, Endgame), oscd.community

Rules from SigmaHQ (rules/windows/process_creation), Detection Rule License (DRL) 1.1. Each rule links to its source and credits its authors.