Meowmycks/trustme

GitHub: Meowmycks/trustme

通过 DISM API 间接触发和线程模拟技术,将 Cobalt Strike Beacon 从管理员权限提升至 TrustedInstaller 权限。

Stars: 89 | Forks: 4

# trustme BOF,用于通过 DISM API 触发和线程模拟来模拟 TrustedInstaller。 trustedinstaller ## 功能 将 Cobalt Strike Beacon 从管理员上下文提权至 `NT AUTHORITY\SYSTEM`,并在令牌组中包含 `NT SERVICE\TrustedInstaller` SID。这使你能够修改由 TrustedInstaller 拥有的文件、注册表键和其他对象(即仅拥有 SYSTEM 权限可能不足以完成的操作)。 ## 工作原理 大多数成为 TrustedInstaller 的公开方法是通过服务控制管理器 (SCM) 直接启动 TrustedInstaller 服务(例如 `sc start TrustedInstaller` 或 `StartServiceW`)。这种方法虽然有效,但与 SCM 的交互已被防御者充分了解,且通常会被记录。 `trustme` 采用了不同的方法: 1. **加载 `dismapi.dll` 并运行 DISM 健康检查。** DISM API (`DismCheckImageHealth`) 在内部会作为服务堆栈操作的副作用导致 `TrustedInstaller.exe` 启动。DISM 会话保持打开状态,以便 TrustedInstaller 在我们使用它之前不会退出。 2. **使用 `NtGetNextProcess` 遍历进程列表。** 我们不使用 `OpenProcess` 或 `CreateToolhelp32Snapshot`,而是通过 `NtGetNextProcess` 间接枚举进程句柄,并通过 `NtQueryInformationProcess(ProcessImageFileName)` 匹配映像名称。 3. **通过 `NtImpersonateThread` 模拟 TrustedInstaller 线程。** 同样,我们使用 `NtGetNextThread` 遍历线程,而不是通过 TID 打开它们。一旦找到可用的线程,我们就模拟它,并通过 `BeaconUseToken` 将生成的令牌注册到 Beacon。 4. **清理。** DISM 会话关闭,`dismapi.dll` 从 beacon 进程中释放,句柄被释放。模拟令牌会保留在 Beacon 会话中,直到你运行 `rev2self`。 ## 要求 - 提权(管理员) Beacon - 令牌中必须可用 `SeDebugPrivilege`(默认情况下对管理员账户可用,BOF 会自动启用它) - x64 Beacon(x86 应该可以工作,但未经测试) ## 构建 你需要将 [Cobalt Strike bof_template repo](https://github.com/Cobalt-Strike/bof_template) 中的 `beacon.h` 放在与 `trustme.c` 相同的目录中。 **MinGW (Linux/macOS):** ``` x86_64-w64-mingw32-gcc -c trustme.c -o trustme.x64.o -masm=intel -Wall ``` **MSVC (Windows, 来自 x64 Native Tools 提示符):** ``` cl.exe /c /GS- /Fo"trustme.x64.o" trustme.c ``` ## 用法 1. 将 `trustme.x64.o`(和/或 `trustme.x86.o`)放在与 `trustme.cna` 相同的目录中 2. 在 Cobalt Strike 中通过 Script Manager 加载 `trustme.cna` 3. 从一个提权的 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. ``` 4. 验证: ``` beacon> shell whoami /groups | findstr TrustedInstaller NT SERVICE\TrustedInstaller Well-known group S-1-5-80-956008885-... Enabled by default, Enabled group, Group owner ``` 5. 完成后恢复: ``` beacon> rev2self ```
标签:BeaconUseToken, BOF, Cobalt Strike, DISM API, impersonation, NT AUTHORITY\SYSTEM, NtImpersonateThread, RFI远程文件包含, SCP, T-Pot, TrustedInstaller, Web报告查看器, Windows 安全, 令牌模拟, 免 SCM 检测, 协议分析, 客户端加密, 提权, 攻击诱捕, 数据展示, 权限提升, 欺骗防御, 私有化部署, 红队, 防御规避