CVE-2024-11958
📋 TL;DR
A critical SQL injection vulnerability in the duckdb_retriever component of run-llama/llama_index allows attackers to execute arbitrary SQL commands. This can lead to remote code execution by installing malicious extensions and executing system commands. Anyone using the vulnerable component in llama_index is affected.
💻 Affected Systems
- run-llama/llama_index
📦 What is this software?
Llamaindex by Llamaindex
⚠️ Risk & Real-World Impact
Worst Case
Full system compromise via remote code execution, data exfiltration, and complete control over the database and underlying server.
Likely Case
Data theft, data manipulation, privilege escalation, and potential lateral movement within the environment.
If Mitigated
Limited to SQL injection impacts without RCE if shellfs extension is disabled or proper input validation is implemented.
🎯 Exploit Status
Exploit details are publicly available in the huntr.com bounty report. The SQL injection can be chained with shellfs extension installation for RCE.
🛠️ Fix & Mitigation
✅ Official Fix
Patch Version: Commit 35bd221e948e40458052d30c6ef2779bc965b6d0 and later
Vendor Advisory: https://github.com/run-llama/llama_index/commit/35bd221e948e40458052d30c6ef2779bc965b6d0
Restart Required: No
Instructions:
1. Update to the latest version of llama_index. 2. Ensure commit 35bd221e948e40458052d30c6ef2779bc965b6d0 is included. 3. Replace vulnerable duckdb_retriever usage with the patched version.
🔧 Temporary Workarounds
Disable shellfs extension
allPrevents RCE by disabling the extension that allows command execution
ALTER DATABASE DETACH shellfs;
DROP EXTENSION shellfs;
Input validation wrapper
allImplement strict input validation for all user inputs passed to duckdb_retriever
🧯 If You Can't Patch
- Implement network segmentation to isolate the vulnerable component from critical systems
- Deploy a web application firewall (WAF) with SQL injection protection rules
🔍 How to Verify
Check if Vulnerable:
Check if your code uses duckdb_retriever without parameterized queries. Review the specific commit hash in your installation.
Check Version:
git log --oneline | grep -i '35bd221e' or check package version in requirements.txt
Verify Fix Applied:
Verify that commit 35bd221e948e40458052d30c6ef2779bc965b6d0 is present in your codebase and that SQL queries now use parameterized statements.
📡 Detection & Monitoring
Log Indicators:
- Unusual SQL queries with shell commands
- Installation of shellfs extension
- Multiple failed SQL injection attempts
Network Indicators:
- Unexpected database connections
- Unusual outbound traffic from database server
SIEM Query:
SELECT * FROM logs WHERE message LIKE '%shellfs%' OR message LIKE '%UNION SELECT%' OR message LIKE '%EXEC%'