How to decrypt cookie?

泄露秘密 提交于 2019-12-03 08:16:22

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.

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