|
<?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; |
|
} |
|
} |