Skip to content

Potential arbitrary file write vulnerability #12

Description

@Fushuling

In the current code, if debug=true in the JDBC URL, the logfile parameter is directly created as a file path and opened as a FileWriter. The log content contains the raw bytes returned by the server (which can be partially controlled by the attacker).

Image

This means that if an attacker can control the JDBC URL, they can now write arbitrary files to any file path.

import java.sql.SQLException;

public class test {
    public static void main(String[] args) throws SQLException {
        String url = "jdbc:monetdb://127.0.0.1:50000/?debug=true&logfile=D:/test/aaa/1.jsp";
        java.sql.DriverManager.getConnection(url);
    }
}
Image

Modern JDBC drivers such as db2 and PostgreSQL have implemented measures to protect against this issue, for example, by restricting file extensions to .log. Therefore, I believe it is essential to restrict filenames to prevent attacks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions