PyTorch機(jī)器學(xué)習(xí)框架遭遇惡意依賴供應(yīng)鏈鏈攻擊。
與Keras 和 TensorFlow類似,PyTorch是基于Python/ target=_blank class=infotextkey>Python的開(kāi)源機(jī)器學(xué)習(xí)框架。PyTorch廣泛用于計(jì)算機(jī)視覺(jué)和自然語(yǔ)言處理任務(wù)。12月31日,PyTorch團(tuán)隊(duì)稱其發(fā)現(xiàn)了PyTorch中的惡意依賴,受到供應(yīng)鏈攻擊。
供應(yīng)鏈攻擊
PyTorch團(tuán)隊(duì)識(shí)別出了一個(gè)與PyTorch框架'torchtriton'庫(kù)名字一樣的惡意依賴。攻擊者在PyPI中上傳了一個(gè)與torchtriton'庫(kù)名字一樣的惡意依賴庫(kù),實(shí)現(xiàn)了供應(yīng)鏈攻擊。因此,攻擊者可以通過(guò)依賴攻擊向量來(lái)識(shí)別成功入侵開(kāi)源學(xué)習(xí)框架。
惡意torchtriton庫(kù)的主要功能包括:
獲取系統(tǒng)信息:
來(lái)自/etc/resolv.conf 的nameservers;
來(lái)自gethostname() 的hostname;
來(lái)自getlogin() 的當(dāng)前 username;
來(lái)自getcwd() 的當(dāng)前working directory name。
環(huán)境變量;
讀取系統(tǒng)文件:
/etc/hosts
/etc/passwd
$HOME/*
$HOME/.gitconfig
$HOME/.ssh/*
并通過(guò)到域名*.h4ck[.]cfd的加密的DNS查詢來(lái)上傳包括文件內(nèi)容在內(nèi)的以上信息,使用的DNS服務(wù)器為wheezy[.]io。文件上傳功能的文件大小限制為99999字節(jié),還會(huì)上傳$HOME 目錄的前1000個(gè)文件。
修復(fù)補(bǔ)丁
PyTorch團(tuán)隊(duì)建議通過(guò)2022年12月25日到12月30日之間通過(guò)pip安裝PyTorch的用戶,盡量卸載torchtriton和PyTorch,并使用12月30日之后的最新版本。卸載惡意依賴庫(kù)的命令如下:
$ pip3 uninstall -y torch torchvision torchaudio torchtriton$ pip3 cache purge
PyTorch團(tuán)隊(duì)已經(jīng)將'torchtriton'庫(kù)重命名為'pytorch-triton'以預(yù)防潛在的類似攻擊。
圖 PyTorch重命名'torchtriton'庫(kù)
此外,用戶還可以通過(guò)以下命令來(lái)確定是否受到該供應(yīng)鏈攻擊的影響:
python3 -c "import pathlib;import importlib.util;s=importlib.util.find_spec('triton');affected=any(x.name == 'triton' for x in (pathlib.Path(s.submodule_search_locations[0]if s is not None else '/' ) / 'runtime').glob('*'));print('You are {}affected'.format('' if affected else 'not '))"
截止2021年12月31日,BleepingComputer發(fā)現(xiàn)惡意'torchtriton' 依賴在上傳一周內(nèi)已經(jīng)下載超過(guò)2300次。
https://pytorch.org/blog/compromised-nightly-dependency/#how-to-check-if-your-python-environment-is-affected
參考及來(lái)源:https://www.bleepingcomputer.com/news/security/pytorch-discloses-malicious-dependency-chain-compromise-over-holidays/