轉自 http://linuxart.blog.51cto.com/686203/844011
使用iptables進行輕量級別的防護。
limit模塊
限制單位時間內,機器所能承受最大併發量。
演示limit的例子
# iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j ACCEPT
# iptables -A INPUT -p icmp -j DROP
結合http協議
# iptables -A INPUT -p tcp --dport 80 -m limit --limit 10000/s --limit-burst 10000 -j ACCEPT
# iptables -A INPUT -p tcp --dport 80 -j DROP
缺點:不會根據IP來進行限制,僅僅是對所有的請求進行統計從而實現限制。
connlimit模塊
限制單個IP與服務器最多建立的連接數。
安裝模塊:
patch-o-matic-ng-20090507.zip
使用例子:
限制當個IP只能和服務器最多建立16個連接
# iptables -A INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 16 -j DROP
====================================
硬盤加密
11.jpg ---> ext3 --> sda1
11.jpg --> ext3 ---> 加密層 --> sda1
sda1 ---> 解密 --> ext3 --> 11.jpg
cryptsetup工具加密硬盤數據
1、新建一個分區(使用現有分區,原有的數據就會完全丟失)
2、對需要加密的分區進行初始化
# cryptsetup --verbose --verify-passphrase -c aes-cbc-plain luksFormat /dev/sda9
WARNING!
========
This will overwrite data on /dev/sda9 irrevocably.
Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase:
Verify passphrase:
Command successful.
3、加密完成之後,每次使用都需要把映射出來的加密設備打開,去操作該設備。
# cryptsetup luksOpen /dev/sda9 sda9_crypt
Enter LUKS passphrase for /dev/sda9:
key slot 0 unlocked.
Command successful.
生成了一個映射的設備 sda9_crypt
數據----> ext3 ---> sda9_crypt ----加密處理----> /dev/sda9
# ll /dev/mapper/sda9_crypt
4、格式化後存放數據。
# mkfs.ext3 /dev/mapper/sda9_crypt
# mount /dev/mapper/sda9_crypt /mnt
5、取消掛載,關閉加密的分區
# umount /dev/mapper/sda9_crypt
# cryptsetup luksClose sda9_crypt
修改密碼:
新增加一個密碼
# cryptsetup luksAddKey /dev/sda9
Enter any LUKS passphrase: 《--舊密碼
Verify passphrase: 再次確認
key slot 0 unlocked.
Enter new passphrase for key slot: 《--新密碼
Verify passphrase:
Command successful.
刪除舊密碼,必須保留至少一個密碼
# cryptsetup luksDelKey /dev/sda9 0 《--- 0是密碼slot編號
Command successful.
=================================
基於主機的***檢測軟件(HIDS)
工作原理:
監控系統重要文件的變更。
rpm工具
# rpm -Vf /etc/httpd/conf/httpd.conf
S.5....T c /etc/httpd/conf/httpd.conf
S file Size differs
M Mode differs (includes permissions and file type)
5 MD5 sum differs
D Device major/minor number mismatch
L readLink(2) path mismatch
U User ownership differs
G Group ownership differs
T mTime differs
只支持由rpm包釋放出來的文件
tripwire
1、安裝
# rpm -ivh tripwire-2.4.1.1-1.el5.i386.rpm
2、配置
# cd /etc/tripwire/
# ls
twcfg.txt twpol.txt
修改策略
# man twpolicy
- Ignore the following properties
+ Record and check the following properties
a Access timestamp
b Number of blocks allocated
c Inode timestamp (create/modify)
d ID of device on which inode resides
g File owner’s group ID
i Inode number
l File is increasing in size (a "growing file")
m Modification timestamp
n Number of links (inode reference count)
p Permissions and file mode bits
r ID of device pointed to by inode
(valid only for device objects)
s File size
t File type
u File owner’s user ID
C CRC-32 hash value
H Haval hash value
M MD5 hash value
S SHA hash value
# vim twpol.txt
定一個簡單的策略
(
rulename = "webroot check",
severity = $(SIG_HI)
)
{
/share/08/ ->$(SEC_CRIT);
!/share/08/sec_01;
!/share/08/ula_05.txt;
}
3、生成密鑰
# /usr/sbin/tripwire-setup-keyfiles
分別輸入sitekey 私鑰,localkey公鑰密碼
還有把策略文件和配置文件進行簽名
tw.cfg , tw.pol
4、初始化系統文件的狀態數據,保存到數據文件中
# tripwire --init
...
Wrote database file: /var/lib/tripwire/dev.upl.com.twd
The database was successfully generated.
5、測試
根據策略的規則進行檢查
# tripwire --check --rule-name "webroot check"
...
Performing integrity check...
Wrote report file: /var/lib/tripwire/report/dev.upl.com-20110831-153115.twr
....
查看報告文件
# twprint --print-report --twrfile /var/lib/tripwire/report/dev.upl.com-20110831-153115.twr
檢查所有文件:
# tripwire --check
Wrote report file: /var/lib/tripwire/report/dev.upl.com-20110831-154224.tw
報告中,有很多文件是不存在,會出現報錯,還有一些文件被修改了但這些文件你認爲正常的修改操作,不想在下一次檢測中再次出現警告,應該數據文件,把這些更改的操作納入數據文件中:
# LANG=C tripwire --update --twrfile /var/lib/tripwire/report/dev.upl.com-20110831-154224.twr
Added:
[x] "/share/08/sec_05/DedecmsV55-UTF8-Final.tar.gz"
Removed:
[x] "/share/08/11.txt"
Modified:
[x] "/share/08"
[x] "/share/08/sec_05" 《---保留x,就說明要把該文件的最新狀態更新到數據庫
《--哪些文件是正常的修改操作,就應該保留x
保存退出,輸入公鑰密碼就能更新數據文件
Please enter your local passphrase:
Wrote database file: /var/lib/tripwire/dev.upl.com.twd
====================================
一些基本的安全操作:
託管到安全的受信任的機房。
設定bois密碼,屏蔽掉軟區引導,光驅引導,網絡引導等其他外設引導
設定grub密碼
設定強壯系統密碼。指定好密碼策略,密碼一定要加密,使用屏蔽口令,刪除沒有用的帳號或者禁止使用這些帳號
禁止快捷鍵重啓
停止沒有用的服務
修改系統的登錄用的banner: /etc/issue, /etc/issue.net