问题描述:公司漏扫发现数据库内出现空用户名及密码,需要对这些用户进行整改

1.首先出现了疑问,这些空的用户名是怎么出现的,而且不附带密码。

2.可以手动这样创建这样的用户名和密码形式么。

3.如果能这样创建一个用户,是不是我可以不用用户名和密码能直接登录服务器呢。

4.如何对这样的形式存在进行规避。

空用户名为匿名用户,那么匿名用户能登录么,登录方式可以不用带用户名么。延伸到了mysql的匿名用户,安装完MySQL后,系统默认会创建一个不需要密码的root用户,和一个无用户名无密码的匿名用户(Anonymous Account)。进行下面的初始化操作以合理授权,增强安全。

mysql> create user ''@'localhost' ;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host,authentication_string from mysql.user;
+------------------+-----------+------------------------------------------------------------------------+
| user | host | authentication_string |
+------------------+-----------+------------------------------------------------------------------------+
| employee_proxy | % | *DC6775B6D1F01EFD99CC191E929862480DAC2F7A |
| root | % | *858D7135C67CFFAEE40C01A38AB99018DBB245A7 |
| test01 | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| tspmlf | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| username | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| | localhost | |
| backuper | localhost | *4DDFC2472B45DA20DB77FD7F3C19996CCCE35897 |
| employee | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| mysql.infoschema | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.session | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.sys | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| root | localhost | *858D7135C67CFFAEE40C01A38AB99018DBB245A7 |
| zabbix | localhost | *C5A9E29672800EE5E1A1B0EA8C397728FD1660D8 |
+------------------+-----------+------------------------------------------------------------------------+
13 rows in set (0.00 sec)
[mysql@rhel7 ~]$ /usr/local/mysql8/bin/mysql -u -p -hlocalhost -P33306 -S /data/mysql8/db_dxpt08/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.22 MySQL Community Server - GPL Copyright (c) 2000, 2020, 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> show grants for ''@'localhost' ;
  +--------------------------------------+
  | Grants for @localhost |
  +--------------------------------------+
  | GRANT USAGE ON *.* TO ``@`localhost` |
  +--------------------------------------+
  1 row in set (0.00 sec)

mysql> select current_user(),user();
+----------------+--------------+
| current_user() | user() |
+----------------+--------------+
| @localhost | -p@localhost |
+----------------+--------------+
1 row in set (0.00 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)

mysql>
mysql>
mysql> select user,host from mysql.user;
ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for table 'user'

如何进行规避,删除这种方式

--用drop ‘’@‘localhost’ 方式进行删除

mysql> select user,host,authentication_string from mysql.user;
+------------------+-----------+------------------------------------------------------------------------+
| user | host | authentication_string |
+------------------+-----------+------------------------------------------------------------------------+
| employee_proxy | % | *DC6775B6D1F01EFD99CC191E929862480DAC2F7A |
| root | % | *858D7135C67CFFAEE40C01A38AB99018DBB245A7 |
| test01 | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| tspmlf | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| username | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| | localhost | |
| backuper | localhost | *4DDFC2472B45DA20DB77FD7F3C19996CCCE35897 |
| employee | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| mysql.infoschema | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.session | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.sys | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| root | localhost | *858D7135C67CFFAEE40C01A38AB99018DBB245A7 |
| zabbix | localhost | *C5A9E29672800EE5E1A1B0EA8C397728FD1660D8 |
+------------------+-----------+------------------------------------------------------------------------+
13 rows in set (0.00 sec) mysql> drop user ''@'localhost';
Query OK, 0 rows affected (0.01 sec) mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec) mysql> select user,host,authentication_string from mysql.user;
+------------------+-----------+------------------------------------------------------------------------+
| user | host | authentication_string |
+------------------+-----------+------------------------------------------------------------------------+
| employee_proxy | % | *DC6775B6D1F01EFD99CC191E929862480DAC2F7A |
| root | % | *858D7135C67CFFAEE40C01A38AB99018DBB245A7 |
| test01 | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| tspmlf | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| username | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| backuper | localhost | *4DDFC2472B45DA20DB77FD7F3C19996CCCE35897 |
| employee | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| mysql.infoschema | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.session | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.sys | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| root | localhost | *858D7135C67CFFAEE40C01A38AB99018DBB245A7 |
| zabbix | localhost | *C5A9E29672800EE5E1A1B0EA8C397728FD1660D8 |
+------------------+-----------+------------------------------------------------------------------------+
12 rows in set (0.00 sec)

