日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢(xún)
選擇下列產(chǎn)品馬上在線(xiàn)溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
PHP Composer漏洞可能引發(fā)供應(yīng)鏈攻擊

Composer是PHP中管理和安全軟件依賴(lài)的主要工具,被開(kāi)發(fā)團(tuán)隊(duì)廣泛應(yīng)用于更新過(guò)程等。因此,Composer使用名為Packagist 的在線(xiàn)服務(wù)來(lái)確定包下載供應(yīng)鏈的正確性。而Packagist每個(gè)月的下載請(qǐng)求在14億次左右。

研究人員在進(jìn)行安全研究時(shí),在 Packagist使用的Composer源碼中發(fā)現(xiàn)了一個(gè)嚴(yán)重的安全漏洞,漏洞CVE編號(hào)為CVE-2021-29472。攻擊者利用該漏洞可以在Packagist.org 服務(wù)器上執(zhí)行任意系統(tǒng)命令。此外,攻擊者還可以進(jìn)一步竊取維護(hù)者憑證,或?qū)螺d重定向到傳播后門(mén)依賴(lài)的第三方服務(wù)器。

漏洞分析

在請(qǐng)求下載包時(shí),Composer 首先會(huì)查詢(xún)Packagist來(lái)獲取元數(shù)據(jù)。元數(shù)據(jù)中包含2個(gè)獲取代碼源的域source和dist。Source只想開(kāi)發(fā)庫(kù),dist只想預(yù)構(gòu)建的庫(kù)。Composer在從庫(kù)中下載代碼時(shí)會(huì)使用外部系統(tǒng)命令來(lái)避免重新實(shí)現(xiàn)針對(duì)每隔版本控制軟件的邏輯。因此,這些調(diào)用都是用wrapper ProcessExecutor來(lái)執(zhí)行的:

 
 
 
  1. composer/src/Composer/Util/ProcessExecutor.php 
  2.   
  3. use Symfony\Component\Process\Process; 
  4. // [...] 
  5. class ProcessExecutor 
  6.     // [...] 
  7.     public function execute($command, &$output = null, $cwd = null) 
  8.     { 
  9.         if (func_num_args() > 1) { 
  10.             return $this->doExecute($command, $cwd, false, $output); 
  11.         } 
  12.         return $this->doExecute($command, $cwd, false); 
  13.     } 
  14.     // [...] 
  15.     private function doExecute($command, $cwd, $tty, &$output = null) 
  16.     { 
  17.         // [...] 
  18.         if (method_exists('Symfony\Component\Process\Process', 'fromShellCommandline')) { 
  19.             // [1] 
  20.             $process = Process::fromShellCommandline($command, $cwd, null, null, static::getTimeout()); 
  21.         } else { 
  22.             // [2] 
  23.             $process = new Process($command, $cwd, null, null, static::getTimeout()); 
  24.         } 
  25.         if (!Platform::isWindows() && $tty) { 
  26.             try { 
  27.                 $process->setTty(true); 
  28.             } catch (RuntimeException $e) { 
  29.                 // ignore TTY enabling errors 
  30.             } 
  31.         } 
  32.         $callback = is_callable($output) ? $output : array($this, 'outputHandler'); 
  33.         $process->run($callback); 

在 [1]和[2]中,可以看到參數(shù) $command 是在shell中執(zhí)行的。大多數(shù)的ProcessExecutor 調(diào)用都是在版本控制軟件驅(qū)動(dòng)中執(zhí)行的,版本控制軟件負(fù)載原創(chuàng)和本地庫(kù)的所有操作。比如,在Git驅(qū)動(dòng)中:

 
 
 
  1. composer/src/Composer/Repository/Vcs/GitDriver.php 
  2.   
  3. public static function supports(IOInterface $io, Config $config, $url, $deep = false) 
  4.     if (preg_match('#(^git://|\.git/?$|git(?:olite)?@|//git\.|//github.com/)#i', $url)) { 
  5.         return true; 
  6.     } 
  7.     // [...] 
  8.     try { 
  9.         $gitUtil->runCommand(function ($url) { 
  10.             return 'git ls-remote --heads ' . ProcessExecutor::escape($url); // [1] 
  11.         }, $url, sys_get_temp_dir()); 
  12.     } catch (\RuntimeException $e) { 
  13.         return false; 
  14.     } 

使用ProcessExecutor::escape() 可以將參數(shù)$url 逃逸以預(yù)防子命令($(...), `...`) ,但是無(wú)法預(yù)防用戶(hù)提供(--)開(kāi)頭的值,只要加上其他的參數(shù)就可以成為最終的命令。這類(lèi)漏洞就叫做參數(shù)注入。

類(lèi)似的有漏洞的模式也出現(xiàn)在其他驅(qū)動(dòng)中,用戶(hù)控制的數(shù)據(jù)可以成功繞過(guò)檢查并連接在一起成為系統(tǒng)命令:

 
 
 
  1. composer/src/Composer/Repository/Vcs/SvnDriver.php 
  2. public static function supports(IOInterface $io, Config $config, $url, $deep = false) 
  3.     $url = self::normalizeUrl($url); 
  4.     if (preg_match('#(^svn://|^svn\+ssh://|svn\.)#i', $url)) { 
  5.         return true; 
  6.     } 
  7.     // [...] 
  8.     $process = new ProcessExecutor($io); 
  9.     $exit = $process->execute( 
  10.         "svn info --non-interactive ".ProcessExecutor::escape($url), 
  11.         $ignoredOutput 
  12.     ); 
  13. composer/src/Composer/Repository/Vcs/HgDriver.php 
  14. public static function supports(IOInterface $io, Config $config, $url, $deep = false) 
  15.     if (preg_match('#(^(?:https?|ssh)://(?:[^@]+@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i', $url)) { 
  16.         return true; 
  17.     } 
  18.     // [...] 
  19.     $process = new ProcessExecutor($io); 
  20.     $exit = $process->execute(sprintf('hg identify %s', ProcessExecutor::escape($url)), $ignored); 
  21.     return $exit === 0; 

更多技術(shù)細(xì)節(jié)參見(jiàn):https://blog.sonarsource.com/php-supply-chain-attack-on-composer

補(bǔ)丁

研究人員將該漏洞提交給Packagist團(tuán)隊(duì)后,該團(tuán)隊(duì)快速反應(yīng),在12個(gè)小時(shí)內(nèi)就部署了安全補(bǔ)丁。

本文翻譯自:https://blog.sonarsource.com/php-supply-chain-attack-on-composer


新聞標(biāo)題:PHP Composer漏洞可能引發(fā)供應(yīng)鏈攻擊
分享鏈接:http://www.dlmjj.cn/article/cdseopd.html