hm3030 发表于 2012-6-15 16:35:18

MySQL安全和管理

本帖最后由 hm3030 于 2012-6-15 16:40 编辑

目的:
[*]识别MySQL 安全问题
[*]改进MySQL 安装过程
[*]识别数据问题
[*]提高数据一致性和安全
[*]审计


安装安全:

[*]默认是可怕的

                  hack MySQL:


[*] MySQL默认安装对super用户无密码可以登录
[*]匿名访问
[*]在配置文件里面提供superuser和密码
[*]shell里面带密码登录,history文件
[*]无权限的用户可以访问MySQL权限表:整个mysql库
[*]能启动和停止mysqld进程,可以重置密码:--skip-grant-tables
[*]暴力检查
[*]应用使用明文密码,用户可能有某些特权

                   破坏MySQL:

[*]窃取CPU周期:select md5(a.c),md5(b.c) from a,b order by rand();
[*]强迫disk I/O:set session tmp_table_size=1024*4;
[*]匿名访问            


[*]最低限度:$mysql_secure_installation
[*]

[*]移除匿名用户
[*]移除test库
[*]移除非localhost root用户
[*]设置root密码                  

操作系统

[*]默认总是不安全的
[*]永远不要用root用户运行mysqld
[*]分离data、binary logs、logs、configuration、backups、个别目录权限
[*]root用户安装,单独MySQL目录的权限:


chown -R root:root PATH/mysql
chown -R mysql:mysql PATH/mysql/{data,log,binlog,etc}
chmod 700 PATH/mysql/{data,binlog}
chmod 750 PATH/mysql/{etc,log}

[*]网络
[*]

[*]MySQL监听的TCP/IP端口
[*]

[*]默认端口3306
[*]--skip-networking 禁用tcp/ip

[*]防火墙管理
权限和特权

[*]用户权限
[*]

[*]最佳方法:


create user admin@localhost identified by 'admin_password';
grantcreate,select,insert,update,delete on db.* to admin@localhost;

[*]

[*]通常方法:                        


                               create user super_user@'%';
                               grant all on *.* to super_user@'%';

[*]grant all on *.*
[*]

[*]grant all on *.* to user@'%';         

                              *.*       让你可以访问所以库里面所以表
                                 @‘%’   让你可以从任何外部位置访问
                                 All         授予你所以权限

[*]super权限
[*]

[*]绕过read_only
[*]绕过init_connect
[*]能禁用binary log
[*]能动态改变配置文件
[*]无保留连接
[*]应用用户
[*]

[*]应用仅读访问:select
[*]应用读写访问:insert,update,delete,select
[*]应用DBA(仅schema访问):create,drop,create routine,select,insert,update,delete,...
[*]新的功能
[*]

[*]user authentication interface: http://dev.mysql.com/doc/refman/5.5/en/authentication-plugins.html
[*]PAM/LDAP authentication(5.6 Enterprise) https://blogs.oracle.com/MySQL/entry/new_commercial_extensions_for_mysql

数据一致性(data in != data out?)

[*]sql_mode:strict_all_tables,no_zero_date,no_zero_in_date,no_engine_substitution

审计

[*]status variables :select variable_name,variable_vaule from information_schema.global_status where variable_name like 'com_alter%';
[*]binary log:mysqlbinlog /path/binlog_file > binlog.txt ;grep -ie ALTER -e CREATE -e DROP binlog.txt
[*]schema比较:mysqldump -uroot -p --no-data --all-databases --skip-dump-date|sed -e "s/AUTO_INCREMENT=[^\ ] / /">schema.`date +%Y%m%d.%H%M`sql; diff schema.1 schema.2
[*]审计插件(5.5): http://dev.mysql.com/doc/refman/5.5/en/audit-plugins.html
总结:


[*]MySQL默认不是安全的
[*]OS安全
[*]合适的用户权限
不涵盖:

[*]Replication
[*]SSL
[*]Backups
[*]SQL Injection


                                          
页: [1]
查看完整版本: MySQL安全和管理