Php problem eval/html/php


Php problem eval/html/php

我一直在写一个php/html页面编码器/解码器…我知道它已经存在了,但这是一个大学项目,所以点击XDDD

我对我想要保护的页面进行编码,假设使用base64_encode,当我收到任何页面的请求时,我有一个加载器读取编码页面,解密它并使用eval执行它。当我尝试解密和执行混合php/html页面时,真正的问题就出现了。显然eval不能执行html代码,所以我的问题是,我真的成为疯狂的分割页面执行php代码和打印html?如果我包含一个编码的php或php/html页面我真的需要重用上面的方法吗?

我希望有人能真正帮助我,因为离截止日期还有一个星期,我现在不能改变这个项目。

克里斯,这里是函数和第一个调用$param[0]我已经得到了文件名名为

function MyInclude($filename)
{
// create the temp file
$temp_filename = "tmp.php";
$handle = fopen($temp_filename , 'w+');
if (!$handle)
  die('Error creating temp file');
// write the decrypted data, close the handle
$tmp=file_get_contents($filename);
$data=MCrypt_Decode($tmp,'PFL_EPU_V100_mia');
fwrite($handle,$data );
fclose($handle);
// start output buffering to contain any output the script creates
ob_start();
try {
 include($temp_filename);
} catch (Exception $e) {
 die('There was an error in the encrypted file, cannot process');
}
// get the output, clear the buffer
$output = ob_get_contents();
ob_end_clean();
//destroy the temp file
unlink($temp_filename);
// now you can output the buffer, if desired:
echo $output;
}
MyInclude($param[0]);

$param[0]文件在这里

<?php
 session_start();
 $_SESSION['title']='Home';
 MyInclude("header.php");
?>
<body>
    sono il body <?php echo APP_PATH; ?>
</body>
<?
echo "boss";
 MyInclude("footer.php");
?>

你知道吗??或者你需要一些其他的代码?让我知道T_T

迈克

可以eval()包含html和php混合的字符串,只要包含标签。

http://php.net/manual/en/function.eval.php

eval()遇到php关闭标记(?>)时,它将停止尝试将其视为php代码,并只是返回所有内容,直到它到达php打开标记。

你的问题的典型解决方案是这样的:

$file = ... //Your decoded php/html code here
$file = '?>' . $file; //Add a close tag to the beginning;
ob_start();
eval($file);
$output = ob_get_clean();
echo $output; //Or do something else with it... really, if you're 
              //just going to be echoing it you can skip the output buffering

是否有可能解密页面,将其写入文件,然后include ?这将让PHP解释器做它最擅长的事情——解释PHP文档。这将包括HTML/PHP组合,而不依赖于eval

大概是:

// create the temp file
$temp_filename = "tmp.php";
$handle = fopen($filename , 'w');
if (!$handle)
  die('Error creating temp file');
// write the decrypted data, close the handle
fwrite($handle, $decrypted_data);
fclose($handle);
// start output buffering to contain any output the script creates
ob_start();
try {
 include_once($temp_filename);
} catch (Exception $e) {
 die('There was an error in the encrypted file, cannot process');
}
// get the output, clear the buffer
$output = ob_get_contents();
ob_end_clean();
//destroy the temp file
unlink($temp_filename);
// now you can output the buffer, if desired:
echo $output;

函数引用

打开外部文件:http://us2.php.net/manual/en/function.fopen.php

写入文件:http://us2.php.net/manual/en/function.fwrite.php

文件关闭:http://us2.php.net/manual/en/function.fclose.php

ob_start: http://us2.php.net/manual/en/function.ob-start.php

ob_get_contents: http://us2.php.net/manual/en/function.ob-get-contents.php

ob_end_clean: http://us2.php.net/manual/en/function.ob-end-clean.php

分开:http://www.php.net/manual/en/function.unlink.php

您需要将已解码的文件转储到另一个文件并对其进行include();。eval方法将不起作用,因为如果文件中的第一项既不是开始的<?php标记,也不是有效的PHP代码位,它将退出并出现解析错误。

不仅如此,您还需要用不同的函数在加密文件中找到/替换include(), require(), include_once()require_once()的任何出现,以确保在解密之前不会尝试执行另一个加密文件。您可以在执行(即解密)时执行此操作,但最好在加密时执行,以最大限度地减少在执行之前预获取代码所需的时间。

你可以定义这些自定义函数来解密文件,并在你的加载器脚本中包含/要求它

您的问题描述有点模糊,但是您的问题似乎可以通过输出缓冲解决。

您是否尝试过解密页面,然后解析文本以分离出其中的任何内容,然后仅执行该代码?