How to decrypt a cookie?

I just found a message about failures in the sentinel, I'm trying to debug and see the cause of the problem.

Fortunately, in the cookie panel, I see the value laravel_sessionthat was used during the crash.

The question is, how can I decrypt a cookie?

+4
source share
1 answer

You can decrypt the cookie with the following code:

    $cookie = 'eyJpdiI6ImFUQ0FvMWFSVlNvTmhlQjdLWGw1Z1E9PSIsInZhbHVlIjoicFh6Q09iTDl0K0huWU1Nc1NYVmxSY2hPRGU5Vk85dDJyYUpRbUVjRWg5R0JxYkVobkF3YkZVcVQrakFFUmxaVnZrTjFST3F3RTZ4akpDZEpvUFJiQXc9PSIsIm1hYyI6IjlhYmJhMTY3MWMxYWI3YjJmNmFjMmNkZWE0MWZmMmVhNTNiMjI5ZWY3NzUwNzQ0ZjAzMGQ1ZGU0YzVhNjJmZGYifQ==';
    $cookie_contents = json_decode( base64_decode( $cookie, true ));
    $value = base64_decode( $cookie_contents->value );
    $iv = base64_decode( $cookie_contents->iv );
    $clear = unserialize( \openssl_decrypt($value, \Config::get( 'app.cipher' ), \Config::get( 'app.key' ), OPENSSL_RAW_DATA, $iv));
    echo "Cookie contents (Session ID): $clear\n";

You’ll end up with a session ID that looks something like this:

  • Laravel 5.1: 55782b00dbfcc3f848585ac2cefc66802d773cf5
  • Laravel 5.4: yPjeV74joY4MtMNNtTpeOYBP2CMixJBBChc9HRND

I have not tested Laravel 5.3, but I am sure it will work.

, cookie $cookie, .

+3

Source: https://habr.com/ru/post/1684653/


All Articles