MySQL AUDIT Plugin是一个 MySQL安全审计插件,由McAfee提供,设计强调安全性和审计能力。该插件可用作独立审计解决方案,或配置为数据传送给外部监测工具。支持版本为MySQL (5.1, 5.5, 5.6, 5.7),MariaDB (5.5, 10.0, 10.1) ,Platform (32 or 64 bit)。从Mariadb 10.0版本开始audit插件直接内嵌了,名称为server_audit.so,可以直接加载使用。
二进制文件地址:https://bintray.com/mcafee/mysql-audit-plugin/release
macfee的mysql audit插件虽然日志信息比较大,对性能影响大,但是如果想要开启审计,请斟酌。
二、安装使用MySQL AUDIT
# unzip audit-plugin-mysql-5.6-1.1.5-774-linux-x86_64.zip
MySQL的插件目录为:
mysql>show global variables like 'plugin_dir'
+---------------+------------------------+
| Variable_name | Value |
+---------------+------------------------+
| plugin_dir | /app/mysql/lib/plugin/ |
+---------------+------------------------+
1 row in set (0.00 sec)
复制库文件到MySQL库目录下
# cp audit-plugin-mysql-5.6-1.1.2-694/lib/libaudit_plugin.so /app/mysql/lib/plugin/
# chmod a+x /app/mysql/lib/plugin/libaudit_plugin.so
加载Audit插件
mysql>INSTALL PLUGIN AUDIT SONAME 'libaudit_plugin.so'
查看版本
mysql>show global status like '%audit%'
+------------------------+-----------+
| Variable_name | Value |
+------------------------+-----------+
| Audit_protocol_version | 1.0 |
| Audit_version | 1.1.2-694 |
+------------------------+-----------+
2 rows in set (0.00 sec)
开启Audit功能
mysql>SET GLOBAL audit_json_file=ON
Query OK, 0 rows affected (0.00 sec)
执行任何语句(默认会记录任何语句),然后去mysql数据目录查看mysql-audit.json文件(默认为该文件)。
当然,我们还可以通过命令查看audit相关的命令。
mysql>SHOW GLOBAL VARIABLES LIKE '%audit%'
其中我们需要关注的参数有:
1、audit_json_file
是否开启audit功能。
2、audit_json_log_file
记录文件的路径和名称信息。
3、audit_record_cmds
audit记录的命令,默认为记录所有命令。可以设置为任意dml、dcl、ddl的组合。如:audit_record_cmds=select,insert,delete,update。还可以在线设置set global audit_record_cmds=NULL。(表示记录所有命令)
4、 audit_record_objs
audit记录 *** 作的对象,默认为记录所有对象,可以用SET GLOBAL audit_record_objs=NULL设置为默认。也可以指定为下面的格式:audit_record_objs=,test.*,mysql.*,information_schema.*。
5、audit_whitelist_users
用户白名单。
三、查看审计数据
插入一些数据,查看一下mysql-audit.json文件信息(json格式),如下:
$ cat /app/mysql/data/mysql-audit.json
{"msg-type":"activity","date":"1517989674556","thread-id":"3","query-id":"39","user":"root","priv_user":"root","ip":"","host":"localhost","connect_attrs":{"_os":"Linux","_client_name":"libmysql","_pid":"1331209","_client_version":"5.6.27","_platform":"x86_64","program_name":"mysql"},"pid":"3472328296227680304","os_user":"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","appname":"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","rows":"10","cmd":"select","objects":[{"db":"sbtest","name":"sbtest1","obj_type":"TABLE"}],"query":"select * from sbtest1 limit 10"}
审计记录文件一般存放在mysql的数据目录下。
注意点: 1.当拥有SUPER权限的用户连接时,init_connect设定的sql语句不会被执行 2.务必保证init_connect设定的sql语句没有任何错误,要不然连接会出错。 3.此参数可以让局部变量像全局变量那在配置文件设置属性: 全局、字符串、可动态修改 一.示例1 SET GLOBAL init_connect='SET AUTOCOMMIT=0'还可以在命令行或选项文件中设置该变量。要想使用选项文件设置变量,应包括下述行: [mysqld] init_connect='SET AUTOCOMMIT=0' 请注意init_connect的内容并不为拥有SUPER权限的用户执行;实际是内容设置错误(包含错误查询,例如语法错误),这样使所有连接失败。不为SUPER用户执行,使SUPER用户可以打开连接并固定init_connect。 二、示例2 此参数可以用于做登陆审计。 mysql TABLE `wsz` ( `i` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`i`) ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1 mysql SET GLOBAL init_connect="SET AUTOCOMMIT=0insert into test.wsz values ('')"Query OK, 0 rows affected (0.00 sec) 退出后用普通用户登陆: [seezoo@dbaview.cn ~]$ /home/seezoo/mysql/mysql50134/bin/mysql -S /home/seezoo/mysql/mysql50134/mysql.sock Welcome to the MySQL monitor. Commands end with or /g. Your MySQL connection id is 25 Server version: 5.1.34 Source distribution Type 'help' or '/h' for help. Type '/c' to clear the current input statement. mysql select @@autocommit+--------------+ | @@autocommit | +--------------+ | 0 | +--------------+ 1 row in set (0.00 sec) mysql select * from test.wsz+---+ | i | +---+ | 1 | | 2 | | 3 | | 4 | | 5 | +---+ 5 rows in set (0.00 sec) 用root用户登陆后发现相关值没修改: [seezoo@dbaview.cn ~]$ /home/seezoo/mysql/mysql50134/bin/mysql -uroot -S /home/seezoo/mysql/mysql50134/mysql.sock Welcome to the MySQL monitor. Commands end with or /g. Your MySQL connection id is 26 Server version: 5.1.34 Source distribution Type 'help' or '/h' for help. Type '/c' to clear the current input statement. mysql select * from test.wsz+---+ | i | +---+ | 1 | | 2 | | 3 | | 4 | | 5 | +---+ 5 rows in set (0.00 sec) mysql select @@autocommit+--------------+ | @@autocommit | +--------------+ | 1 | +--------------+ 1 row in set (0.00 sec) [seezoo@dbaview.cn ~]$ /home/seezoo/mysql/mysql50134/bin/mysql -S /home/seezoo/mysql/mysql50134/mysql.sock Welcome to the MySQL monitor. Commands end with or /g. Your MySQL connection id is 27 Server version: 5.1.34 Source distribution Type 'help' or '/h' for help. Type '/c' to clear the current input statement. mysql select @@autocommit+--------------+ | @@autocommit | +--------------+ | 0 | +--------------+ 1 row in set (0.00 sec) mysql select * from test.wsz+---+ | i | +---+ | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | +---+ 6 rows in set (0.00 sec)欢迎分享,转载请注明来源:内存溢出
评论列表(0条)