CodeIgniter / Kohana PHP Object Injection / Timing Attack

ID 1337DAY-ID-22246
Type zdt
Reporter Scott Arciszewski
Modified 2014-05-14T00:00:00


CodeIgniter versions 2.1.4 and below and Kohana versions 3.2.3 and below and 3.3.2 and below suffer from PHP object injection, a timing attack, and a remote code execution vulnerability.

                                            Background info and boring history shit:

1. Remote timing attack
2. PHP Object Injection
3. Possibly, as a result of 2, remote code execution

- CodeIgniter (<= 2.1.4)
- Kohana (<= 3.2.3, 3.3.2)

Some PHP frameworks (CodeIgniter and Kohana, for sure), give you the option
of storing $_SESSION data in a cookie, then appending a hash of the session
data and an unknown key.

For example:


Vulnerability 1 - Remote Timing Attack

If you wanted to alter the above serialized blob to read:


... in theory, you would need to either know the encryption key stored in
the framework's configuration. And remotely brute-forcing an md5/sha1 hash
isn't really attractive.

Luckily, the behavior of standard string comparison operators (== and ===)
is to return false as soon as two bytes do not match. Thus we could
discover that...


...takes a little longer than...


... and then ...


... will take slightly longer.

Theoretically, if we need 100 samples per possible hexit to guess the
correct value through this strategy, and there are 32 hexits in a hash, at
10 request per second it will take 51200 samples to crack an md5 hash. If
you can guess 50 per second without bringing the target server to its
knees, that's about 18 minutes (worst case) to get the end result:


Vulnerability 2 - PHP Object Injection

If you can convince PHP to pass arbitrary data to unserialize(), which is
the automatic next step when the timing attack succeeds, then you can
inject objects into the code. From what I understand, this can also lead to
remote code execution.

CodeIgniter already patched this in its 3.0/develop branch.
Kohana accepted my pull request for its 3.3/develop branch:

Note: Kohana uses SHA1, not MD5, so add another 20% to my estimate.

# [2016-04-19]  #