To read /flag in this PHP deserialization challenge, we need to construct a payload that triggers the __call method in the hahaha class, which executes call_user_func($this->cmd, $this->content). We can set $cmd to file_get_contents and $content to /flag to read the file.
Exploitation Steps:
Trigger __destruct in Year:
The Year class's __destruct method checks if $this->key == "come on" and calls firecrackers() if true.
firecrackers() sets $this->rabbit->wish, which triggers __set in Rabbit.
Trigger __set in Rabbit:
The __set method in Rabbit returns $this->aspiration->family.
If $this->aspiration is an object of Nevv, accessing family will trigger __get in Nevv (but Nevv doesn't have __get).
Instead, we can make $this->aspiration a Nevv object and ensure it is called via __invoke.
Trigger __invoke in Nevv:
The __invoke method in Nevv calls $this->happiness->check().
If $this->happiness is a hahaha object, calling check() (which doesn't exist) will trigger __call in hahaha.
Trigger __call in hahaha:
The __call method executes call_user_func($this->cmd, $this->content).
We set $cmd = "file_get_contents" and $content = "/flag" to read the file.
Final Payload Construction:
We need to serialize a Year object with:
$key = "come on" (to trigger __destruct).
$rabbit set to a Nevv object where:
$happiness is a hahaha object with $cmd = "file_get_contents" and $content = "/flag".
Serialized Payload:
php
<?php
$h = new hahaha("file_get_contents", "/flag");
$n = new Nevv();
$n->happiness = $h;
$y = new Year("come on");
$y->rabbit = $n;
echo serialize($y);
?>