--delete from mysql.user where user='';

mysql> create user ''@'127.0.0.1' ;
Query OK, 0 rows affected (0.01 sec) mysql> select user,host,authentication_string from mysql.user;
+------------------+-----------+------------------------------------------------------------------------+
| user | host | authentication_string |
+------------------+-----------+------------------------------------------------------------------------+
| employee_proxy | % | *DC6775B6D1F01EFD99CC191E929862480DAC2F7A |
| root | % | *858D7135C67CFFAEE40C01A38AB99018DBB245A7 |
| test01 | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| tspmlf | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| username | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| | 127.0.0.1 | |
| backuper | localhost | *4DDFC2472B45DA20DB77FD7F3C19996CCCE35897 |
| employee | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| mysql.infoschema | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.session | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.sys | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| root | localhost | *858D7135C67CFFAEE40C01A38AB99018DBB245A7 |
| zabbix | localhost | *C5A9E29672800EE5E1A1B0EA8C397728FD1660D8 |
+------------------+-----------+------------------------------------------------------------------------+
13 rows in set (0.00 sec) mysql> delete from mysql.user where user='';
Query OK, 1 row affected (0.00 sec) mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec) mysql> select user,host,authentication_string from mysql.user;
+------------------+-----------+------------------------------------------------------------------------+
| user | host | authentication_string |
+------------------+-----------+------------------------------------------------------------------------+
| employee_proxy | % | *DC6775B6D1F01EFD99CC191E929862480DAC2F7A |
| root | % | *858D7135C67CFFAEE40C01A38AB99018DBB245A7 |
| test01 | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| tspmlf | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| username | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| backuper | localhost | *4DDFC2472B45DA20DB77FD7F3C19996CCCE35897 |
| employee | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| mysql.infoschema | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.session | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.sys | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| root | localhost | *858D7135C67CFFAEE40C01A38AB99018DBB245A7 |
| zabbix | localhost | *C5A9E29672800EE5E1A1B0EA8C397728FD1660D8 |
+------------------+-----------+------------------------------------------------------------------------+
12 rows in set (0.00 sec)

匿名用户一般会在刚创建完数据库时,用来防止用户忘记登录密码。如果不及时清理掉,会暴露一个风险给漏扫。

