跳到内容
HackIndex logo

HackIndex

工具

Laravel Cookie 伪造与解码器

解码 Laravel AES 加密 Cookie 或伪造已签名的 Cookie——用于 CTF 挑战和授权测试。

Laravel 使用 .env 文件中的 APP_KEY,以 AES-256-CBC(Laravel 10+ 为 AES-256-GCM)加密所有 Cookie。加密值是 base64 编码的 JSON,包含 IV、密文和 HMAC-SHA256 签名。本工具解密 Cookie 以显示会话载荷(用户 ID、角色、CSRF 令牌),验证 HMAC 签名,并允许伪造新的有效签名 Cookie。所有处理均在服务器端 PHP 中完成,不存储或记录任何内容。

解码 Cookie

解密并验证现有 Cookie

接受:base64:xxx(标准)、十六进制字符串或原始 base64。在目标 .env 中以 APP_KEY 形式找到。

伪造 Cookie

生成有效的已签名 Laravel Cookie

AES-256-CBC 是 Laravel 9 及以下版本的默认值。AES-256-GCM 适用于 Laravel 10+。

Tip: decode a real cookie first to see the exact serialized format, then modify and forge.

工作原理

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. 1. Get the cookie: intercept the target request in Burp Suite or browser DevTools and copy the laravel_session cookie value.
  2. 2. Get the APP_KEY: find it in the target .env, a leaked config, or crack it from known plaintext.
  3. 3. Decode: paste both above and decode to reveal the session payload (user ID, CSRF token, flash data).
  4. 4. Modify & forge: change the payload (e.g. elevate user_id), paste the APP_KEY and forge a new valid signed cookie.
  5. 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 形式存储——请原样粘贴。