0x01 序言
在社区看到一个大佬的分析,过程很详细。自己跟着走了一遍,收货颇多。
0x02 话不多说就是干
漏洞出现在App\Weibo\Controller\ShareController.calss.php 中的

使用了 I() 函数获取了query 的值,并进行了解码。然后display模板,看下模板那里 
Common/functions.php看下W() 
W() 是渲染的功能, {:W('Weibo/Share/fetchShare',array('param'=>$parse_array))} Weibo/Share/fetchShare 是调用的方法 再看下/Weibo/Widget/ShareWidget.class.php/fetchShare()  调用了assginFetch() ,assginFetch() 调用了D() 方法,应该是实例化了某个类,调用了getInfo() 
在Weibo/Model/ShareMode.class.php 中调用了getInfo() 
getInfo() 又调用了D() ,可以实例化Model类,其中的所有变量都可控,那么满足 1.为Model类 2.方法只能有一个传入的参数 看下tp框架本身自带的Model类。/ThinkPHP/Library/Think/Model.class.php 
这里是可以代码执行的,但是得调用他,并且参数可控 可以找到一个可利用的类,参数可控,然后调用这个类 /Application/Common/Model/ScheduleModel.class.php 
看下_validationFieldItem() 
这里不论$val[0] 是不是数组,都会在$args 数组中插入元素,并且是在数组的开头 很明显$val[0] 不是数组,那么$data[$val[0]] 的就显得很重要了。 逆着分析一下。 $args=$val[6] ,然后$args 的开头插入了$data[$val[0]] ,简直是开局两把枪了。 然后$val[4]==functions 的话,就会执行一个回调函数,但是是数组作为参数。$val[1] 的值为执行函数。 如果$val[1]=assert ,就会执行$args 而$data 和$val 是runSchedule() 方法传进的 回到runSchedule() 
$method[0] 是D() 调用的类,$method[1] 是方法,$args , $schedule 是传参。 而$method 是$schedule['method'] 分割而成,那么$schedule['method'] 需要为:Model->_validationFieldItem 而$args=$data ,$schedule 是$val 上面说过$data[$val[0]] 的值很重要。 看下getInfo() 
触发类在/Application/Common/Model/ScheduleModel.class.php 那么$param['app']=Common $param['model'] = Schedule $param['method']=runSchedule 然后将$param['id']传入runSchedule() 上面说的$schedule['method']=Model->_validationFieldItem id['method']=Model->_validationFieldItem 那么就进入了_validationFieldItem()
大体思路:
1.ShareController.shareBox-> 2.ShareWidget. fetchShare-> 3.ShareWidget.assginFetch-> 4.ShareModel.getInfo(这里控制D方法生成ScheduleModel类,并调用传入一个参数的方法)-> 5.ScheduleModel.runSchedule(这里控制D方法生成Model类,并调用传入两个参数的方法)-> 6.Model._validationFieldItem
poc 要注意的是,query传值后,会进行urldecode() /index.php?s=/weibo/share/sharebox&query=app=Common%26model=Schedule%26method=runSchedule%26id[method]=Model-%3E_validationFieldItem%26id[args]=1=phpinfo()%26id[4]=function%26id[1]=assert%26id[6]=phpinfo()%26id[0]=1%26id[status]=1 
参考链接:https://forum.butian.net/share/187
|