天天看點

入侵檢測

轉自 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.

 生成了一個映射的裝置 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:  再次确認

Enter new passphrase for key slot:  《--新密碼

Verify passphrase:  

 删除舊密碼,必須保留至少一個密碼

# cryptsetup luksDelKey /dev/sda9 0  《--- 0是密碼slot編号

=================================

基于主機的入侵檢測軟體(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

繼續閱讀