PHP-CPP Include file within extension

2

I'm developing a php extension with PHP-CPP, where I need to make an include of a php file within the extension, I'm doing this to protect the code. I'm trying this way:

Php::Value HomeController () {
std::string source = "";
source += "<?php\r\n";
source += "namespace App\Http\Controllers\ajax;\r\n";
source += "use Illuminate\Http\Request;\r\n";
source += "use App\Http\Requests;\r\n";
source += "use App\Http\Controllers\Controller;\r\n";
source += "class HorarioController extends Controller {\r\n";
source += "protected $page = \"ajax.horario\";\r\n";
source += "public function index(){\r\n";
source += "return $this->view;\r\n";
source += "}\r\n";
source += "}\r\n";

Php::Value val = Php::call("base64_encode", source);
std::string retorno = val;
retorno = "data://text/plain;base64,"+retorno;

return retorno;
}

but if the person removes the "data: // text / plain; base64," and using base64_decode has access to my class. Home I tried this way too:

void HomeControllerInclude () {
std::string source = "";
source += "<?php\r\n";
source += "namespace App\Http\Controllers\ajax;\r\n";
source += "use Illuminate\Http\Request;\r\n";
source += "use App\Http\Requests;\r\n";
source += "use App\Http\Controllers\Controller;\r\n";
source += "class HorarioController extends Controller {\r\n";
source += "protected $page = \"ajax.horario\";\r\n";
source += "public function index(){\r\n";
source += "return $this->view;\r\n";
source += "}\r\n";
source += "}\r\n";

Php::Value val = Php::call("base64_encode", source);
std::string retorno = val;
retorno = "data://text/plain;base64,"+retorno;

Php::call("include", retorno);
}

But I get the following error: Invalid call to include

Note: I'm using this method because it's the safest I know, the rest have dozens of reverse engineering methods.

EDITION:
I found a function in PHP-CPP that does the include, it's the function Php::include() it works perfectly with php files, but when I have to use include with data://text/plain;base64, I do not get an error message and does not include , what will it be?

Php::Value HomeControllerInclude () {
    std::string source = "";


    source = "<?php class novo { public static function coco() {  return 20; } }";

    Php::Value val = Php::call("base64_encode", source);
    std::string retorno = val;

    retorno = "data://text/plain;base64,"+retorno;


    return include(retorno);
}
    
asked by anonymous 29.10.2015 / 11:43

1 answer

1

The Php::include is used only to include real files and probably does not support the data: protocol that is usually (if not only) used for html applications.

Note that in github the include method tries to read a file :

Value include(const char *filename)
{
    // we can simply execute a file
    return File(filename).execute();
}

The correct one would probably be to use Php::eval , see what its source is:

Value eval(const char *phpCode) 
{
    // we have a script for this
    return Script(phpCode).execute();
}

The code should look something like:

Php::Value HomeControllerInclude () {
    std::string source = "";

    source = "<?php class novo { public static function coco() {  return 20; } }";

    return eval(source);
}

Or:

return Php::eval(source);

It can occur from <?php to affect eval , so use:

return eval("?>" + source);
    
08.11.2015 / 22:39