Skip to content

Instantly share code, notes, and snippets.

@jyxjjj
Created May 20, 2024 03:06
Show Gist options
  • Save jyxjjj/d261fdaab3f05143fab6e362e2f97822 to your computer and use it in GitHub Desktop.
Save jyxjjj/d261fdaab3f05143fab6e362e2f97822 to your computer and use it in GitHub Desktop.
<?php /** @noinspection PhpComposerExtensionStubsInspection */
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Process;
use SQLite3;
class DecryptChromeCookies extends Command
{
protected $signature = 'DecryptChromeCookies';
protected $description = '';
public function handle(): int
{
$password = Process::run('security find-generic-password -w -s "Chrome Safe Storage"');
$password = trim($password->output());
$iv = str_repeat(b' ', 16);
$user = Process::run('whoami');
$user = trim($user->output());
$db = new SQLite3("/Users/$user/Library/Application Support/Google/Chrome/Default/Cookies");
/** @noinspection SqlResolve */
$query = 'SELECT `name`, `encrypted_value` FROM `cookies` WHERE `host_key` = ".bilibili.com" ORDER BY `name`';
$result = $db->query($query);
$ciphers = [];
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$ciphers[$row['name']] = $row['encrypted_value'];
}
$db->close();
$hash = openssl_pbkdf2($password, b'saltysalt', 16, 1003);
$payload = [];
foreach ($ciphers as $name => $cipher) {
$cipher = substr($cipher, 3);
$payload[$name] = openssl_decrypt($cipher, 'aes-128-cbc', $hash, OPENSSL_RAW_DATA, $iv);
}
$cookie = http_build_query($payload, '', '; ');
dump($cookie);
return self::SUCCESS;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment