How to decrypt cookie?

对着背影说爱祢 提交于 2019-12-09 05:53:09

问题


I've just caught a crash reported on sentry, I am trying to debug and see the root cause for the problem.

Luckily, in the cookies panel, I can see the laravel_session value that was used while crash happened.

The question, is, how can decrypt the cookie?


回答1:


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 should end up with a session ID that looks something like this:

  • Laravel 5.1: 55782b00dbfcc3f848585ac2cefc66802d773cf5
  • Laravel 5.4: yPjeV74joY4MtMNNtTpeOYBP2CMixJBBChc9HRND

I didn't test with Laravel 5.3, but I'm confident it will work.

When using this code, make sure you paste the entire contents of the cookie into the $cookie variable, including the two equals signs at the end.



来源:https://stackoverflow.com/questions/45932817/how-to-decrypt-cookie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!