Skip to content
RCE Write-up Advanced

From S3 bucket to Laravel unserialize RCE

A Laravel application had debug mode enabled, leaking AWS credentials that allowed access to an S3 bucket containing source code with a hard-coded APP_KEY. With the APP_KEY, an attacker could forge a malicious Laravel session cookie that, when deserialized, led to pre-authentication remote code execution.

blog.truesec.com

Published on blog.truesec.com

Laravel is weirdly helpful when APPDEBUG is enabled. It should never be used outside a local dev environment.

Alexander Andersson, on blog.truesec.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely multiple misconfigurations: debug mode enabled, overly permissive AWS credentials, hard-coded secrets in source code, and use of a Laravel version with insecure deserialization.

Impact

Pre-authentication remote code execution, allowing an attacker to run arbitrary commands on the server.

What the attacker needed

Debug mode enabled; AWS credentials with S3 access; APP_KEY hard-coded in source; Vulnerable Laravel version

The fix

Disable debug mode, restrict AWS credentials, avoid hard-coding secrets, and disable deserialization or update Laravel to a patched version.

How it was found

  1. Enable debug mode to leak environment variables including AWS keys.
  2. Use the AWS keys to list S3 buckets and download the application source code.
  3. Find the APP_KEY in the source code.
  4. Use PHPGGC to generate a gadget chain payload.
  5. Encrypt and sign the payload with the APP_KEY to create a malicious cookie.
  6. Send the cookie to the application to trigger deserialization and execute code.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Debug mode in a web framework shows detailed error messages that can include sensitive information like passwords or cloud keys. Here, those keys let the attacker download the application's source code and find the secret key used to sign cookies. With that key, the attacker could craft a cookie that made the server run their commands.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.