验证码: 看不清楚,换一张 查询 注册会员,免验证
  • {{ basic.site_slogan }}
  • 打开微信扫一扫,
    您还可以在这里找到我们哟

    关注我们

thinkphp5.0.x命令是怎么执行filter的

阅读:517 来源:乙速云 作者:代码code

thinkphp5.0.x命令是怎么执行filter的

Thinkphp5.0.x命令执行

同样是利用call_user_func()进行命令执行,在Request类的函数filterValue中执行

首先搜索哪些函数调用了filterValue:

thinkphp5.0.x命令是怎么执行filter的

在Request类中的cookie()和input()函数中调用了filterValue()

搜索cookie函数调用情况,未发现结果;搜索input调用情况:

thinkphp5.0.x命令是怎么执行filter的

从run函数跟进:

Step1

在$request = is_null($request) ? Request::instance() : $request;

会执行request的构造函数,此时已经通过构造函数中file_get_contents(‘php://input’)获取到了POST的内容并赋值给$request->input变量

thinkphp5.0.x命令是怎么执行filter的

Step2

$dispatch = self::routeCheck($request, $config);

thinkphp5.0.x命令是怎么执行filter的

在routeCheck中会进入Route类的check函数:

thinkphp5.0.x命令是怎么执行filter的

check函数调用了$request->method():

传入参数默认值为false,会执行到elseif中获取var_method => _method,下面会对获取到的变量进行覆盖,此时如果传入__construct,$_POST获取到post提交的数据,即可在construct函数中遍历POST的数组对request类中的成员进行覆盖

thinkphp5.0.x命令是怎么执行filter的

thinkphp5.0.x命令是怎么执行filter的

thinkphp5.0.x命令是怎么执行filter的

以下利用过程需要:debug模式开启

在run()中会调用param():

thinkphp5.0.x命令是怎么执行filter的

跟进param函数:

/**

* 获取当前请求的参数

* @access public

* @param string|array  $name 变量名

* @param mixed         $default 默认值

* @param string|array  $filter 过滤方法

* @return mixed

*/

首先进入if条件,跟进method方法

thinkphp5.0.x命令是怎么执行filter的

thinkphp5.0.x命令是怎么执行filter的

method()传入参数为true:

执行下面语句:获取原始请求类型$_SERVER['REQUEST_METHOD'],返回值为POST

thinkphp5.0.x命令是怎么执行filter的

返回到param中,$method=POST 

thinkphp5.0.x命令是怎么执行filter的

因此会执行switch中的POST部分,进入post函数:

thinkphp5.0.x命令是怎么执行filter的

post函数:

/**

* 设置获取POST参数

* @access public

* @param string        $name 变量名

* @param mixed         $default 默认值

* @param string|array  $filter 过滤方法

* @return mixed

*/

thinkphp5.0.x命令是怎么执行filter的

传入参数:

thinkphp5.0.x命令是怎么执行filter的

,然后复制给$content,然后对$_POST和是否json格式判断,如果是json传入还需要进行json_decode,否则直接使用$_POST的值

thinkphp5.0.x命令是怎么执行filter的

进入input方法:传入参数为POST所获取到的

thinkphp5.0.x命令是怎么执行filter的

thinkphp5.0.x命令是怎么执行filter的

Name为false,input返回data,post()直接返回

param()函数中:$vars = $this->post(false);

进入getFilter:

thinkphp5.0.x命令是怎么执行filter的

getFilter中$filter = $filter ?: $this->filter;获取到$request类的filter变量值(之前在construct遍历覆盖的),并作为返回值给input函数

thinkphp5.0.x命令是怎么执行filter的

继续执行array_walk_recursive($data, [$this, 'filterValue'], $filter);

array_walk_recursive() 函数对数组中的每个元素应用用户自定义函数。在函数中,数组的键名和键值是参数

相当于$filters=system取$data中的每一个变量作为$value传入,当取到ccc=ipconfig时,system作为call_user_func第一个参数,ipconfig作为第二个,造成了命令执行。

thinkphp5.0.x命令是怎么执行filter的

执行结果:

thinkphp5.0.x命令是怎么执行filter的

分享到:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: hlamps#outlook.com (#换成@)。
相关文章
{{ v.title }}
{{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
你可能感兴趣
推荐阅读 更多>