Skip to content

Security: TsekNet/unsudo

Security

docs/security.md

Security

For security teams and engineers. The README covers what unsudo is for; this is the threat model and how to deploy it safely. The short version: code-sign it and allowlist it in your EDR/WDAC, see Deployment hardening.

unsudo is a dual-use tool. SYSTEM-to-user token impersonation plus arbitrary process launch is exactly the primitive an attacker wants. Deploy it as such.

What it is and is not

Property Detail
No elevation unsudo runs the command with the user's session token — for an administrator, that is the filtered, medium-integrity token (exactly what they get at their desktop), not the linked elevated token. It does not elevate or bypass UAC.
No persistence on the run path When a user is logged on, the run path installs nothing and exits. The no-user case is the one exception: by default unsudo registers an AtLogon scheduled task that fires once and deletes itself (pass -nodefer to fail instead of scheduling). No service, no autostart.
No network It does not open sockets or phone home.
Transparent The entire token path is a few hundred lines of Go in this repository. Read it.
Auditable A single, named, hash-stable, code-signable binary is far easier for an EDR/WDAC policy to allowlist and reason about than runtime C# compilation (Add-Type), which resembles the fileless-execution pattern EDR scrutinizes.

The red-team objection

"You shipped a binary that sits on disk and lets any SYSTEM process launch an arbitrary executable in a logged-on user's interactive session. That is a turnkey SYSTEM-to-user execution primitive, a LOLBin. An attacker who lands SYSTEM drops unsudo (or finds it already deployed) and now has a clean, reliable way to run code as every logged-on user: act from their desktop, touch their HKCU, impersonate them. You productized a token-manipulation technique and put it on disk."

A fair description. The response is not that the capability is harmless, it is that unsudo adds no capability that the only actor who can use it does not already have.

The objection The response
"It's a privilege escalation / LOLBin." It only ever descends. unsudo requires SeTcbPrivilege (SYSTEM-only) and hands the child the user's lower-privileged token. There is no input under which a less-privileged caller gains privilege. Proven on-device: a normal administrator without SeTcbPrivilege gets "no usable session," not a user shell.
"An attacker can abuse it." Only an attacker already at SYSTEM, and SYSTEM is already total control. The same result is ~40 lines of CreateProcessAsUser they can drop themselves, or the in-memory Add-Type P/Invoke that unsudo exists to replace. The trust boundary is "who can run as SYSTEM," which is the OS's, and it is identical with or without unsudo on disk.
"Dropping it widens the attack surface." Against a non-SYSTEM attacker it is inert, it no-ops without SeTcbPrivilege. It widens nothing for anyone who has not already won SYSTEM.
"A bare executable that calls CreateProcessAsUser is a finding." Correct, and that is an argument for this shape, not against it. A single named, hash-stable, signable binary is allowlistable and EDR-loggable; the workaround it replaces (runtime C# compilation) is the fileless pattern EDR actually hunts. unsudo shrinks the gray area.

Residual risk, stated plainly: unsudo is a clean, reusable SYSTEM-context primitive, so treat the ability to invoke it as equivalent to holding SYSTEM. That is not novel exposure, it is an existing SYSTEM capability made named, signed, and observable instead of ad hoc and invisible. Harden it as such (below) and have your EDR alert on unsudo running with an unexpected parent process or arguments.

Threat model

The dangerous capability is launching an arbitrary process as a logged-on user from SYSTEM. The two questions that matter:

  1. Who can invoke unsudo? It must run as SYSTEM, so the real question is who can cause a SYSTEM process to run it. That is your management agent's trust boundary, not unsudo's.
  2. Can the binary or its input be tampered with? If an attacker can replace unsudo.exe or control its arguments, they get code execution as the logged-on user. So:

Deferred job specs (StrictModes)

When no user is logged on, unsudo persists the command to %ProgramData%\unsudo\jobs\<id>.json and a SYSTEM scheduled task runs it at the next logon (see architecture.md). That spec is therefore a command a SYSTEM task will execute, so its file permissions are a trust boundary, exactly like an SSH private key. unsudo treats it that way:

Protection Behavior
Locked on creation unsudo sets an explicit ACL on %ProgramData%\unsudo (owner = Administrators; protected DACL granting full control to SYSTEM and Administrators only, inherited by children). Standard users cannot create, alter, or plant a spec there.
Verified on use (StrictModes) Before executing a deferred job, run-deferred refuses to run if the jobs directory or the spec file is owned by anyone but SYSTEM/Administrators, or grants write access to any other account, the same way ssh refuses a private key others can write.
Refusals are logged A refusal is recorded to the Windows Event Log (source unsudo, event ID 1024) with the offending path, since a deferred run has no console.

So even if the data directory's ACL is later weakened, a tampered or attacker-planted spec is refused, not executed. Editing a spec to run arbitrary code requires write access that only SYSTEM/Administrators have, which is no privilege boundary crossed.

Deployment hardening

Control Why
Code-sign the binary and pin its hash in your EDR/WDAC allowlist An unsigned binary in a writable directory that calls CreateProcessAsUser is a finding. A signed, allowlisted one is a tool.
Restrict write access to unsudo's directory to SYSTEM/Administrators unsudo runs as SYSTEM's caller; if a standard user can overwrite unsudo.exe, they can run code as SYSTEM's caller chooses
Validate any caller-supplied arguments If your wrapper passes user-controlled strings to unsudo run, treat them as untrusted input
Log invocations Record who invoked unsudo, the command, the resolved target user, and the session, for audit

Reporting

This is a side project; there is no formal disclosure process. Open an issue (or a private report if the repository has it enabled) for security concerns.

There aren't any published security advisories