douyi3307 2012-03-17 10:28
浏览 41

如何限制上传的PHP文件中使用的函数?

I'm trying to make a plugin system and the plugin contain PHP code. I think if someone evil reach the area that upload this plugin he can upload evil code so I want to limit the functions used in plugin file such as if there is eval() or base64_encode function the upload should fail.

I think this will be done by the regex, but I have no experiance with it.

So I want something like that

<?php

$file = 'plugin.php';

$content = file_get_contents($file);

if(file_is_secure($content)){
    upload($file);
}else{
    exit('evil');
}

?>

see this example

<?php
    $content = file_get_contents('example.php');
    preg_match_all("/(function )(\S*\(\S*\))/", $content, $matches);
    foreach($matches[2] as $match) {
        $function[] = "// " . trim($match) . "<br />
";
    }
    natcasesort($function);
    $functionlist .= "/* Functions in this file */<br />
";
    $functionlist .= "/**************************/<br />

";
    $functionlist .= implode('', $function);
    echo $functionlist;
?>

i want one like this but for making a white list and not for use functions, but for the function it self " i mean function(); not function name(){}

  • 写回答

1条回答 默认 最新

  • dongyuan7110 2012-03-17 10:32
    关注

    Take a look at the runkit extension for PHP. This allows you to remove or redefine PHP functions, and to execute PHP code within a sandbox environment.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog