text
stringlengths
0
1.99k
// 6
if (! $user = $this->persistences->findUserByPersistenceCode(code)) {
return false;
}
if (! $this->cycleCheckpoints('check', $user)) {
return false;
}
return $this->user = $user;
}
...........................................................................
At (1) the code calls check() on the persistences object. Inside of
cartalyst/sentinel/src/Persistences/IlluminatePersistenceRepository.php,
we find:
...........................................................................
public function check()
{
if ($code = $this->session->get()) {
return $code;
}
if ($code = $this->cookie->get()) { // 2
return $code;
}
}
...........................................................................
We don't care about the session because we don't control that, but at (2)
it grabs the cookie.
Since we implemented Sentinel using the native interface (without
integrating with Laravel) then it will use the NativeCookie class located
in cartalyst/sentinel/src/Cookies/NativeCookie.php:
...........................................................................
public function get()
{
return $this->getCookie(); // 3
}
...snip...
/**
* Returns a PHP cookie.
*
* @return mixed
*/
protected function getCookie()
{
if (isset($_COOKIE[$this->options['name']])) {
$value = $_COOKIE[$this->options['name']]; // 4
if ($value) {
return json_decode($value); // 5
}
}
}
...........................................................................
At (3) the code calls getCookie, then at (4) the code attempts to grab
the cookie. The default cookie name is 'cartalyst_sentinel' as seen below,
but it can be overwritten in the Sentinel's config file at
cartalyst/sentinel/src/config/config.php:
...........................................................................
class NativeCookie implements CookieInterface
{
/**
* The cookie options.
*
* @var array
*/
protected $options = [
'name' => 'cartalyst_sentinel',
'domain' => '',
'path' => '/',
'secure' => false,
'http_only' => false,
];
...........................................................................
At (5) a curious thing occurs, a call to json_decode() happens on the
attacker provided cookie. json_decode() can return different types
depending on the provided input:
...........................................................................
researcher@venus:~/sentinel$ php -r 'var_dump(json_decode("\"1\""));'
string(1) "1"
researcher@venus:~/sentinel$ php -r 'var_dump(json_decode("1"));'
int(1)
researcher@venus:~/sentinel$ php -r 'var_dump(json_decode("[1]"));'
array(1) {
[0]=>
int(1)
}
researcher@venus:~/sentinel$ php -r
'var_dump(json_decode("{\"a\":\"b\"}"));'
object(stdClass)#1 (1) {