Skip to content

SQL Injection in BSim Password Change Allows PostgreSQL Privilege Escalation

High
nsadeveloper789 published GHSA-vv7r-2rhf-5h7g May 14, 2026

Package

ghidra

Affected versions

>= 11.0

Patched versions

12.1

Description

Summary

The changePassword() method in PostgresFunctionDatabase interpolates the username directly into an ALTER ROLE SQL statement without escaping double quotes, allowing an authenticated BSim user to escalate to PostgreSQL superuser.

Details

In Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/PostgresFunctionDatabase.java lines 107-108:

buffer.append("ALTER ROLE \"");
buffer.append(username);

The username originates from the PasswordChange network protocol message. In PasswordChange.java:76:

username = el.getAttribute("username");

No validation or escaping is performed on the username. While the username is wrapped in double quotes in the SQL statement, double quote characters within the username are NOT escaped. A username containing " breaks out of the identifier quoting.

The password value IS escaped (single quotes doubled at lines 111-113), making the unescaped username an apparent oversight.

The data flow is:

  1. Network XML → BSimQuery.restoreXml() (BSimQuery.java:147-156)
    1. PasswordChange.restoreXml() (PasswordChange.java:75-76)
    1. username = el.getAttribute("username") (no validation)
    1. fdbPasswordChange() (PostgresFunctionDatabase.java:620)
    1. changePassword(c, query.username, ...) (line 620)
    1. buffer.append(username) (line 108, no escaping)
    1. st.executeUpdate(buffer.toString()) (line 121, executes injected SQL)

Impact

Any authenticated BSim user can escalate to PostgreSQL superuser, gaining full control over the database server. This includes reading all data, creating new roles, modifying system configuration, and potentially achieving operating system command execution via PostgreSQL's COPY PROGRAM or extension loading.

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H

CVE ID

No known CVE

Weaknesses

Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')

The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data. Learn more on MITRE.

Credits