MySQL匿名空用户名处理的更多相关文章

  1. 何修改WAMP中mysql默认空密码--转

    何修改WAMP中mysql默认空密码  http://www.cnblogs.com/hooray/archive/2011/07/23/2114792.html WAMP安装好后,mysql密码是为 ...

  2. paip.导入数据英文音标到数据库mysql为空的问题之道解决原理

    paip.导入数据英文音标到数据库mysql为空的问题之道解决原理 #---原因:mysql 导入工具的bug #---解决:使用双引号不个音标括起来. 作者 老哇的爪子 Attilax 艾龙,  E ...

  3. WAMP中修改mysql默认空密码

    WAMP中如何修改mysql默认空密码 WAMP安装好后,mysql教程密码是为空的,那么要如何修改呢?其实很简单,通过几条指令就行了,下面我就一步步来操作.首先,通过WAMP打开mysql控制台.提 ...

  4. 解决windows下的mysql匿名登陆无法使用mysql数据库的问题

    原文:解决windows下的mysql匿名登陆无法使用mysql数据库的问题 我在windows下安装了mysql,但是不用密码就能登进去,而root明明是有密码的,我用select user()命令 ...

  5. MySQL设置空密码

    因为刚安装的时候,MySQL强制设置密码,但是我需要设置MySQL为空密码 语句: ';

  6. 【转】修改mysql数据库的用户名和密码

    修改mysql数据库的用户名和密码 更改密码 mysql -u root -p Enter password:*** mysql>use mysql; 选择数据库 Database change ...

  7. c# 调用mysql数据库验证用户名和密码

    使用mysql数据库验证用户名和密码时,如果用户名是中文,一直查不到数据 需要把app.config 中修改为 数据库统一设置utf8编码格式,连接数据库的时候设置编码Charset=utf8可以避免 ...

  8. 修改WAMP中mysql默认空密码

    WAMP安装好后,mysql密码是为空的,那么要如何修改呢?其实很简单,通过几条指令就行了,下面我就一步步来操作. 首先,通过WAMP打开mysql控制台. 提示输入密码,因为现在是空,所以直接按回车 ...

  9. 如何修改WAMP中mysql默认空密码

      WAMP安装好后,mysql密码是为空的,那么要如何修改呢?其实很简单,通过几条指令就行了,下面我就一步步来操作. 首先,通过WAMP打开mysql控制台. 提示输入密码,因为现在是空,所以直接按 ...

  10. 如何修改WAMP中mysql默认空密码 以及修改时报错的处理方法

    WAMP安装好后,mysql密码是为空的,那么要如何修改呢?其实很简单,通过几条指令就行了,下面我就一步步来操作. 首先,通过WAMP打开mysql控制台. 提示输入密码,因为现在是空,所以直接按回车 ...

随机推荐

  1. Ai2022中文版(Illustrator 2022)Mac/win v26.4.1

    Adobe Illustrator 2022 Mac/win是设计行业中的矢量图形经典.数以百万计的设计人员和艺术家使用行业标准的矢量图形软件创作各类内容,从炫酷的 Web 和移动图形,到徽标.图标. ...

  2. 2003031118—李伟—Python数据分析五一假期作业—MySQL的安装以及使用

            项目  期中试卷 课程班级博客链接 20级数据班(本) 这个作业要求链接 作业要求 博客名称 2003031118-李伟-Python数据分析五一假期作业-MySQL的安装以及使用 要 ...

  3. Java中集合基础相关知识

    1.集合基础 1.1 集合概述 编程的时候如果需要存储多个数据使用长度固定的数据存储,适应不了元素个数变化的需求,这时候我们就需要用集合. 集合类的特点:提供了一种存储空间可变的存储模型,存储的数据容 ...

  4. C语言中链表与队列

    https://www.cnblogs.com/lanhaicode/p/10432004.html

  5. DP-最大子矩阵

    1768:最大子矩阵 题目描述: 描述已知矩阵的大小定义为矩阵中所有元素的和.给定一个矩阵,你的任务是找到最大的非空(大小至少是1 * 1)子矩阵比如,如下4 * 4的矩阵 0 -2 -7 09 2 ...

  6. Blob文件下载type类型

    let url = window.URL.createObjectURL(new Blob([文件流(一般为res.data)], {type: "Blob类型"}) let li ...

  7. Web服务器2

    Web服务器2 基于华为鲲鹏云服务器CentOS中(或Ubuntu),使用Linux Socket实现: Web服务器的客户端服务器,提交程序运行截图 实现GET即可,请求,响应要符合HTTP协议规范 ...

  8. Mysql用户及其权限

    一.创建用户 create user 'user_name' identified by 'password'; 二.用户授权 grant [权限名] on 数据库名.表名 to user_name ...

  9. TP5.1模板循环标签

    第一种volist name=assign中的变量名 id=数组中的key offset=开始循环的位置 length=步长 {volist name='list' id='vo' offset='0 ...

  10. eclipse console 控制台输出乱码解决办法

    一.console输出日志显示乱码 二.在类编辑处点击右键 Run As --> Run Configurations 三.在Common中设置字符集 gbk 四.restart 搜索 复制