Summary
WeGIA versions 3.6.5 and below contain an authenticated SQL injection vulnerability in the html/matPat/restaurar_produto.php endpoint, where the id_produto GET parameter is interpolated directly into SQL queries.
An authenticated attacker who can access this endpoint may inject arbitrary SQL commands, potentially leading to full database compromise and exposure or modification of sensitive institutional data.
Affected context
This vulnerability appears in WeGIA deployments (version 3.6.5 and below) where:
- Users can authenticate and reach the
html/matPat/restaurar_produto.phpscript - The application runs with a database account that has broad privileges on the schema
- Input from the
id_produtoGET parameter is processed by the backend without additional filtering or protections at the web server or WAF level
In such configurations, the trusted, authenticated context of the application becomes a conduit for attacker-controlled SQL.
Exploit preconditions
- Attack surface: HTTP(S) interface to the
html/matPat/restaurar_produto.phpendpoint. - Required access: Valid authenticated user account with permission to invoke the affected functionality.
- Input vector: The
id_produtoparameter supplied via the URL query string ($_GET). - Trigger point: Execution of the SQL queries in
restaurar_produto.phpthat interpolateid_produtodirectly into SQL strings. - Why exploitation is possible: The parameter is taken directly from
$_GETand concatenated into SQL without sanitization, type-casting, or parameterized queries, allowing attacker-controlled SQL syntax to be executed by the database engine.
Why this happens
The core issue is the direct concatenation of user-supplied input into SQL statements, mapping to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
In restaurar_produto.php, the id_produto value from $_GET is trusted as-is and embedded into two SQL query strings without:
- Using prepared statements with bound parameters
- Enforcing numeric type-casting for what appears to be an identifier
- Applying server-side validation or encoding
This pattern allows the attacker to alter the structure of the SQL queries themselves, rather than only influencing data values, resulting in arbitrary SQL execution under the application's database privileges.
Potential impact
- Full read access to database tables, which may expose sensitive donor, beneficiary, or operational data.
- Unauthorized modification or deletion of records, potentially disrupting charitable operations and reporting.
- Creation or modification of application-level accounts or roles stored in the database.
- Escalation of privileges within the application if authorization logic relies on database-stored flags or roles.
- Potential pivot to underlying infrastructure if database features (e.g., file access, stored procedures) are misconfigured and overly powerful.
General mitigation guidance
Effective mitigation focuses on eliminating string-concatenated SQL and tightening trust boundaries around user input:
- Replace dynamic SQL concatenation with parameterized queries / prepared statements for all database interactions, especially where user input is involved.
- Enforce strict server-side validation and type constraints for identifiers such as
id_produto, ensuring only expected numeric formats are accepted. - Centralize database access patterns in a data access layer that enforces parameter binding and discourages ad-hoc SQL construction.
- Apply least-privilege principles to the application's database account, limiting its ability to perform destructive or administrative operations.
- Consider adding a web application firewall (WAF) or reverse proxy with rules to detect and block obvious SQL injection patterns, as a defense-in-depth measure rather than a primary fix.
How teams detect issues like this
Organizations can use multiple approaches to detect this class of vulnerability:
- Static analysis: Configure SAST tools or linters to flag direct concatenation of
$_GET,$_POST, and other request-derived variables into SQL strings, and to enforce the use of prepared statements. - Code review: During manual reviews, treat any dynamic SQL construction as high risk; look specifically for query-building patterns in PHP files that reference superglobals and lack clear parameter binding.
- Dynamic testing: Employ DAST tools or targeted penetration tests that inject SQL meta-characters into parameters like
id_produtoand monitor for database errors, anomalous responses, or data leakage. - Logging and monitoring: Enable detailed application and database logging to spot unexpected query patterns, syntax errors driven by user input, or spikes in failed queries involving the vulnerable endpoint.

