关于php:解码eval(base64_decode)

decoding eval(base64_decode))

我正在尝试解码此代码。
我知道可以通过将eval更改为echo来完成。但是在这种情况下,它不起作用。我犯错了吗?这是我的encode_file.php代码:

我已尝试将eval更改为echo,但其不起作用。
我也尝试过以下解码器:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?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;
?>

但是它也不能很好地工作。任何有关如何对其进行解码的解决方案,或者我的解码器代码有什么问题。


以下是解码此内容所需的步骤(注意-为清楚起见,我已将变量/函数重命名):

1。我们看到该脚本读取了自身的内容,因此可以假设-我们无法更改此文件

因此让我们使用此内容创建新文件并更改此文件:

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

2。然后我们可以将第一个eval更改为echo,并应注释所有其他eval:

这是第一行:

1
echo base64_decode("aWYoIWZ1bmN0aW9uX2V4aXN0cygiWWl1bklVWTc2YkJodWhOWUlPOCIpKXtmdW5jdGlvbiBZaXVuSVVZNzZiQmh1aE5ZSU84KCRnLCRiPTApeyRhPWltcGxvZGUoIlxuIiwkZyk7JGQ9YXJyYXkoNjU1LDIzNiw0MCk7aWYoJGI9PTApICRmPXN1YnN0cigkYSwkZFswXSwkZFsxXSk7ZWxzZWlmKCRiPT0xKSAkZj1zdWJzdHIoJGEsJGRbMF0rJGRbMV0sJGRbMl0pO2Vsc2UgJGY9dHJpbShzdWJzdHIoJGEsJGRbMF0rJGRbMV0rJGRbMl0pKTtyZXR1cm4oJGYpO319");

这将给我们:

1
2
3
4
5
6
7
8
9
10
11
12
13
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。现在我们可以删除第一个echo / eval并转到第二个:

这是第二行:

1
echo base64_decode(getSubString($encoded));

给我们:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
if(!function_exists("decodeCode"))
{
    function decodeCode($a,$h)
    {
        if($h==sha1($a))
        {
            return(gzinflate(base64_decode($a)));
        }
        else
        {
            echo("Error: File Modified");
        }
    }
}

4。我们可以将其删除并转到上一个评估:

在这里:

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

,我们看到了最终代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
* @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);
}