HackTheBox - PersistenceIsFutile
- Challenge Scenario
Hackers made it onto one of our production servers 😅. We’ve isolated it from the internet until we can clean the machine up. The IR team reported eight difference backdoors on the server, but didn’t say what they were and we can’t get in touch with them. We need to get this server back into prod ASAP - we’re losing money every second it’s down. Please find the eight backdoors (both remote access and privilege escalation) and remove them. Once you’re done, run /root/solveme as root to check. You have SSH access and sudo rights to the box with the connections details attached below. username: user password: hackthebox
1 |
|
Recon & Exploit
非常喜歡這一題,練習很多linux面向的persistent
1 |
|
可以看到有一個奇怪的elf檔案(.backdoor),所以就dump到本機的電腦逆一下裡面寫什麼
1 |
|
惡意alias
從以上的關鍵字會發現bashrc和環境變數可能有問題
1 |
|
從以上的bashrc內容看得出來cat被alias成惡意的操作,所以我直接看所有的alias,發現真的只有$ cat這個惡意command,所以直接把這個alias註解掉
1 |
|
查看root
1 |
|
會看到這行命令會啟動一個 daemon (alertd)這個某個command其實沒看過,所以合理懷疑應該是惡意的command,而這個command的實際elf file在/usr/bin中
- 監聽 4444 port
- 當有人連進來時,啟動一個 bash shell
- 背景執行,達到 遠端控制 / 反彈 shell
把該檔案刪除並且把該command註解掉
1 |
|
惡意的排程任務
這也是linux persistent的起手式
1 |
|
果然看到奇怪的東西,把這個排程取消掉
1 |
|
ssh public key authorized
另外,也看一下系統級的cron有什麼問題
1 |
|
有問題的是pyssh和/etc/cron.daily/access-up這兩個腳本
1 |
|
這兩個檔案在做的事情不一樣,前者主要是觸發ssh的python library,後者則是更改UUID,先看前者在做什麼
1 |
|
實際decode會發現就是把ssh public key寫入授權的key list,讓持有對應私鑰的人可以直接 SSH 登入 root,不需要密碼,把這個檔案刪除並且修改ssh authorized key file
1 |
|
惡意的其他後門
接著看第二個檔案在做的事情是將/bin/bash複製到一些隨機的檔案路徑,並賦予SUID檔案屬性。所以難的地方就是那些隨機的filename是什麼,這個部分我是參考1的紀錄
1 |
|
把這些檔案刪除
惡意的process
1 |
|
實際看/var/lib/private/connectivity-check寫了什麼發現是一個reverse shell,所以要把這個process kill掉並且把檔案刪除
另外,這個檔案是由誰或什麼execute
1 |
|
所以也要把這個檔案刪除
查看/etc/passwd - 通靈
這個也是參考1的說明,發現gnats這個user的GID被改成root,而且shell被改成/bin/bash
1 |
|