Skip to content
RCE Write-up Advanced

From Behaviors to Shells: Yii2 PHP Framework RCE | CVE-2024–58136 — Exploit and Mitigation!

Yii2 before 2.0.52 improperly validates the __class key when attaching behaviours via JSON, allowing instantiation of arbitrary PHP classes. An attacker could achieve remote code execution by supplying crafted JSON with gadget classes.

nav1n👨🏻‍💻⚠️ Follow

Published on infosecwriteups.com

This article demonstrates how to discover this vulnerability in real-world applications using and explains how to get the Recevese Shell & mitigation.

nav1n👨🏻‍💻⚠️, on infosecwriteups.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

Yii2 checks only the 'class' key for subclassing Behaviour but still instantiates whatever is in '__class', enabling gadget-based RCE.

Impact

An attacker could achieve unauthenticated remote code execution, though only a few targets may be exploitable due to CSRF, authentication, or other protections.

What the attacker needed

Yii2 before 2.0.52; JSON parser enabled; Attacker can send JSON to endpoint

The fix

Upgrade Yii2 to version 2.0.52 or later.

How it was found

  1. Send a POST request with JSON containing an 'as hack' behaviour with __class set to a gadget class and a method to call phpinfo.
  2. Check if the response includes phpinfo output to confirm RCE.
  3. Set up a listener with netcat.
  4. Send a similar POST request with __class set to a gadget that calls system with a reverse shell command.

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.

This is a bug in a PHP framework called Yii2. When the framework receives JSON data to attach 'behaviours' (extra features) to objects, it trusts a special key called __class and creates whatever class is named there. An attacker can name a dangerous class that runs code, so they can run commands on the server.

What is RCE?

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

More by nav1n👨🏻‍💻⚠️

View all

3 more disclosed reports, best first.

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.