下面thinkphp框架教程欄目將給大家介紹Thinkphp5.0.x命令怎么執行filter,希望對需要的朋友有所幫助!
Thinkphp5.0.x命令執行
同樣是利用call_user_func()進行命令執行,在Request類的函數filterValue中執行【推薦:thinkphp框架】
首先搜索哪些函數調用了filterValue:
在Request類中的cookie()和input()函數中調用了filterValue()
搜索cookie函數調用情況,未發現結果;搜索input調用情況:
從run函數跟進:
step1
在$request = is_null($request) ? Request::instance() : $request;
會執行request的構造函數,此時已經通過構造函數中file_get_contents(‘php://input’)獲取到了POST的內容并賦值給$request->input變量
Step2
$dispatch = self::routeCheck($request, $config);
在routeCheck中會進入Route類的check函數:
check函數調用了$request->method():
傳入參數默認值為false,會執行到elseif中獲取var_method => _method,下面會對獲取到的變量進行覆蓋,此時如果傳入__construct,$_POST獲取到post提交的數據,即可在construct函數中遍歷POST的數組對request類中的成員進行覆蓋
以下利用過程需要:debug模式開啟
在run()中會調用param():
跟進param函數:
??? /**
???? * 獲取當前請求的參數
???? * @access public
???? * @param string|array? $name 變量名
???? * @param mixed???????? $default 默認值
???? * @param string|array? $filter 過濾方法
???? * @return mixed
???? */
首先進入if條件,跟進method方法
method()傳入參數為true:
執行下面語句:獲取原始請求類型$_SERVER[‘REQUEST_METHOD’],返回值為POST
返回到param中,$method=POST
因此會執行switch中的POST部分,進入post函數:
post函數:
??? /**
???? * 設置獲取POST參數
???? * @access public
???? * @param string??????? $name 變量名
???? * @param mixed???????? $default 默認值
???? * @param string|array? $filter 過濾方法
???? * @return mixed
???? */
傳入參數:
,然后復制給$content,然后對$_POST和是否json格式判斷,如果是json傳入還需要進行json_decode,否則直接使用$_POST的值
進入input方法:傳入參數為POST所獲取到的
Name為false,input返回data,post()直接返回
param()函數中:$vars = $this->post(false);
進入getFilter:
getFilter中$filter = $filter ?: $this->filter;獲取到$request類的filter變量值(之前在construct遍歷覆蓋的),并作為返回值給input函數
繼續執行array_walk_recursive($data, [$this, ‘filterValue’], $filter);
array_walk_recursive() 函數對數組中的每個元素應用用戶自定義函數。在函數中,數組的鍵名和鍵值是參數
相當于$filters=system取$data中的每一個變量作為$value傳入,當取到ccc=ipconfig時,system作為call_user_func第一個參數,ipconfig作為第二個,造成了命令執行。
執行結果:
?
?
?