Skip to content

Command Processor AutoRun: cmd.exe Persistence

How the Command Processor AutoRun value runs a command whenever cmd.exe starts, how attackers use it to persist and ride elevated prompts, and how to remove it.

MITRE ATT&CK
T1546
Tactics
Persistence, Privilege escalation
Runs
Each new shell
Set up by
Users and administrators
Locations
  • HKLM\SOFTWARE\Microsoft\Command Processor
  • HKCU\Software\Microsoft\Command Processor
  • HKLM\SOFTWARE\WOW6432Node\Microsoft\Command Processor

How it works

cmd.exe documents this itself in cmd /?: unless it is started with /D, it looks for a REG_SZ or REG_EXPAND_SZ value named AutoRun in HKLM\Software\Microsoft\Command Processor and in HKCU\Software\Microsoft\Command Processor, and if either or both are present, it executes them first. The value is a command line in cmd's own syntax, so it can chain commands with &, redirect output and call batch files.

This happens every time cmd.exe starts, not only when someone opens a prompt:

  • an interactive Command Prompt, including an elevated one;
  • every cmd.exe /c that a script, installer, scheduled task or service starts;
  • every batch file opened from Explorer, which runs through cmd.exe;
  • programs that shell out through cmd.exe to run a command.

The AutoRun command runs inside that cmd.exe process, so it has the same user, the same integrity level and the same session. That has two consequences. An HKLM value runs for every account that starts cmd.exe, including SYSTEM when a service or task uses it. And an HKCU value, which the user can set without administrator rights, runs elevated the next time that user, if an administrator, opens an elevated prompt, because the elevated process reads the same user hive.

On 64-bit Windows, the 32-bit cmd.exe in C:\Windows\SysWOW64 reads the machine value from HKLM\SOFTWARE\WOW6432Node\Microsoft\Command Processor. ATT&CK has no sub-technique for AutoRun; this site files it under Event Triggered Execution (T1546).

Two side effects give it away in practice. Anything the command prints appears at the top of every prompt, so attackers redirect output to nul. And a command that itself starts cmd.exe without /D triggers AutoRun again, in a loop, so careful payloads use cmd /d or start their program with start.

Where it lives

LocationWho can write itOn a stock Windows 10 or 11
HKLM\SOFTWARE\Microsoft\Command Processor, value AutoRunAdministrators, SYSTEMNo AutoRun; the key holds settings such as CompletionChar, DefaultColor and EnableExtensions
HKLM\SOFTWARE\WOW6432Node\Microsoft\Command Processor, value AutoRunAdministrators, SYSTEMNo AutoRun
HKCU\Software\Microsoft\Command Processor, value AutoRunThe userKey often absent

Legitimate software does use it. Developer tools set a per-user AutoRun to prepare every prompt: Clink (clink autorun install) injects itself into cmd.exe this way, and conda init cmd.exe adds Anaconda's hook. Some administrators set a code page or load doskey macros. Know which of these your users have before reading an AutoRun as hostile.

How attackers use it

Setting it is one command:

reg add "HKCU\Software\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "start /b C:\Users\Public\Libraries\svc.exe >nul 2>&1" /f
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Command Processor' -Name AutoRun -Value 'C:\ProgramData\Microsoft\Crypto\init.cmd >nul 2>&1'

The patterns:

  • A per-user value as a low-privilege foothold that waits for the user to open an elevated prompt.
  • A machine-wide value on a server, where scheduled tasks, services and management agents start cmd.exe many times a day, so the payload is restarted constantly, often as SYSTEM.
  • A short, quiet command (start /b, output sent to nul) that calls a batch file elsewhere, so the registry value looks like a developer's setting while the batch file holds the payload.

It is less common than Run keys and easy to miss in a quick review, which is the attraction. Its PowerShell counterpart is the PowerShell profile.

How to check a host

Start your own prompts with cmd /d, or work from PowerShell, so that you do not run the payload while you look for it.

