今天做题时候看的一个题

<?php
highlight_file(__FILE__);
function new_addslashes($string) {
     if(!is_array($string)) return addslashes($string);
     foreach($string as $key => $val) $string[$key] = new_addslashes($val);
     return $string;
 }
if(!get_magic_quotes_gpc()) {
    $_POST = new_addslashes($_POST);
    $_GET = new_addslashes($_GET);
    $_REQUEST = new_addslashes($_REQUEST);
    $_COOKIE = new_addslashes($_COOKIE);
}
if(isset($_POST['sudo'])) {
    // print_r($_POST);
    $file = __DIR__ .'/config.php';
    require $file;
    $key = $_POST['info']['name'];
    if(!isset($LANG[$key])) {
        
        $content = file_get_contents($file);
        $content = substr($content,0,-3);
        $data = $content."\n\$LANG['$key'] = '$_POST[no1]';\n?>";
        file_put_contents($file,$data);
    } elseif(isset($LANG[$key]) && $LANG[$key]!=$_POST['no1']) {
        echo 1;
        $content = file_get_contents($file);
        $content = str_replace($LANG[$key],$_POST['no1'],$content);
        echo $content;
        file_put_contents($file,$content);
    }
}
if(isset($_GET['re'])){
    file_put_contents("./config.php",base64_decode("PD9waHAKJExBTkdbJ21lbWJlcl9tYW5hZ2UnXSA9ICdhZG1pbic7Cj8+Cg=="));
}
?>

题目看起来很清晰。对全部参数都用addslashes转义,后面写入单引号闭合也没有办法。但是还有一个关键函数replace的函数。这个是个关键点。首先要知道的是addslashes的转移对%00转义后是\0

然后我们想办法先可以在文件写入一个%00'经过转义后就是\0\'那么再依据替换如果我们把0替换成\呢很自然\会变成\\然后这个文件就是\\\\'很自然成功闭合了单引号然后写入一句话木马就行了。