BOF to impersonate TrustedInstaller via DISM API trigger and thread impersonation.
Elevates a Cobalt Strike Beacon from an admin context to NT AUTHORITY\SYSTEM with the NT SERVICE\TrustedInstaller SID in the token groups. This gives you the ability to modify files, registry keys, and other objects that are owned by TrustedInstaller (i.e. things that just having SYSTEM may not be enough for).
Most public approaches to becoming TrustedInstaller start the TrustedInstaller service directly via the Service Control Manager (e.g. sc start TrustedInstaller or StartServiceW). This works, but interacting with SCM is well-understood by defenders and commonly logged.
trustme takes a different approach:
-
Loads
dismapi.dlland runs a DISM health check. The DISM API (DismCheckImageHealth) internally causesTrustedInstaller.exeto start as a side effect of servicing stack operations. The DISM session is held open so TrustedInstaller doesn't exit before we can use it. -
Walks the process list using
NtGetNextProcess. Instead ofOpenProcessorCreateToolhelp32Snapshot, we enumerate process handles indirectly throughNtGetNextProcessand match by image name viaNtQueryInformationProcess(ProcessImageFileName). -
Impersonates a TrustedInstaller thread via
NtImpersonateThread. Similarly, we walk threads withNtGetNextThreadrather than opening them by TID. Once we find a usable thread, we impersonate it and register the resulting token with Beacon viaBeaconUseToken. -
Cleans up. The DISM session is closed,
dismapi.dllis freed from the beacon process, and handles are released. The impersonation token persists in the Beacon session until you runrev2self.
- Elevated (admin) Beacon
SeDebugPrivilegemust be available in the token (it is by default for admin accounts, the BOF enables it automatically)- x64 Beacon (x86 should work but is untested)
You need beacon.h from the Cobalt Strike bof_template repo in the same directory as trustme.c.
MinGW (Linux/macOS):
x86_64-w64-mingw32-gcc -c trustme.c -o trustme.x64.o -masm=intel -WallMSVC (Windows, from x64 Native Tools prompt):
cl.exe /c /GS- /Fo"trustme.x64.o" trustme.c- Place
trustme.x64.o(and/ortrustme.x86.o) in the same directory astrustme.cna - Load
trustme.cnain Cobalt Strike via Script Manager - From an elevated Beacon:
beacon> trustme
[+] SeDebugPrivilege enabled
[*] DISM health check complete, TrustedInstaller should be running
[*] Found TrustedInstaller.exe (PID: 31337)
[+] Thread impersonation successful (identity: SYSTEM)
[+] Token applied to Beacon session
[+] Now running as TrustedInstaller. Use 'rev2self' to revert.
- Verify:
beacon> shell whoami /groups | findstr TrustedInstaller
NT SERVICE\TrustedInstaller Well-known group S-1-5-80-956008885-... Enabled by default, Enabled group, Group owner
- Revert when done:
beacon> rev2self