cmd /d /c reg query "HKLM\SOFTWARE\Microsoft\Command Processor" /v AutoRun
cmd /d /c reg query "HKLM\SOFTWARE\WOW6432Node\Microsoft\Command Processor" /v AutoRun
cmd /d /c reg query "HKCU\Software\Microsoft\Command Processor" /v AutoRun
Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Command Processor', 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Command Processor' -Name AutoRun -ErrorAction SilentlyContinue
Get-ItemProperty 'Registry::HKEY_USERS\*\Software\Microsoft\Command Processor' -Name AutoRun -ErrorAction SilentlyContinue

The last command covers every loaded user hive, including those of SYSTEM (HKU\S-1-5-18) and the service accounts; load the hives of users who are not logged on with reg load. Autoruns also lists the AutoRun values (autorunsc.exe -accepteula -a l -s -h -c).

Offline, read Microsoft\Command Processor and WOW6432Node\Microsoft\Command Processor in the SOFTWARE hive, Software\Microsoft\Command Processor in each NTUSER.DAT, and, for the built-in accounts, the DEFAULT hive in C:\Windows\System32\config (SYSTEM) and the NTUSER.DAT files under C:\Windows\ServiceProfiles\LocalService and NetworkService. The key's last-write time is a fair clue: Windows rarely writes to it. In process creation events (4688 with command lines, or Sysmon event 1), a program started by AutoRun appears as a child of cmd.exe immediately after it starts, every time, whatever the parent asked cmd.exe to do. Sysmon event 13 records the value being set.

Compare each value with the software installed: the values Clink and conda write name a file inside their own install folder, so any extra command chained in the same value is an addition. What stands out: any AutoRun you cannot tie to an installed tool, a program in a user-writable folder, start /b or powershell in the value, output redirected to nul, and an HKLM value on a machine with no developer tools.

What Windows Persistence flags

The tool reads AutoRun in Microsoft\Command Processor and WOW6432Node\Microsoft\Command Processor in the SOFTWARE hive, and in the same two paths under Software in each user hive of the collection: the users' profiles, the Default profile, SYSTEM's .DEFAULT hive (shown as the user "SYSTEM (.DEFAULT)") and the LOCAL SERVICE and NETWORK SERVICE profiles, which the collection command copies. Each non-empty value is an entry triggered by the shell.

Every such entry raises cmd.exe AutoRun (medium): Windows sets no AutoRun, so any value is worth reading, Clink and conda included. The command-line rules then run on the value: Downloads and runs code, Encoded PowerShell command, Obfuscated command, Runs with a hidden window, Runs from a temporary or public folder, Runs from a network share, Windows program used to run outside code, Windows program name in the wrong place, Machine-made name and the others, plus System-wide autostart from a writable folder for the machine-wide values. Across mechanisms: Written date, Inside a Defender exclusion (exclusion) and program also runs from mechanisms.

Because every value is flagged, Hide Windows entries never hides an AutoRun entry.

Limits: the tool reads the command, not the batch file or program it calls. It cannot know whether the programs that start cmd.exe on this machine pass /D.

Cleaning up

  1. Work from PowerShell or cmd /d. Preserve the key: reg export "HKCU\Software\Microsoft\Command Processor" cmdproc.reg, and copy and hash the files the value calls.
  2. Delete the value only: reg delete "HKCU\Software\Microsoft\Command Processor" /v AutoRun /f (or the HKLM path). Do not delete the key: the machine key holds cmd's own settings.
  3. If the value belongs to a developer tool, remove it through that tool, or keep it and check that nothing was appended to it.
  4. Delete the payload, then look for it in the other mechanisms. An HKLM value, or an HKCU value of a user who opens elevated prompts, ran with administrator or SYSTEM rights: treat the host as fully compromised and rotate its administrator and service credentials.

See also

On Windows Forensics

The artifacts behind this technique, in the Windows Forensics reference: