MYSQL信息安全基线

MySQL 信息安全基线

MySQL 信息安全基线是一套针对 MySQL 数据库的安全配置标准,旨在减少潜在的安全风险。以下是关键的安全配置建议:

  1. 检查是否存在匿名用户或弱口令
SELECT User,host FROM MySQL.user WHERE authentication_string='';` `SELECT user,host FROM MySQL.user WHERE user = '';

查询返回为空则正常

  1. 清理无关的账号/删除多余账号
mysql>delete from user where user='账号';
mysql>flush privileges;
  1. 设置口令复杂度/配置mysqld.cnf文件
[mysqld]
plugin-load = "validate_password.so"
validate-password = FORCE_PLUS_PERMANENT
# 密码长度
validate_password_length = 8
# 密码中至少包含的大小写字母总个数
validate_password_mixed_case_count = 1
# 密码中至少包含的数字总个数
validate_password_number_count = 1
# 密码中至少包含的特殊字符总个数
validate_password_special_char_count = 1
# 密码的验证强度等级
validate_password_policy = MEDIUM
  1. 修改默认端口/编辑my.cnf文件
[mysqld] 
port=55555
  1. 配置最大连接数
    编辑MySQL配置文件:my.cnf 或者是 my.ini
    在[mysqld]配置段添加:
max_connections = 2000
  1. 禁止 mysql 对本地文件存取
    在 my.cnf 的 mysql 字段下加 local-infile=0
# 查看现有配置
show variables like 'local_infile'
# 修改配置
[mysqld]
local_infile = 0
  1. my.cnf文件安全配置
ls –al /etc/my.cnf      #应为644权限
  1. history文件安全
ls -al .mysql_history .bash_history    #应为600权限
  1. 检查不受限访问数据库功能/my.cnf 注释参数
# 在my.cnf文件中注释
#skip-grant-tables
  1. 检查日志配置/修改my.cnf配置
log-error=/xxxx/log/mysqld.log   #(路径根据实际情况而定)
  1. 设置日志保存时长/修改my.cnf配置
expire_logs_days = 180
  1. 避免不同用户共享账号
# 创建用户
create user '用户名'@'用户host' identified by '密码'
  1. 修改root账号名
# 修改 root 账号名
update mysql.user set user="xxx" where user="root"
  1. 禁止重用数据库用户名
# 查看是否有重用数据库用户名。若有,则删除
select user,count() from mysql.user group by user having count() > 1 
  1. 防暴力破解
#  限制用户输入密码错误3次锁定1天
create user '用户'@'host' identified by '密码' failed_login_attempts 3 password_lock_time 1
[mysqld]
plugin-load-add = "connection_control.so"
connection-control=FORCE_PLUS_PERMANENT
connection-control-failed-login-attempts=FORCE_PLUS_PERMANENT
connection-control-failed-connections-threshold=3
connection-control-min-connection-delay=86400000
connection-control-max-connection-delay=86400000
  1. 密码安全
  • 检查账户默认密码和弱密码。
  • 口令长度需要至少 14 位,并需要包括数字、英文字母和特殊符号,见第三条
  • 密码应至少每 90 天进行一次更换。
[mysqld]
default_password_lifetime=90
#  将账号设置为 90 天更换一次。
alter user '账号名'@'host' password expire interval 90 day
  • 在 mysqld.cnf 文件中添加配置 validate_password_policy=STRONG 将密码强度更改为强
[mysqld]
validate_password_policy=STRONG
  • 在 mysqld.cnf 文件中添加配置 validate_password_length=14,设置密码长度最小为 14
[mysqld]
validate_password_length=14
  • 禁止数据库用户密码为空
#  检查是否有密码为空的用户。
SELECT User,host FROM mysql.user WHERE LENGTH(authentication_string) = 0
  • 禁止在 mysqld.cnf 中配置密码
  1. 授权
    依照最小化权限配置原则
use mysql;
select * from user;
select * from db;
select * from host;
select * from tables_priv;
select * from columns_priv;
-- 回收用户在特定数据库上的特定权限
REVOKE SELECT, INSERT ON database_name.* FROM 'username'@'host';
-- 回收所有权限但保留用户账号
REVOKE ALL PRIVILEGES ON database_name.* FROM 'username'@'host';
-- 回收全局权限
REVOKE SUPER, PROCESS ON *.* FROM 'username'@'host';
-- 回收用户的授权权限
REVOKE GRANT OPTION ON *.* FROM 'username'@'host';
  1. 安装最新补丁
  • 确保系统安装了最新的安全补丁
  1. 设置可信IP访问控制
  • 通过OS防火墙设置IP访问控制
  1. 删除不使用的客户端程序
  • 删除/usr/bin 路径下除了mysql/mysqlbinlog/mysqldump 外的其它 mysql 客户端程序:
