doukang7486 2014-06-01 00:45
浏览 429
已采纳

解码eval(base64_decode))

I am trying to decode this code. I know it can be done by changing eval to echo. But in this case its not working. Is i am making any mistake. This is my encoded_file.php code:

i have tried to change eval to echo but its not working file. I also tried this decoder:

<?php

// Open and read the content of the encoded file into a variable
$file = file_get_contents('encoded_file.php');

// Strip php tags
$file = str_replace('<?php', "", $file);
$file = str_replace('<?', "", $file);
// Make sure to get rid of short tags....
$file = str_replace('?>', "", $file);

 // Strip new lines
$file = str_replace("
", "", $file);

// Add semi colon to get around a parsing issue.
$file = $file.';';

// Change the Eval function
$file = str_replace('eval', 'echo ', $file);

// Function to eval the new string
function deval()
{
global $file;
ob_start();
eval($file);
$contents = ob_get_contents();
ob_end_clean();
return($contents);
}  

// Run the code thru once
$file = deval();

// Counter
$cnt = 1;

// Loop it till it's decoded
while(preg_match('/^\?><\?php eval/', $file))
{
$file = str_replace('?><?php eval', 'echo', $file);
$file = str_replace('?><?', "", $file);
$file = deval();
  $cnt;
}

//clean up some tags
$file = str_replace('?><?php', "", $file);
$file = str_replace('?><?', "", $file);

echo $cnt,' iterations<br/><br/>';
echo $file;
?>

but it also not working well. Any solution how to decode it or what's wrong in my decoder code.

  • 写回答

1条回答 默认 最新

  • dongmei1988 2014-06-01 01:11
    关注

    Here are the steps which are needed to decode this (note - I've renamed variables/functions for clarity):

    1. We see that this script reads content of itself, so we can assume - we cannot change this file

    so lets create new file with this content and change this file:

    $encoded=file('another_file.txt');
    

    2. Then we can change first eval to echo and all other evals should be commented:

    here is first line:

    echo base64_decode("aWYoIWZ1bmN0aW9uX2V4aXN0cygiWWl1bklVWTc2YkJodWhOWUlPOCIpKXtmdW5jdGlvbiBZaXVuSVVZNzZiQmh1aE5ZSU84KCRnLCRiPTApeyRhPWltcGxvZGUoIlxuIiwkZyk7JGQ9YXJyYXkoNjU1LDIzNiw0MCk7aWYoJGI9PTApICRmPXN1YnN0cigkYSwkZFswXSwkZFsxXSk7ZWxzZWlmKCRiPT0xKSAkZj1zdWJzdHIoJGEsJGRbMF0rJGRbMV0sJGRbMl0pO2Vsc2UgJGY9dHJpbShzdWJzdHIoJGEsJGRbMF0rJGRbMV0rJGRbMl0pKTtyZXR1cm4oJGYpO319");
    

    this will give us:

    if(!function_exists("getSubString"))
    {
        function getSubString($g,$b=0)
        {
            $a=implode("
    ",$g);
            $d=array(655,236,40);
            if($b==0) $f=substr($a,$d[0],$d[1]);
            elseif($b==1) $f=substr($a,$d[0]+$d[1],$d[2]);
            else $f=trim(substr($a,$d[0]+$d[1]+$d[2]));
            return $f;
        }
    }
    

    3. Now we can remove first echo/eval and go to 2nd one:

    here is 2nd line:

    echo base64_decode(getSubString($encoded));
    

    give us:

    if(!function_exists("decodeCode"))
    {
        function decodeCode($a,$h)
        {
            if($h==sha1($a))
            {
                return(gzinflate(base64_decode($a)));
            }
            else
            {
                echo("Error: File Modified");
            }
        }
    }
    

    4. we can remove it and go to last eval:

    here is it:

    echo decodeCode(getSubString($encoded,2),getSubString($encoded,1));
    

    and we see final code:

    /**
    * @site #####
    * @copyright 2010
    */
    include 'config.php';
    $id=$_GET['id'];
    if(isset($id))
    {
        header("Content-type: image/jpeg");
        $url='http://#####/siteuploads/thumb/'.$id;
        $path=pathinfo($url);
        header('Content-Disposition: attachment; filename="'.$path['basename'].'"');
        $img=imagecreatefromjpeg($url);
        $red=imagecolorallocate($img,255,155,255);
        imagestring($img,2,1,2,$site,$red);
        echo imagejpeg($img);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MapReduce实现倒排索引失败
  • ¥15 luckysheet
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题