基线管理之MariaDB安全配置
實驗?zāi)康?/span>
MariaDB的安全配置過程與配置方法,掌握數(shù)據(jù)庫安全配置對安全運維至關(guān)重要。
實驗環(huán)境
一臺Centos7 已安裝MariaDB數(shù)據(jù)庫
MariaDB安裝命令如下
yum -y install mariadb實驗原理
通過配置文件與數(shù)據(jù)庫的配置,實現(xiàn)MariaDB安全配置
實驗步驟
一、操作系統(tǒng)級權(quán)限檢查
1、檢查數(shù)據(jù)庫的運行權(quán)限(每排第一個),不建議以root運行數(shù)據(jù)庫,防止越權(quán)攻擊
ps -ef | egrep "^mysql.*$"如圖顯示mysqld的運行用戶為mysql
2、禁用mariadb的歷史記錄功能
查找緩存文件
find $HOME -name ".mysql_history"將緩存文件指向空文件
rm -f $HOME/.mysql_history ln -s /dev/null $HOME/.mysql_history3、查看并配置數(shù)據(jù)庫存放路徑權(quán)限
登錄數(shù)據(jù)庫
mysql -u root -p查看數(shù)據(jù)庫存放路徑
show variables where variable_name = 'datadir';
退出數(shù)據(jù)庫
quit
查看數(shù)據(jù)庫存放路徑權(quán)限
ls -l /var/lib | grep mysql
如圖權(quán)限為755,使用以下命令改為700
chmod 700 /var/lib/mysql
二、Mariadb數(shù)據(jù)庫的通用安全配置
1、刪除默認(rèn)的test數(shù)據(jù)庫
進入數(shù)據(jù)庫
mysql -u root
show DATABASES LIKE 'test';
刪除數(shù)據(jù)庫
DROP DATABASE 'test';
2、禁用local_infile參數(shù)
查看local_infile參數(shù)是否開啟
show variables where variable_name = 'local_infile';
如上圖顯示local_infile 是開啟狀態(tài),需要修改mariadb配置文件。修改方法,見后文。
3、修改secure_file_priv參數(shù)
查看secure_file_priv參數(shù)
SHOW GLOBAL VARIABLES WHERE Variable_name = 'secure_file_priv' ;
如圖顯示路徑為空,表示所有路徑,建議設(shè)置為固定值,需要修改mariadb配置文件。修改方法,見后文。
4、確定只有root用戶有內(nèi)置數(shù)據(jù)庫mysql的權(quán)限
查看內(nèi)置數(shù)據(jù)庫的權(quán)限
SELECT user, host FROM mysql.user WHERE (Select_priv = 'Y') OR (Insert_priv = 'Y') OR (Update_priv = 'Y') OR (Delete_priv = 'Y') OR (Create_priv = 'Y') OR (Drop_priv = 'Y');
5、查看file_priv權(quán)限,確定只有root用戶有
select user, host from mysql.user where file_priv = 'Y';
撤銷用戶權(quán)限
如果在上例檢查中,發(fā)現(xiàn)非root用戶,可以使用下面命令撤銷
revoke file on *.* from 'user';
同時這里檢查權(quán)限還應(yīng)有process_priv、super_priv這些字段。
6、配置允許用戶登錄的主機
查看當(dāng)前用戶可以登錄的主機
select user,host from mysql.user;
更新用戶允許登錄的主機,如
update mysql.user set host="192.168.1.200" where host="localhost" and user="root";
7、查看密碼安全策略
show variables like 'validate_password%';
三、驗證安全配置
1、生成兩個任意文件
echo 1111 > /tmp/111.txt
echo 2222 > /var/lib/mysql-files/222.txt
2、進入數(shù)據(jù)庫
mysql -u root
3、導(dǎo)入文件,前面我們查看參數(shù)時,發(fā)現(xiàn)local_infile參數(shù)為on
執(zhí)行以下操作
創(chuàng)建數(shù)據(jù)庫
create database temp;
use temp;
創(chuàng)建表,并導(dǎo)入/tmp/111.txt
create table table_test(cmd text);
insert into table_test(cmd) values (load_file('/tmp/111.txt'));
select cmd from table_test;
再次導(dǎo)入/var/lib/mysql/222.txt
insert into table_test(cmd) values (load_file('/var/lib/mysql/222.txt'));
select cmd from table_test;
發(fā)現(xiàn)導(dǎo)入成功
3、配置禁止導(dǎo)入,與導(dǎo)入路徑
退出數(shù)據(jù)庫
quit
編輯數(shù)據(jù)庫配置文件
vim /etc/my.cnf
加入下面行,指定允許導(dǎo)入的路徑,如/tmp
secure_file_priv=/tmp
保存并退出文件
重啟mariadb數(shù)據(jù)庫
systemctl restart mariadb
進入數(shù)據(jù)庫
mysql -u root -h 127.0.0.1
嘗試導(dǎo)入文件
use temp;
insert into table_test(cmd) values (load_file('/var/lib/mysql/222.txt'));
select * from table_test;
雖然提示執(zhí)行成功,但查看數(shù)據(jù)庫時,發(fā)現(xiàn)值為NULL
實驗總結(jié)
通過mariadb的配置文件與參數(shù)查看,理解mariadb的一些安全配置。
總結(jié)
以上是生活随笔為你收集整理的基线管理之MariaDB安全配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基线管理之Centos安全配置
- 下一篇: Linux虚拟机改中文