CentOS 7 安全強化、檢測、審計
RKHunter:檢測Rootkit
RKHunter 傳送門:http://rkhunter.sourceforge.net/
Root Kit 詳解:http://linux.vbird.org/linux_security/0420rkhunter.php
[root@linuxprobe ~]# yum --enablerepo=epel -y install rkhunter
- 配置和使用RKHunter,對於常規檢查,檢查指令碼安裝在cron.daily目錄下,並由Cron每天執行
[root@linuxprobe ~]# vi /etc/sysconfig/rkhunter# recipient address for reportMAILTO=root@localhost# if specified "yes", scan more detailyDIAG_SCAN=no# update database[root@linuxprobe ~]# rkhunter --update# update system file properties[root@linuxprobe ~]# rkhunter --propupd # execute checking# --sk means sikpping to push Enter key# if specified --rwo , display only warnings[root@linuxprobe ~]# rkhunter --check --sk
Lynis
安全審計工具 Lynis 傳送門:https://cisofy.com/lynis/
[root@linuxprobe ~]# yum --enablerepo=epel -y install lynis
[root@linuxprobe ~]# lynis audit system
相關文檔Lynis 教程: http://netsecurity.51cto.com/art/201410/455466.htm
AIDE 簡介
- AIDE(Advanced Intrusion Detection Environment,進階入侵檢測環境)是個入侵偵查工具,主要用途是檢查文檔的完整性。
- 安裝和配置基於主機的IDS(入侵偵測系統)“AIDE”(進階入侵檢測環境)
AIDE :https://sourceforge.net/projects/aide/
[root@linuxprobe ~]# yum -y install aide
- 配置AIDE並初始化資料庫。可以使用帶有預設配置的AIDE,但是如果要自訂設定,請按如下所示更改設定檔。設定規則寫在26-84行附近,參考它們。
[root@linuxprobe ~]# vi /etc/aide.conf# for example, change setting of monitoring /var/log/var/log p+u+g+i+n+acl+selinux+xattrs# initialize database[root@linuxprobe ~]# aide --initAIDE, version 0.15.1### AIDE database at /var/lib/aide/aide.db.new.gz initialized.# copy generated DB to master DB[root@linuxprobe ~]# cp -p /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
[root@linuxprobe ~]# aide --checkAIDE, version 0.15.1### All files match AIDE database. Looks okay![root@linuxprobe ~]# chmod 640 /root/anaconda-ks.cfg[root@linuxprobe ~]# aide --check# 檢測到的差異如下AIDE 0.15.1 found differences between database and filesystem!!Start timestamp: 2016-10-27 04:44:55Summary: Total number of files: 31983 Added files: 0 Removed files: 0 Changed files: 1---------------------------------------------------Changed files:---------------------------------------------------changed: /root/anaconda-ks.cfg--------------------------------------------------Detailed information about changes:---------------------------------------------------File: /root/anaconda-ks.cfg Perm : -rw------- , -rw-r----- Ctime : 2016-10-25 04:52:57 , 2016-10-27 04:44:25 ACL : old = A:----user::rw-group::---other::------- D: <NONE> new = A:----user::rw-group::r--other::------- D: <NONE>
- 如果沒有ploblem,即使檢測到一些差異,則更新資料庫如下
[root@linuxprobe ~]# aide --updateAIDE 0.15.1 found differences between database and filesystem!!Start timestamp: 2016-10-27 04:49:12Summary: Total number of files: 31983 Added files: 0 Removed files: 0 Changed files: 1---------------------------------------------------Changed files:---------------------------------------------------changed: /root/anaconda-ks.cfg---------------------------------------------------Detailed information about changes:---------------------------------------------------...# update database[root@linuxprobe ~]# cp -p /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
- 如果檢查regulary添加在Cron。記錄檔[/var/log/aide/aide.log]每次都更新,如果沒有區別,它將用零位元組更新,因此如果你想儲存記錄檔,它需要建立一個shell指令碼或發送結果通過電子郵件或其他。
# for example, add daily check in Crontab and send results via email[root@dlp ~]# vi /etc/cron.d/aide00 01 * * * /usr/sbin/aide --update | mail -s 'Daily Check by AIDE' root
Tripwire 簡介
# install from EPEL[root@linuxprobe ~]# yum --enablerepo=epel -y install tripwire
# generate keys[root@linuxprobe ~]# tripwire-setup-keyfiles..........Enter the site keyfile passphrase:# set site keyfile passphraseVerify the site keyfile passphrase:# confirm.........Enter the local keyfile passphrase:# set local keyfile passphraseVerify the local keyfile passphrase:# confirm..........Please enter your site passphrase: # answer with site keyfile passphrase..........Please enter your site passphrase: # answer with site keyfile passphrase..........[root@linuxprobe ~]# cd /etc/tripwire[root@linuxprobe tripwire]# vi twcfg.txt# line 12: report level (4 is max)REPORTLEVEL =4# generate config[root@linuxprobe tripwire]# twadmin -m F -c tw.cfg -S site.key twcfg.txtPlease enter your site passphrase:# answer with site keyfile passphraseWrote configuration file: /etc/tripwire/tw.cfg# optimize policy file with the script below[root@linuxprobe tripwire]# vi twpolmake.pl#!/usr/bin/perl# Tripwire Policy File customize tool# ----------------------------------------------------------------# Copyright (C) 2003 Hiroaki Izumi# This program is free software; you can redistribute it and/or# modify it under the terms of the GNU General Public License# as published by the Free Software Foundation; either version 2# of the License, or (at your option) any later version.# This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.# You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.# ----------------------------------------------------------------# Usage:# perl twpolmake.pl {Pol file}# ----------------------------------------------------------------#$POLFILE=$ARGV[0];open(POL,"$POLFILE") or die "open error: $POLFILE" ;my($myhost,$thost) ;my($sharp,$tpath,$cond) ;my($INRULE) = 0 ;while (<POL>) { chomp; if (($thost) = /^HOSTNAME\s*=\s*(.*)\s*;/) { $myhost = `hostname` ; chomp($myhost) ; if ($thost ne $myhost) { $_="HOSTNAME=\"$myhost\";" ; } } elsif ( /^{/ ) { $INRULE=1 ; } elsif ( /^}/ ) { $INRULE=0 ; } elsif ($INRULE == 1 and ($sharp,$tpath,$cond) = /^(\s*\#?\s*)(\/\S+)\b(\s+->\s+.+)$/) { $ret = ($sharp =~ s/\#//g) ; if ($tpath eq '/sbin/e2fsadm' ) { $cond =~ s/;\s+(tune2fs.*)$/; \#$1/ ; } if (! -s $tpath) { $_ = "$sharp#$tpath$cond" if ($ret == 0) ; } else { $_ = "$sharp$tpath$cond" ; } } print "$_\n" ;}close(POL) ;[root@linuxprobe tripwire]# perl twpolmake.pl twpol.txt > twpol.txt.new[root@linuxprobe tripwire]# twadmin -m P -c tw.cfg -p tw.pol -S site.key twpol.txt.newPlease enter your site passphrase:Wrote policy file: /etc/tripwire/tw.pol
[root@linuxprobe tripwire]# tripwire -m i -s -c tw.cfgPlease enter your local passphrase:
- 手動執行檢查。 (Cron的每日檢查指令碼包含在包中)