自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

PHP Composer漏洞可能引發(fā)供應(yīng)鏈攻擊

安全 漏洞
​研究人員在PHP Composer中發(fā)現(xiàn)一個(gè)安全漏洞,攻擊者利用該漏洞可以發(fā)起供應(yīng)鏈攻擊。

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

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

漏洞分析

在請求下載包時(shí),Composer 首先會查詢Packagist來獲取元數(shù)據(jù)。元數(shù)據(jù)中包含2個(gè)獲取代碼源的域source和dist。Source只想開發(fā)庫,dist只想預(yù)構(gòu)建的庫。Composer在從庫中下載代碼時(shí)會使用外部系統(tǒng)命令來避免重新實(shí)現(xiàn)針對每隔版本控制軟件的邏輯。因此,這些調(diào)用都是用wrapper ProcessExecutor來執(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ū)動中執(zhí)行的,版本控制軟件負(fù)載原創(chuàng)和本地庫的所有操作。比如,在Git驅(qū)動中:

  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ù)防子命令($(...), `...`) ,但是無法預(yù)防用戶提供(--)開頭的值,只要加上其他的參數(shù)就可以成為最終的命令。這類漏洞就叫做參數(shù)注入。

類似的有漏洞的模式也出現(xiàn)在其他驅(qū)動中,用戶控制的數(shù)據(jù)可以成功繞過檢查并連接在一起成為系統(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é)參見: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

 

責(zé)任編輯:趙寧寧 來源: 嘶吼網(wǎng)
相關(guān)推薦

2023-07-19 12:04:55

2021-11-23 14:54:05

漏洞供應(yīng)鏈攻擊網(wǎng)絡(luò)攻擊

2021-04-25 15:49:06

拜登黑客攻擊

2022-04-06 10:12:51

Go供應(yīng)鏈攻擊風(fēng)險(xiǎn)

2017-11-08 09:39:11

供應(yīng)鏈消費(fèi)升級CIO

2023-02-23 07:52:20

2022-04-13 14:49:59

安全供應(yīng)鏈Go

2021-09-12 14:38:41

SolarWinds供應(yīng)鏈攻擊Autodesk

2020-06-01 08:45:17

GitHub代碼開發(fā)者

2022-03-14 14:37:53

網(wǎng)絡(luò)攻擊供應(yīng)鏈攻擊漏洞

2021-09-16 14:59:18

供應(yīng)鏈攻擊漏洞網(wǎng)絡(luò)攻擊

2020-12-24 11:09:44

VMwareCiscoSolarWinds

2021-10-14 13:14:12

安全供應(yīng)鏈漏洞威脅

2024-01-19 21:51:42

2023-01-11 00:05:58

2022-02-21 10:12:20

供應(yīng)鏈攻擊網(wǎng)絡(luò)攻擊

2023-11-06 07:11:14

2024-04-25 12:54:05

2022-07-18 17:00:00

網(wǎng)絡(luò)安全數(shù)據(jù)供應(yīng)鏈

2023-11-02 12:13:08

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號