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:
- Network XML →
BSimQuery.restoreXml() (BSimQuery.java:147-156)
-
- →
PasswordChange.restoreXml() (PasswordChange.java:75-76)
-
- →
username = el.getAttribute("username") (no validation)
-
- →
fdbPasswordChange() (PostgresFunctionDatabase.java:620)
-
- →
changePassword(c, query.username, ...) (line 620)
-
- →
buffer.append(username) (line 108, no escaping)
-
- →
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.
Summary
The
changePassword()method inPostgresFunctionDatabaseinterpolates the username directly into anALTER ROLESQL 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.javalines 107-108:The username originates from the
PasswordChangenetwork protocol message. InPasswordChange.java:76: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:
BSimQuery.restoreXml()(BSimQuery.java:147-156)PasswordChange.restoreXml()(PasswordChange.java:75-76)username = el.getAttribute("username")(no validation)fdbPasswordChange()(PostgresFunctionDatabase.java:620)changePassword(c, query.username, ...)(line 620)buffer.append(username)(line 108, no escaping)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.