天天看點

RHS333-11 入侵檢測

 Linux入侵檢測

一、iptables實作日志記錄網絡流量

[root@station2 aide]# iptables -A INPUT -p tcp --dport 80 -j LOG --log-prefix="80"

[root@station2 aide]# tail /var/log/messages

Apr  5 23:23:35 station2 kernel: 80IN=eth0 OUT= MAC=54:52:00:67:6f:33:00:18:8b:7c:67:87:08:00 SRC=192.168.32.221 DST=192.168.32.32 LEN=353 TOS=0x00 PREC=0x00 TTL=127 ID=3155 DF PROTO=TCP SPT=56663 DPT=80 WINDOW=4420 RES=0x00 ACK PSH URGP=0

Apr  5 23:23:35 station2 kernel: 80IN=eth0 OUT= MAC=54:52:00:67:6f:33:00:18:8b:7c:67:87:08:00 SRC=192.168.32.221 DST=192.168.32.32 LEN=40 TOS=0x00 PREC=0x00 TTL=127 ID=3156 DF PROTO=TCP SPT=56663 DPT=80 WINDOW=4302 RES=0x00 ACK URGP=0

Apr  5 23:23:35 station2 kernel: 80IN=eth0 OUT= MAC=54:52:00:67:6f:33:00:18:8b:7c:67:87:08:00 SRC=192.168.32.221 DST=192.168.32.32 LEN=40 TOS=0x00 PREC=0x00 TTL=127 ID=3157 DF PROTO=TCP SPT=56663 DPT=80 WINDOW=4302 RES=0x00 ACK FIN URGP=0

二、開發端口監控

1、本地監控:netstat

[root@station2 ~]# netstat -tulpn   #監控端口開放

[root@station2 ~]# netstat -tupn    #監控活動連結

2、遠端監控:nmap (gui工具:nmapfe)

[root@station2 ~]#nmap -P0 station3.example.com   #掃描主機

[root@station2 ~]#nmap -sV 192.168.32.0/24        #掃描網段

三、檢查檔案是否修改

1、md5sum(通過檢查檔案的hash值變化)

[root@station2 ~]# md5sum install.log

7d0c76c92baf8ec23714e38d99ad48f7  install.log

[root@station2 ~]# echo "1111">>install.log

[root@station2 ~]# md5sum install.log     

470d4cd0bbfe77613ecb614fd02e86e0  install.log

2、tripwire

3、rpm

[root@station2 ~]# rpm -Vf /etc/hosts.allow

S.5....T  c /etc/aliases

S.5....T  c /etc/printcap

      # 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

四、aide(進階入侵檢測環境)

AIDE檢測對系統管理檔案的任何修改,AIDE是Tripware的替代品。它提供簡便的配置和詳細的報表。

1、安裝

[root@station2 ~]# yum install aide

2、修改配置檔案/etc/aide.conf,指定要求檢查的系統檔案

[root@station2 ~]# vi /etc/aide.conf

3、生成檢查資料庫

[root@station2 ~]# aide -i

AIDE, version 0.13.1

### AIDE database at /var/lib/aide/aide.db.new.gz initialized.

[root@station2 ~]# cp /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz

#生成入侵檢測資料庫/var/lib/aide/aide.new.db.gz,必須修改成aide.db.gz。aide的資料庫是aide.db.gz,預設生成aide.new.db.gz是為了避免更新時覆寫原資料庫。

4、測試

[root@station2 ~]# echo "vsftpd: All: 192.168.32.33">>/etc/hosts.allow

[root@station2 ~]# aide --check

File: /etc/hosts.allow

  Mtime    : 2011-04-05 22:31:05              , 2011-04-05 23:47:00

  Ctime    : 2011-04-05 22:31:05              , 2011-04-05 23:47:00

  Inode    : 7458581                          , 7458490

  MD5      : cX97u2rExsuNyiOLdj/8vw==         , yq5XmgvQaEMfuR6STPPKVw==

  RMD160   : bX8Xnn90YGotaxpN/nsHQTBM+W0=     , r3Sb2RlBnZI38i4IyuWaVpurHk4=

  SHA256   : BD7vdNOGmxiFuhEvG87Y3ysbdJeHnIUU , vYwvU0mVeqI6ynTu2t8zqto9z5d6iE2q

#檢測顯示/etc/hosts.allow被修改

五、磁盤備份鏡像

[root@station2 ~]#dd if=/dev/hdd of=/home/image-hdd.img bs=1k conv=noerror,sync

#conv=noerror:出現磁盤錯誤不停止備份,sync不同記憶體直接備份,加快備份速度

[root@station2 ~]#$mount -o loop /home/image-hadd.img /mnt

#挂載備份鏡像

六、後面檢測

1、lsof:檢查打開的檔案

2、fuser:檢查使用檔案的程序,并對其處理

[root@station2 ~]# fuser /usr/sbin/saslauthd  #檢視運作檔案的程序

/usr/sbin/saslauthd: 26360e 26361e 26362e 26363e 26365e

[root@station2 ~]# fuser -k /usr/sbin/saslauthd  #關閉運作檔案的程序

[root@station2 ~]# fuser /usr/sbin/saslauthd  

本文轉自netsword 51CTO部落格,原文連結:http://blog.51cto.com/netsword/536091