rm -rf /usr/bin/mysqladmin
rm -rf /usr/bin/mysqlcheck
rm -rf /usr/bin/mysql_config
rm -rf /usr/bin/mysql_config-64
rm -rf /usr/bin/mysql_config_editor
rm -rf /usr/bin/mysqld_pre_systemd
rm -rf /usr/bin/mysqldumpslow
rm -rf /usr/bin/mysqlimport
rm -rf /usr/bin/mysql_install_db
rm -rf /usr/bin/mysql_plugin
rm -rf /usr/bin/mysqlpump
rm -rf /usr/bin/mysql_secure_installation
rm -rf /usr/bin/mysqlshow
rm -rf /usr/bin/mysqlslap
rm -rf /usr/bin/mysql_ssl_rsa_setup
rm -rf /usr/bin/mysql_tzinfo_to_sql
rm -rf /usr/bin/mysql_upgrade
  • 删除/usr/share/man/man1/目录下除了/usr/share/man/man1/mysql.1.gz 外的其它 mysql 相关帮助文档:
 ls /usr/share/man/man1/mysql |grep -w -v mysql.1 |xargs rm
  • 检查客户端程序是否已删除:
ls -al /usr/bin/mysqladmin
ls -al /usr/bin/mysqlcheck
ls -al /usr/bin/mysql_config
ls -al /usr/bin/mysql_config-64
ls -al /usr/bin/mysql_config_editor
ls -al /usr/bin/mysqld_pre_systemd
ls -al /usr/bin/mysqldumpslow
ls -al /usr/bin/mysqlimport
ls -al /usr/bin/mysql_install_db
ls -al /usr/bin/mysql_plugin
ls -al /usr/bin/mysqlpump
ls -al /usr/bin/mysql_secure_installation
ls -al /usr/bin/mysqlshow
ls -al /usr/bin/mysqlslap
ls -al /usr/bin/mysql_ssl_rsa_setup
ls -al /usr/bin/mysql_tzinfo_to_sql
ls -al /usr/bin/mysql_upgrade
  1. 禁止设置SKIP-SECURE-AUTH
  • skip-secure-auth 会关闭 secure_auth,将允许使用 mysql_old_password 插件存储密码的用户连接数据库,因此禁止设置 skip-secure-auth
 # 检查skip-secure-auth:
 show variables like 'secure_auth';
 # mysqld.cnf 配置文件中删除[mysqld] skip-secure-auth
 [mysqld] 
 skip-secure-auth。
  1. 设置 MASTER_INFO_REPOSITORY、RELAY-LOG-INFO-REPOSITORY
  • MASTER_INFO_REPOSITORY
    定义:控制主从复制中主库连接信息的存储方式
    作用:记录连接到主库所需的用户名、密码、主机名、端口等认证信息

  • RELAY_LOG_INFO_REPOSITORY
    定义:控制中继日志(relay log)元数据的存储方式
    作用:记录从库读取主库二进制日志的位置和执行进度

FILE文件存储 TABLE数据库存储

SET GLOBAL MASTER_INFO_REPOSITORY = 'TABLE';
SET GLOBAL RELAY_LOG_INFO_REPOSITORY = 'TABLE';

# 在my.cnf或mysqld.cnf中添加
[mysqld]
master_info_repository = TABLE
relay_log_info_repository = TABLE

23.禁止使用MYSQL_PWD环境变量

# 检查当前环境变量
env | grep MYSQL_PWD

# 检查所有用户的profile文件
grep -r "MYSQL_PWD" /etc/profile /etc/profile.d/ /home/*/.bashrc /home/*/.bash_profile

# 查看是否有进程使用该环境变量
ps auxe | grep MYSQL_PWD

# 取消当前环境变量
unset MYSQL_PWD
# 确保后续不能设置
export MYSQL_PWD=
  1. 限制安装文件属主和权限
 show variables where variable_name = 'plugin_dir';
 plugin_dir /usr/lib64/mysql/plugin/
 # 权限需要是500
 ls -l /usr/lib64/mysql
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值