The discovery, revealed during the DownUnderCTF 2025 capture-the-flag competition, demonstrates how attackers can exploit PDO’s query parsing mechanism to achieve code injection in seemingly bulletproof applications.
The vulnerability was first demonstrated in a challenging web exploitation problem called ‘legendary’ during the sixth edition of DownUnderCTF, which took place over the weekend.
The challenge, created by security researcher hashkitten, was solved by only a single team, highlighting its sophisticated nature.
The technique leverages a previously unknown weakness in how PHP’s PDO library handles prepared statement emulation, particularly when parsing SQL queries containing null bytes.
The researcher explained that PDO doesn’t use MySQL’s native prepared statement API by default.
Instead, it emulates prepared statements by implementing its own SQL parser to identify bound parameters while avoiding interference from comments, strings, and table names.
This parser, however, contains critical flaws that can be exploited under specific circumstances.
The attack works by exploiting how PDO’s parser handles null bytes () within SQL queries.
When a null byte is encountered in what should be a table or column name surrounded by backticks, the parser becomes confused and misidentifies subsequent question marks as bound parameters.
A proof-of-concept payload demonstrates this: ?#%00 Injecting a column name parameter causes PDO to treat the question mark as a bound parameter rather than literal text.
The attack chain involves constructing payloads like:
sqlSELECT `?#` FROM fruit WHERE name = ?
After PDO processing, this becomes:
sqlSELECT `'injected_payload';#` FROM fruit WHERE name = ?
The technique is particularly dangerous because it affects scenarios where developers correctly escape user input for column names using standard methods like replacing backticks with double backticks (`` → “`), which should theoretically prevent injection.
The vulnerability affects MySQL by default since PDO emulation is enabled automatically. PostgreSQL becomes vulnerable when developers explicitly enable PDO::ATTR_EMULATE_PREPARES => true, a common performance optimization.
Surprisingly, older PHP versions (8.3 and earlier) are significantly more vulnerable due to their unified parser design, which incorrectly assumes all databases support backslash escaping.
Security researchers recommend immediately disabling PDO::ATTR_EMULATE_PREPARES where possible, upgrading to PHP 8.4, and implementing strict input validation that rejects null bytes.
The discovery highlights how seemingly secure coding practices can harbor unexpected vulnerabilities when underlying libraries make incorrect assumptions about query parsing.
This revelation underscores the importance of defense-in-depth strategies and regular security audits of even the most trusted database interaction methods.
Find this Story Interesting! Follow us on Google News, LinkedIn, and X to Get More Instant updates
The post PHP PDO Flaw Allows Hackers to Inject Malicious SQL appeared first on Cyber Security News.
INDIANAPOLIS (AP) — Felix Rosenqvist swung to the outside of David Malukas, then found a…
INDIANAPOLIS (AP) — Felix Rosenqvist swung to the outside of David Malukas, then found a…
Nicolas Cage has said that The Odyssey director Christopher Nolan is on the list of…
Sebastian Stan obliquely addressed his casting in The Batman: Part II while promoting his Palme…
Idris Elba isn't just taking himself out of the running to play James Bond in…
Karmine Corp, the French Esports team who’s reached the semifinals in the last two Rocket…
This website uses cookies.