解码 Cookie
解密并验证现有 Cookie伪造 Cookie
生成有效的已签名 Laravel Cookie工作原理
Laravel encrypts cookies using AES-256-CBC (or AES-128-CBC / GCM variants) with the APP_KEY from your .env file. The encrypted value is base64-encoded JSON containing an IV, the ciphertext, and an HMAC-SHA256 signature. This tool decrypts and verifies the signature or forges a new valid cookie from scratch. Both operations happen server-side in PHP without storing any input.
- 1. Get the cookie: intercept the target request in Burp Suite or browser DevTools and copy the laravel_session cookie value.
- 2. Get the APP_KEY: find it in the target .env, a leaked config, or crack it from known plaintext.
- 3. Decode: paste both above and decode to reveal the session payload (user ID, CSRF token, flash data).
- 4. Modify & forge: change the payload (e.g. elevate user_id), paste the APP_KEY and forge a new valid signed cookie.
- 5. Inject: replace the original cookie in your request and resend.
什么是 Laravel 加密 Cookie?
Laravel automatically encrypts and signs all cookies set via Cookie::make() or the cookie helper (unless excluded via $except in EncryptCookies middleware). The session cookie (laravel_session by default) uses the cookie session driver only when SESSION_DRIVER=cookie, otherwise it contains just an encrypted session ID pointer. In CTF challenges, apps frequently use the cookie driver to store the full session payload directly in the cookie.
iv
Initialisation Vector. Randomly generated for each encryption operation. Base64-encoded inside the JSON payload.
value
The AES-encrypted ciphertext. Base64-encoded. openssl_encrypt() with flags=0 (default) returns base64 directly.
mac
HMAC-SHA256 of base64(iv) concatenated with base64(value), keyed with the raw APP_KEY bytes. Absent for GCM ciphers.
tag
GCM authentication tag. Used instead of HMAC for AES-256-GCM and AES-128-GCM ciphers (Laravel 10+).
常见问题
这会将我的 Cookie 或 APP_KEY 发送到任何地方吗?
不会。解密和加密均在服务器端使用 PHP 的 openssl_decrypt / openssl_encrypt 完成。不存储、不记录、不向第三方传输任何数据。
什么是 Cookie 会话驱动?
When SESSION_DRIVER=cookie is set in .env, Laravel serializes the entire session array, encrypts it, and stores it directly in the browser cookie. This is common in CTF challenge setups. Most production apps use file, database, or Redis drivers where only an encrypted session ID is stored in the cookie.
HMAC 签名是如何工作的?
Laravel computes hash_hmac("sha256", base64(iv) . base64(ciphertext), raw_key). Both the IV and ciphertext strings used in the MAC computation are the base64-encoded versions stored in the JSON, not the raw bytes.
伪造时应选择哪种加密算法?
Match the cipher to the one used by the target app. Laravel 5-9 default is AES-256-CBC. Laravel 10+ supports AES-256-GCM. You can detect it from the presence of the tag field in the decoded cookie structure (GCM has a non-empty tag field; CBC has mac instead).
即使 APP_KEY 正确,解密也会失败——为什么?
确认粘贴的是原始 Cookie 值而非 URL 编码版本。某些框架会对 Cookie 进行双重编码。同时验证密钥格式:Laravel 在 .env 中以 base64:xxx 形式存储——请原样粘贴。