//nefariousplan

Junction Preemption

A privileged process writes to a directory it never pre-created with restrictive permissions. A standard user occupies the path first as an NTFS junction. The privileged write follows the attacker's redirection.

SYSTEM writes the file, correctly, with the right ACL, to the exact path the installer asked for. A standard user already pointed that path at System32 before the installer started.

Mechanism

Privileged process writes into a directory it didn't pre-create with restrictive ACLs. C:\ProgramData\Vendor\stage is writable by any user. Attacker creates Vendor\ first and makes it a junction to C:\Windows\System32. The installer resolves the path, NTFS walks through the junction, the privileged write lands in System32 with whatever ACL the installer set. The privilege check passed. At an address the attacker chose.

The variants change the bait, not the shape. Printer drivers stage spool files in user-writable temp paths. Antivirus uninstallers drop quarantine logs under Temp because the install lived there. Update services unpack downloads in ProgramData because that's the convention. Each is one missing SECURITY_ATTRIBUTES away from the same redirection.

Code that does call CreateDirectory before writing doesn't escape the pattern unless it passes a restrictive SECURITY_ATTRIBUTES on creation. The default inherits from the parent, and ProgramData's parent allows everyone-create-subdirectory. So the privileged code creates the dir, the dir inherits the loose ACL, the attacker still wins on the next install or update cycle.

Defenses that check after the fact (GetFileSecurity after open, attribute inspection on the resulting file) are decoration. The handle is already on the redirected target. The write has happened. The ACL on the resulting file reflects the attacker's choice, not the installer's intent.

Exhibits

CVE-2026-7791: Skylight Doesn't Create ROTATE. The Standard User Does.. Skylight's archive routine writes through C:\ProgramData\Amazon\Skylight Metrics Agent\ROTATE as SYSTEM and treats the path as if its installer owned it. The installer did not pre-create ROTATE with a restrictive SECURITY_ATTRIBUTES, and the parent ProgramData ACL grants BUILTIN\Users create-and-modify on every child. The PoC's setup branch handles every initial state, missing directory, normal directory, pre-existing junction, and lands each one as an NTFS junction pointing at the attacker's chosen target. The File.Move SYSTEM does on the next rotation tick writes the attacker's DLL into C:\Program Files\Amazon\EC2Launch, the AWS-provided agent that loads plugin DLLs from its install directory at instance boot. The exhibit's contribution to this pattern is the cleanup-loop variant: Skylight would normally have rolled the arbitrary write back, and the CVE title bills the deletion-window the attacker uses to prevent that as a coequal bug. It isn't. The race is the cleanup's; the primitive is the junction's.

CVE-2026-0827: LdeApi.Server.exe Assumes It Creates the Directory First. The Lenovo Diagnostics Engine service writes MP27AM7W_estimation.json to C:\ProgramData\Lenovo\LDE\SYSTEM as SYSTEM. The path does not exist on a fresh install. The PoC pre-creates it as an NTFS mount point into the NT object namespace before the service arrives, then plants a symbolic link at \RPC Control\MP27AM7W_estimation.json pointing to the attacker's chosen target. The entire exploit lives in the gap between "this path will be created by the service" and "this path can be created by anyone first." The service writes to the attacker's target because it followed the junction and never checked whether the directory it expected to own was actually a real directory.

Boundaries

Not TOCTOU. The junction is in place before the privileged work starts. There is no race window for the defender to shrink, no timing-sensitive code to audit. The attacker wins deterministically by existing there first.

Not generic symlink-following. Junctions resolve at the NTFS driver below most process-level reparse guards. Code that assumes O_NOFOLLOW-style protections carry over from POSIX intuition will miss this; Windows requires explicitly setting FILE_FLAG_OPEN_REPARSE_POINT and inspecting the reparse attribute.

Defender playbook

Pre-create every privileged-writable directory at install time with an ACL that denies non-admin write. Resolve paths only after your code owns the directory. First-write assumptions are the bug; take ownership explicitly.

Open paths with FILE_FLAG_OPEN_REPARSE_POINT and reject reparse targets before writing. Check FILE_ATTRIBUTE_REPARSE_POINT on every directory in the resolution chain, not just the leaf. A junction anywhere along the way is a redirect you didn't authorize.

During code review, treat every CreateFile/CreateDirectory against a path under user-writable space as a load-bearing security choice. Require a pre-validated handle on the parent directory and explicit SECURITY_ATTRIBUTES on creation. Static analyzers can flag the pattern; exceptions need justification, not boilerplate.

Kinship

TOCTOU That Isn't. Junction-preemption is the canonical example of a TOCTOU That Isn't. The "race" framing in advisories misdirects the fix toward atomicity primitives, but the attacker placed the junction long before the privileged process started. The fix is directory ownership, not a tighter window.

Symlinks don't suck. Writing to a directory you don't own does.