I am looking for a way to implement the __toString method using only eval in PHP. The end goal is to be able to read a file. Note that this is part of a CTF challenge and not a real world application.
I am given the following implementation
function __toString(){
eval($this->var);
}
Since $var is under my control I can set if to whatever I want. So far I've tried the following without success:
$var = "return file_get_contents('file.txt');"
Any hints?
UPDATE: The relevant code looks as follows:
class MyClass{
private $var;
function __toString(){
if (isset($this->var) eval($this->var);
}
}