Process
forfiles.exe
forfiles.exe selects files by name, date, or size and runs a command for each one. Administrators use it in maintenance scripts. Attackers use it as an indirect way to launch programs, executing a command through a signed binary rather than calling it directly.
File identity
Not observed.
Not observed.
Not observed.
Not observed.
Execution context
Not observed.
Not observed.
Not observed.
Not observed.
Not observed.
Not observed.
Ancestry
Not observed.
Not observed.
Not observed.
Not observed.
Behavior
Not observed.
Not observed.
Not observed.
Not observed.
forfiles /p c:\windows\system32 /m notepad.exe /c "{CMD}"Execute · Use forfiles to start a new process to evade defensive counter measuresforfiles /p c:\windows\system32 /m notepad.exe /c "{PATH_ABSOLUTE}:evil.exe"ADS · Use forfiles to start a new process from a binary hidden in an alternate data stream
Indicators
Not observed.
Analysis
forfiles.exe iterates over a set of files matching criteria and runs a command (/c) for each match, substituting tokens like the file name. The command it runs can be any program, which is the behavior attackers repurpose: forfiles becomes the launcher, so the real command appears as a child of forfiles rather than of the script or shell. The genuine binary lives at C:\Windows\System32\forfiles.exe.
Legitimately, forfiles is used in cleanup and batch jobs, for example deleting files older than a certain date. The command it runs is what gives an instance meaning.
forfiles.exe is used for indirect command execution (T1202). By wrapping a payload in forfiles /p C:\ /m <file> /c "cmd /c <command>", an attacker has forfiles spawn the real command, so detections and parent-child rules that watch for a shell directly under an Office app or script host see forfiles in between instead. The command itself still runs, just one level removed.
Because forfiles is a legitimate maintenance tool, the /c command is what matters. forfiles launching a shell, a LOLBIN, or a download from a temp folder, especially under an unusual parent, is the case to examine.
- Image path other than
C:\Windows\System32\forfiles.exehigh /crunningcmd.exe,powershell.exe, or another LOLBINhigh- Parent is an Office application, a script host, or an unfamiliar processhigh
- A
/ccommand that downloads or executes content from a user-writable pathhigh
Telemetry
Not observed.
Not observed.