CVE-2025-27135
Executive Summary
CVE-2025-27135 is a critical SQL injection vulnerability in RAGFlow, an open-source Retrieval-Augmented Generation (RAG) engine. The flaw resides in the ExeSQL component, which directly passes user-supplied SQL statements to the database without proper sanitization or parameterization. This allows an authenticated attacker to execute arbitrary SQL commands, potentially leading to data exfiltration, modification, or complete database compromise. As of the latest advisory, no patched version is available, leaving all deployments up to version 0.15.1 at risk.
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
RAGFlow is distributed as a Python package via PyPI. The vulnerability affects the core application logic, not a third-party dependency. However, the lack of a patch means that any organization using RAGFlow must consider the entire supply chain risk, including the potential for malicious forks or unofficial patches.
CVSS Breakdown & Threat Level
The CVSS score is listed as 0.0, which is likely a placeholder. Based on the nature of the vulnerability (SQL injection with direct database access), a realistic CVSS v3.1 vector would be:
- Attack Vector (AV): Network (N) – The vulnerability is exploitable over the network.
- Attack Complexity (AC): Low (L) – No special conditions are required.
- Privileges Required (PR): Low (L) – An attacker needs a valid user account.
- User Interaction (UI): None (N) – No user interaction is required.
- Scope (S): Unchanged (U) – The vulnerable component and the database are within the same security authority.
- Confidentiality (C): High (H) – Full database read access.
- Integrity (I): High (H) – Full database write access.
- Availability (A): High (H) – Potential for denial of service via destructive queries.
Estimated CVSS Vector: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
Estimated Base Score: 8.8 (High)
Threat Level: Critical. The vulnerability is easy to exploit, requires low privileges, and can lead to complete database compromise.
Deep Dive & Mechanics
The ExeSQL component in RAGFlow is designed to allow users to execute SQL queries against the backend database for data retrieval and analysis. The vulnerability arises because the component does not validate or sanitize the SQL statement provided by the user. Instead, it directly concatenates the user input into a database query string and executes it.
Root Cause: Lack of input validation and parameterized queries. The code likely uses string formatting or concatenation to build the SQL statement, making it susceptible to injection.
Attack Vector: An authenticated user sends a crafted HTTP request to the RAGFlow API endpoint that invokes the ExeSQL function. The request contains a malicious SQL payload in the sql parameter.
Example Payload:
SELECT * FROM users; DROP TABLE logs; --
Impact:
- Data Exfiltration: Attackers can extract sensitive data from any table in the database.
- Data Manipulation: Attackers can insert, update, or delete records.
- Privilege Escalation: If the database user has elevated privileges, attackers may gain administrative access.
- Denial of Service: Attackers can execute resource-intensive queries or drop tables.
Vulnerable vs. Patched Code
Vulnerable Code (RAGFlow <= 0.15.1):
# Vulnerable implementation
def execute_sql(sql_statement):
cursor = db_connection.cursor()
cursor.execute(sql_statement) # Direct execution without sanitization
return cursor.fetchall()
Patched Code (Hypothetical):
# Patched implementation using parameterized queries
def execute_sql(sql_statement):
# Validate and sanitize input
if not is_safe_sql(sql_statement):
raise ValueError("Unsafe SQL statement")
cursor = db_connection.cursor()
cursor.execute("SELECT * FROM allowed_table WHERE condition = %s", (sql_statement,))
return cursor.fetchall()
Note: As of the latest advisory, no official patch exists. The above is a recommended fix.
Exploitation & Lab Setup
Red Team (Offensive)
Prerequisites:
- A running instance of RAGFlow (version <= 0.15.1)
- Valid user credentials (low-privileged account)
- Network access to the RAGFlow API
Exploitation Steps:
Identify the vulnerable endpoint:
- The
ExeSQLcomponent is typically exposed via an API endpoint like/api/v1/execute_sql. - Use a tool like Burp Suite or curl to interact with the API.
- The
Craft the malicious payload:
- Inject a SQL statement that extracts data or performs unauthorized actions.
- Example:
' OR '1'='1' --
Send the request:
curl -X POST https://target-ragflow.com/api/v1/execute_sql \ -H "Authorization: Bearer <token>" \ -d '{"sql": "SELECT * FROM users; DROP TABLE logs; --"}'Verify exploitation:
- Check the response for data leakage or error messages indicating successful injection.
- Use time-based blind injection techniques if the application does not return results directly.
Automated Exploitation:
- Use SQLMap with the following command:
sqlmap -u "https://target-ragflow.com/api/v1/execute_sql" \ --data='{"sql": "test"}' \ --headers="Authorization: Bearer <token>" \ --dbms=mysql \ --batch
Blue Team (Defensive)
Detection and Response:
Monitor API logs:
- Look for unusual SQL statements in the
sqlparameter of requests to/api/v1/execute_sql. - Alert on patterns like
UNION,SELECT,DROP,INSERT,OR 1=1, etc.
- Look for unusual SQL statements in the
Implement Web Application Firewall (WAF) rules:
- Block requests containing SQL keywords in the
sqlparameter. - Example ModSecurity rule:
SecRule ARGS:sql "@rx (SELECT|INSERT|UPDATE|DELETE|DROP|UNION|OR 1=1)" \ "id:1001,phase:2,deny,status:403,msg:'SQL Injection Attempt'"
- Block requests containing SQL keywords in the
Database activity monitoring:
- Enable database audit logs to capture all queries.
- Alert on queries that deviate from expected patterns (e.g.,
SELECT * FROM users).
Network segmentation:
- Isolate the RAGFlow database from the public network.
- Use a read-only database user for the
ExeSQLcomponent.
Indicators of Compromise (IOCs)
Network IOCs:
- HTTP requests to
/api/v1/execute_sqlwith suspicioussqlparameters. - Outbound database connections from the RAGFlow server to unexpected IPs.
File IOCs:
- Modified log files in
/var/log/ragflow/containing SQL injection attempts. - Unusual entries in the database audit log.
Behavioral IOCs:
- Unauthorized data exports from the database.
- Sudden changes to database schema (e.g., dropped tables).
- High CPU or memory usage on the database server due to resource-intensive queries.
Detection Engineering
YARA Rule
rule CVE_2025_27135_SQL_Injection {
meta:
description = "Detects SQL injection attempts targeting RAGFlow ExeSQL component"
author = "Valters IT"
date = "2025-03-01"
cve = "CVE-2025-27135"
strings:
$sql_keywords = /(SELECT|INSERT|UPDATE|DELETE|DROP|UNION|OR 1=1|--|#)/
$api_endpoint = "/api/v1/execute_sql"
condition:
$api_endpoint and $sql_keywords
}
Sigma Rule
title: SQL Injection Attempt Against RAGFlow ExeSQL
id: 8a9b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d
status: experimental
description: Detects SQL injection attempts in HTTP requests to RAGFlow's ExeSQL endpoint
author: Valters IT
date: 2025-03-01
logsource:
category: webserver
product: apache
detection:
selection:
cs-method: 'POST'
cs-uri-stem: '/api/v1/execute_sql'
cs-uri-query|contains:
- 'SELECT'
- 'INSERT'
- 'UPDATE'
- 'DELETE'
- 'DROP'
- 'UNION'
- 'OR 1=1'
- '--'
- '#'
condition: selection
falsepositives:
- Legitimate use of SQL keywords in data analysis queries
level: high
Suricata Rule
alert http $HOME_NET any -> $EXTERNAL_NET any (
msg:"CVE-2025-27135 - SQL Injection Attempt Against RAGFlow ExeSQL";
flow:to_server,established;
content:"POST"; http_method;
content:"/api/v1/execute_sql"; http_uri;
pcre:"/(SELECT|INSERT|UPDATE|DELETE|DROP|UNION|OR 1=1|--|#)/i";
sid:1000001;
rev:1;
classtype:web-application-attack;
priority:1;
)
Remediation & Mitigation
Immediate Actions:
- Disable the ExeSQL component if not essential for business operations.
- Restrict access to the vulnerable endpoint using network ACLs or API gateways.
- Implement input validation on the
sqlparameter to allow only safe operations (e.g.,SELECTon specific tables).
Long-term Fixes:
- Apply parameterized queries to prevent SQL injection.
- Use a database user with minimal privileges (read-only, limited to specific tables).
- Monitor for official patches from the RAGFlow maintainers and apply them immediately.
Workaround:
- If the ExeSQL component is required, implement a whitelist of allowed SQL statements or use a stored procedure that validates input.
Valters IT