天天看點

Linux 系統與資料庫安全

<a href="http://netkiller.github.com/article/security.html">http://netkiller.github.com/article/security.html</a>

版權 © 2011, 2012 http://netkiller.github.com

摘要

linux 系統安全問題

<a></a>

下面是我多年積累下來的經驗總結,整理成文檔供大家參考:

<a target="_top" href="http://netkiller.github.com/architect/index.html">netkiller architect 手劄</a>

<a target="_top" href="http://netkiller.github.com/linux/index.html">netkiller linux 手劄</a>

<a target="_top" href="http://netkiller.github.com/developer/index.html">netkiller developer 手劄</a>

<a target="_top" href="http://netkiller.github.com/database/index.html">netkiller database 手劄</a>

<a target="_top" href="http://netkiller.github.com/debian/index.html">netkiller debian 手劄</a>

<a target="_top" href="http://netkiller.github.com/centos/index.html">netkiller centos 手劄</a>

<a target="_top" href="http://netkiller.github.com/freebsd/index.html">netkiller freebsd 手劄</a>

<a target="_top" href="http://netkiller.github.com/shell/index.html">netkiller shell 手劄</a>

<a target="_top" href="http://netkiller.github.com/www/index.html">netkiller web 手劄</a>

<a target="_top" href="http://netkiller.github.com/monitoring/index.html">netkiller monitoring 手劄</a>

<a target="_top" href="http://netkiller.github.com/storage/index.html">netkiller storage 手劄</a>

<a target="_top" href="http://netkiller.github.com/mail/index.html">netkiller mail 手劄</a>

<a target="_top" href="http://netkiller.github.com/security/index.html">netkiller security 手劄</a>

<a target="_top" href="http://netkiller.github.com/multimedia/index.html">netkiller multimedia 手劄</a>

<a target="_top" href="http://netkiller.github.com/docbook/index.html">netkiller writer 手劄</a>

<a target="_top" href="http://netkiller.github.com/version/index.html">netkiller version 手劄</a>

<a target="_top" href="http://netkiller.github.com/postgres/index.html">netkiller postgresql 手劄</a>

<a target="_top" href="http://netkiller.github.com/mysql/index.html">netkiller mysql 手劄</a>

<a target="_top" href="http://netkiller.github.com/cryptography/index.html">netkiller cryptography 手劄</a>

<a target="_top" href="http://netkiller.github.com/cisco/index.html">netkiller cisco ios 手劄</a>

<a target="_top" href="http://netkiller.github.com/ldap/index.html">netkiller ldap 手劄</a>

<a target="_top" href="http://netkiller.github.com/intranet/index.html">netkiller intranet 手劄</a>

目錄

帳号權限安全

需求:限制使用者權限,僅提供一些linux常用指令,使用者監控linux系統于網絡運作情況,不允許使用者ssh登入後随意運作linux指令

使用者不能進入到shell環境

使用者可以了解os工作狀态如記憶體,cpu,網絡等等

例如:ping, tracepath, top, free, netstat

可以檢視系統部分日志

例如:access.log, error.log, php-error.log ...

使用mgmt替代bash

shell 啟動檔案,主要使用者隐藏 /srv/sbin/mgmt 檔案(針對菜鳥)

編譯.c檔案

添加shell到/etc/shells

将使用者shell更改為我們剛剛建立的nsh

現在來作一個測試,如果正确應該現在為下面的tui界面

這裡采用的方式是給使用者提供一個界面的方式,另外還有更好的方案,你可以些一個shell的外殼,你需要實作

與shell相同的提示符

提供tab補齊

上下光标鍵翻看曆史指令,左右光标改變位置,home/end 鍵到行首與行尾

ctrl+r 搜尋, ctrl+d 退出

ctrl+s,ctrl+q 等等

流程

例如使用者輸入 cd / 經過過濾器後, cd /home/usr/

例如使用者輸入 cd /aaa 經過過濾器後, cd /home/usr/aaa

rm -rf /usr/local 提示拒絕等等

sa的操作記錄問題

通過~/.bash_history檔案記錄系統管理者的操作記錄,定制.bash_history格式

看看實際效果

dba 沒有系統ssh帳号,隻有資料庫帳号

系統管理者隻能有ssh系統帳号,沒有資料庫帳号

dba 可備份資料庫,還原資料庫指定的備份檔案,但是接觸不到備份檔案

dba 有權重新開機資料庫以及修複損壞庫/表檔案,通過工具完成,而不是登入ssh運作指令

dba不需要通過ssh登入資料庫伺服器,然後運作mysql/sqlplus在登入資料庫

/etc/php5/fpm/pool.d/www.conf

進入mysql用戶端

從安全角度看,你可以去掉輸入密碼的過程。在終端提示符下輸入

enter password:

還可以寫入~/.my.conf檔案

這樣ssh [email protected]的時候輸入第一道密碼,然後進入mysql不需要輸入密碼

如果需要輸入密碼對話到建議删除.bash_history

rm -rf .bash_history

ln -s /dev/null .bash_history

通過~/.mysql_history檔案記錄dba操作記錄

插入時間點,在~/.bashrc中加入下面指令

檢視實際效果

一般資料庫伺服器上可以保留一周的備份資料,曆史資料需要儲存到伺服器以外的帶庫或者陣列櫃中,怎麼樣保證這些資料的安全呢? 我們采用下面方式

制作pgp/gpg密鑰,密鑰放置在資料庫伺服器上,證書做好備份,否則一旦丢失,将無法在将備份檔案恢複

資料庫備份後,首先進行壓縮處理

然後使用公鑰證書進行gpg/pgp資料加密

這時可以放心的将備份資料庫搬出資料庫伺服器到帶庫或磁盤陣列櫃中

恢複資料,将資料庫備份檔案複制到該資料庫伺服器,然後用私鑰解密備份檔案,再恢複到資料庫到中

有時候需要将生産環境的資料複制到開發環境上,例如,測試的時候,重制bug需要真實資料,開發環境的模拟資料無法滿足要求,這時需要将生産環境的資料拉到測試或開發環境。如果保證資料的安全非常重要。

最有效的手段是資料混淆,将重要的資料進行混淆擾亂順序等等

擾亂手段有

颠倒順序

曾加幹擾詞

重置或替換資料,例如密碼可以全部改為test (update user set passwd='test')

拼裝資料 如 (131,137,135,133,139,138,168)後面加8位随機數

其他伺服器不能安裝mysql用戶端與mysqldump備份工具

同時封鎖22等端口,避免互相跳轉

web 伺服器禁止使用ssh,作為跳闆機