[php<=5.4.3] Parsing Bug in PHP PDO prepared statements may lead to
access violation
Affected Product: PHP
Affected Component: PDO - PHP Data Objects
Affected Versions: <=5.4.3 (latest version and trunk)
PHP Bug Ref: #61755
Patch: bug61755.diff
Discovery Date: Feb 2012
Advisory Date: 2012-06-10
Inconsistent parsing of PHP PDO prepared statements. Erroneous design
of parsers
state machine. Under special circumstances parsing of prepared statements does
not stop leading in cycling the whole stack without terminating on \0. This
leads to access violations, accessing of stack data, DoS.
There are several design errors in the state-machine responsible for
parsing PHP
PDO based statement objects. These errors are based on the state-machines
inability to consistently check the supplied SQL-Query. Under special
circumstances an attacker is able to force the responsible PDO code to iterate
beyond the termination of the supplied query string resulting in a
buffer out of
bounds access. This access may lead to uncontrollable as well as attacker
controllable behavior and Access Violations caused by the code iterating the
whole stack and trying to access addresses beyond the stack end. In
very unlikely
and constructed environments it may also be possible to force
parameter rebinding
of prepared statements - even though some context specific input
filtering is applied -
by utilizing the stack cycling behavior of the state machine.
This can be accomplished by 1) pushing a manipulated SQL string containing fake
parameter bindings (:named:, ?) onto the stack (e.g. using post variables)
2) manipulating the main SQL query string (see preconditions) to make
the pdo_parser
cycle the stack 3) until it cycles into the fake query previously
pushed to stack where
the magic happens. This forces the state machine into cycling into
random stack data
and then into the previously pushed manipulated SQL string with fake
parameter bindings.
To finalize this attack the manipulated SQL string then terminates the
SQL parsing
resulting in rebinding of prepared parameters. The attacker needs to
know the original
binding names (for named parameters) and the number of bound params
for this attack
to succeed. This scenario is unlikely to occur but as usual in
computer security this may
be used in conjunction with other attacks to multiply the impact.
State-Machine Graph, Test-Scripts, Traces, PoCs are available.
Discovered by 0x721427D8 via BeyondSecurity - SecuriTeam Secure Disclosure
http://php.net/
http://www.php.net/manual/en/intro.pdo.php
http://svn.php.net/viewvc/php/php-src/trunk/ext/pdo/
http://www.securiteam.com/