Artificial truth

archives | latest | homepage | atom/rss/twitter

The more you see, the less you believe.

Intended solutions for 35c3ctf 2018 web "php"
Tue 01 January 2019 — download

Last year (we're in 2019 now), I had the great pleasure (thanks to tsuro) to write a challenge for the 35c3ctf, called "php". 86% of the teams in the top100 solved it, with a total of 209 solves on 636 playing teams, so maybe it should have been used for the 35c3 junior ctf instead.

But on the other hand, I only got positive feedback about it, so maybe it was ok after all. Anyway, here is the code:


$line = trim(fgets(STDIN));

$flag = file_get_contents('/flag');

class B {
  function __destruct() {
    global $flag;
    echo $flag;

$a = @unserialize($line);

throw new Exception('Well that was unexpected…');

echo $a;

There are several possible solutions.

The intended one was to borrow the fast destruct trick from phpggc: setting our object as a value somewhere in an array, then overwriting the index with something else, triggering the garbage collection. The payload could look like this: a:2:{i:7;O:1:"B":0:{};i:7;i:0}.

An other route could be to feed invalid data to unserialize, because of the presence of the @:

  • a non-existent object present in an array with a B instance: a:2:{i:0;O:1:"B":0:{}i:1;O:1:"LOL";}.
  • an invalid object property count, O:1:"B":1337:{} or O:1:"B":0:{"1337":0}.