When a program starts
File Association Hijacking and UAC Bypass Handlers
How changed open commands for exefile, batfile and per-user classes run code, how fodhelper and eventvwr handlers bypass UAC, and how to check and restore them.
- Tactics
- Persistence, Privilege escalation, Defense evasion
- Runs
- When a program starts
- Set up by
- Users and administrators
- Locations
- HKLM\SOFTWARE\Classes\exefile\shell\open\command
- HKCU\Software\Classes\exefile\shell
- HKCU\Software\Classes\ms-settings\shell\open\command
- HKCU\Software\Classes\mscfile\shell\open\command
- HKCU\Software\Classes\exefile\shell\runas\command
- HKCU\Software\Classes\Folder\shell\open\command
How it works
When Explorer, ShellExecute or the start command opens a file, Windows maps its extension to a class (.exe to exefile, .bat to batfile, .vbs to VBSFile) and runs the command line under that class's shell\<verb>\command key, with %1 replaced by the file's path and %* by its arguments. open is the default verb; runas is the one used for "Run as administrator". Programs that call CreateProcess directly do not go through this lookup; anything started by double-click, from the Start menu or through ShellExecute does.
Windows reads classes from HKEY_CLASSES_ROOT, a merged view of HKLM\SOFTWARE\Classes and the user's HKCU\Software\Classes. When both define the same key, the user's copy wins, the same rule COM hijacking relies on. Two kinds of abuse follow from that.
Changed open commands. If the command for exefile becomes C:\ProgramData\x.exe "%1" %*, every program the user opens from Explorer starts x.exe first, which then starts the real one. The same works for scripts, shortcuts and any document type. The stock commands are short and well known:
| Class | Default shell\open\command |
|---|---|
exefile, comfile, piffile, batfile, cmdfile | "%1" %* |
scrfile | "%1" /S |
UAC bypass handlers. Some Microsoft programs are marked to auto-elevate: for a member of Administrators, under the default UAC level, they start with a full administrator token and no prompt. Several of them open a handler that they look up in HKEY_CLASSES_ROOT, and so in the user's keys first. Whatever command the user's key names then runs elevated:
| Program | Key it reads |
|---|---|
fodhelper.exe, computerdefaults.exe | HKCU\Software\Classes\ms-settings\shell\open\command, with an empty DelegateExecute value |
eventvwr.exe | HKCU\Software\Classes\mscfile\shell\open\command |
sdclt.exe | HKCU\Software\Classes\exefile\shell\runas\command (IsolatedCommand), or Folder\shell\open\command |
WSReset.exe | HKCU\Software\Classes\AppX82a6gwre4fdg3bt635tn5ctqjf8msdd2\Shell\open\command |
Microsoft does not treat UAC as a security boundary and has changed several of these programs over the years, but the keys keep appearing in intrusions. A bypass is privilege escalation more than persistence, yet the key stays behind and fires each time the program starts. With UAC set to "Always notify", auto-elevation prompts too, which stops most of these.
Where it lives
| Location | Default | Who can write it |
|---|---|---|
HKLM\SOFTWARE\Classes\<class>\shell\<verb>\command | The commands in the table above | Administrators |
HKCU\Software\Classes\<class>\shell\<verb>\command (stored in UsrClass.dat) | No exefile, batfile, cmdfile, comfile, piffile or scrfile key; no ms-settings, mscfile or Folder command | The user, no elevation needed |
HKCU\Software\Classes\.<ext> | Absent for program types; per-user defaults for documents live under Explorer\FileExts | The user |
Per-user changes need no rights at all, and no per-user key for the program classes exists on a stock system. Changing the machine-wide classes needs administrator rights.
How attackers use it
The fodhelper bypass is two values and one command:
reg add "HKCU\Software\Classes\ms-settings\shell\open\command" /ve /d "C:\ProgramData\upd\upd.exe" /f
reg add "HKCU\Software\Classes\ms-settings\shell\open\command" /v DelegateExecute /t REG_SZ /d "" /f
fodhelper.exe
The eventvwr variant writes the same kind of default value under mscfile; the sdclt variant writes IsolatedCommand under exefile\shell\runas\command and starts sdclt.exe /KickOffElev. Metasploit ships modules for the fodhelper and eventvwr methods, and the open-source UACME project collects dozens more, so these keys appear in commodity malware as often as in hands-on intrusions. The payload is often cmd.exe /c or a PowerShell one-liner, so nothing new lands on disk.
For persistence, attackers change what opens a common file type. A per-user batfile, vbsfile or htafile command, or one for txtfile, runs the payload and then the real handler with %1, so the user sees the file open normally. With administrator rights, changing exefile in HKLM makes every program launch from Explorer go through the payload, for every user. Some droppers also redirect an extension to a class of their own.
How to check a host
On a live machine, read both the machine and the user views:
reg query "HKLM\SOFTWARE\Classes\exefile\shell\open\command"
reg query "HKCU\Software\Classes\exefile" /s
reg query "HKCU\Software\Classes\ms-settings\shell\open\command"
reg query "HKCU\Software\Classes\mscfile\shell\open\command"
reg query "HKCU\Software\Classes\Folder\shell\open\command"
autorunsc -accepteula -a h -s -h
Autoruns' Image Hijacks category covers the machine-wide exefile-style commands. For other users, read HKU\<SID>_Classes, or load a signed-out user's UsrClass.dat with reg load HKU\IR <path> and unload it afterwards.
Offline, read the SOFTWARE hive's Classes\<class>\shell\open\command and each user's UsrClass.dat at the paths above. Per-user keys are absent on a clean profile, so the key's existence and its last-write time are the evidence. Process creation events (4688 with command-line auditing, Sysmon 1) show the act: fodhelper.exe, computerdefaults.exe, eventvwr.exe, sdclt.exe or WSReset.exe starting cmd.exe, powershell.exe or an unknown program, at high integrity. Sysmon 13 records the registry write; event 4657 does so where auditing is set on the key.
Suspicious: any command under the user's ms-settings, mscfile, Folder or exefile\shell\runas keys; any per-user command for a program or script class; a machine-wide command that differs from "%1" %*.
What Windows Persistence flags
From the SOFTWARE hive, the tool reads the default value of Classes\<class>\shell\open\command for exefile, comfile, piffile, batfile, cmdfile and scrfile. A command equal to Windows' default is marked as such, carries no flag, and the "Hide Windows entries" filter hides it. Anything else raises Differs from the Windows default ("%1" %*), with "%1" /S in the title for scrfile, at high severity.
From each user's UsrClass.dat and NTUSER.DAT (Software\Classes), it reads:
- every verb's command under those six classes and under
htafile,vbsfile,jsfile,wsffile,regfileandlnkfile, takingIsolatedCommandin preference to the default value: Per-user handler for class (high). The one exception isexefile\shell\runas\command, which sdclt runs elevated: it raises UAC bypass handler: exefile runas instead; - the default value of
.exe,.bat,.cmd,.com,.scr,.pifand.lnkin the user's classes, which remaps that extension to another class: Per-user handler for .exe (or the extension concerned), high, on an entry that names the new class; - the
shell\open\commandkey ofms-settings,mscfile,Folder,Launcher.SystemSettingsandAppX82a6gwre4fdg3bt635tn5ctqjf8msdd2, when the key holds a command or aDelegateExecutevalue: UAC bypass handler: class (high), showingIsolatedCommandin preference to the default value when both exist; - the default value of
Software\Microsoft\Windows\CurrentVersion\App Paths\control.exeinNTUSER.DAT, which another sdclt bypass uses: UAC bypass handler: App Paths control.exe (high).
The command-line rules then run on each command: Downloads and runs code, Encoded PowerShell command, Runs with a hidden window, Runs from a temporary or public folder, Windows program used to run outside code and the others. Across mechanisms come Written date, Inside a Defender exclusion (path) and program also runs from mechanisms.
Limits: the machine-wide check covers the open verb of those six classes only. The tool does not judge other machine-wide classes such as txtfile, htafile or vbsfile, machine-wide extension mappings, per-user mappings of other extensions (.txt, .vbs…), or the user's FileExts choices. A remapped extension's entry names the class it points to, not that class's command: read the class to see what runs.
Cleaning up
- Preserve:
reg export "HKCU\Software\Classes\ms-settings" C:\IR\ms-settings.reg(or the class concerned), then save the payload with its hash. - Remove the per-user key the attacker created:
reg delete "HKCU\Software\Classes\ms-settings\shell\open\command" /f, then the empty parents up to the class key if nothing else is in them. Removing the user's copy restores the machine-wide behaviour at once. - Restore a changed machine-wide command from cmd.exe:
reg add "HKLM\SOFTWARE\Classes\exefile\shell\open\command" /ve /d "\"%1\" %*" /f, and compare the result with a clean machine of the same build. Do not delete the machine-wide class.
A UAC bypass means the account was already a local administrator: look at what ran elevated after the key was written (services, tasks, Defender exclusions), consider removing local administrator rights from daily accounts, and set UAC to "Always notify" where users must stay administrators. Check the other users' classes too.
See also
Related techniques
On Windows Forensics
The artifacts behind this technique, in the Windows Forensics reference: