电脑疯子技术论坛|电脑极客社区

微信扫一扫 分享朋友圈

已有 1955 人浏览分享

CentOS 7 安全加固、检测、审计

[复制链接]
1955 0
本帖最后由 zhaorong 于 2017-3-9 15:26 编辑

RKHunter:检测Rootkit

RKHunter 传送门:http://rkhunter.sourceforge.net/
Root Kit 详解:http://linux.vbird.org/linux_security/0420rkhunter.php

RKHunter 安装
  1. [root@linuxprobe ~]# yum --enablerepo=epel -y install rkhunter
复制代码


配置和使用RKHunter,对于常规检查,检查脚本安装在cron.daily目录下,并由Cron每天执行
  1. [root@linuxprobe ~]# vi /etc/sysconfig/rkhunter
  2. # recipient address for report
  3. MAILTO=root@localhost
  4. # if specified "yes", scan more detaily
  5. DIAG_SCAN=no
  6. # update database
  7. [root@linuxprobe ~]# rkhunter --update
  8. # update system file properties
  9. [root@linuxprobe ~]# rkhunter --propupd
  10. # execute checking
  11. # --sk means sikpping to push Enter key
  12. # if specified --rwo , display only warnings
  13. [root@linuxprobe ~]#  rkhunter --check --sk
复制代码


Lynis

  1. 安全审计工具  Lynis 传送门: https://cisofy.com/lynis/
复制代码


安装Lynis

  1. [root@linuxprobe ~]# yum --enablerepo=epel -y install lynis
复制代码


使用Lynis
  1. [root@linuxprobe ~]# lynis audit system
复制代码


相关文档Lynis 教程:  http://netsecurity.51cto.com/art/201410/455466.htm


AIDE 简介

AIDE(Advanced Intrusion Detection Environment,高级入侵检测环境)是个入侵检测工具,主要用途是检查文档的完整性。

安装和配置基于主机的IDS(入侵检测系统)“AIDE”(高级入侵检测环境)


  1. AIDE 下载地址: https://sourceforge.net/projects/aide/
复制代码


安装AIDE

  1. [root@linuxprobe ~]# yum -y install aide
复制代码


配置AIDE并初始化数据库。可以使用带有默认配置的AIDE,但是如果要自定义设置,请按如下所示更改配置文件。

设置规则写在26-84行附近,参考它们。


  1. [code][root@linuxprobe ~]# vi /etc/aide.conf
  2. # for example, change setting of monitoring /var/log
  3. /var/log   p+u+g+i+n+acl+selinux+xattrs
  4. # initialize database
  5. [root@linuxprobe ~]# aide --init
  6. AIDE, version 0.15.1
  7. ### AIDE database at /var/lib/aide/aide.db.new.gz initialized.
  8. # copy generated DB to master DB
  9. [root@linuxprobe ~]# cp -p /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
复制代码


执行检查
  1. [root@linuxprobe ~]# aide --check
  2. AIDE, version 0.15.1
  3. ### All files match AIDE database. Looks okay!

  4. [root@linuxprobe ~]# chmod 640 /root/anaconda-ks.cfg
  5. [root@linuxprobe ~]# aide --check
复制代码

# 检测到的差异如下

  1. AIDE 0.15.1 found differences between database and filesystem!!
  2. Start timestamp: 2016-10-27 04:44:55
  3. Summary:
  4.   Total number of files:    31983
  5.   Added files:          0
  6.   Removed files:        0
  7.   Changed files:        1

  8. ---------------------------------------------------
  9. Changed files:
  10. ---------------------------------------------------
  11. changed: /root/anaconda-ks.cfg
  12. --------------------------------------------------
  13. Detailed information about changes:
  14. ---------------------------------------------------
  15. File: /root/anaconda-ks.cfg
  16. Perm     : -rw-------                       , -rw-r-----
  17. Ctime    : 2016-10-25 04:52:57              , 2016-10-27 04:44:25
  18. ACL      : old = A:
  19. ----
  20. user::rw-
  21. group::---
  22. other::---
  23. ----
  24.                   D: <NONE>
  25.             new = A:
  26. ----
  27. user::rw-
  28. group::r--
  29. other::---
  30. ----
  31.                   D: <NONE>
复制代码
[/code]

如果没有ploblem,即使检测到一些差异,则更新数据库如下

[
  1. root@linuxprobe ~]# aide --update
  2. AIDE 0.15.1 found differences between database and filesystem!!
  3. Start timestamp: 2016-10-27 04:49:12

  4. Summary:
  5.   Total number of files:    31983
  6.   Added files:          0
  7.   Removed files:        0
  8.   Changed files:        1
  9. ---------------------------------------------------
  10. Changed files:
  11. ---------------------------------------------------
  12. changed: /root/anaconda-ks.cfg
  13. ---------------------------------------------------
  14. Detailed information about changes:
  15. ---------------------------------------------------
  16. ...
  17. # update database
  18. [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脚本或发送结果通过电子邮件或其他。

  1. # for example, add daily check in Crontab and send results via email
  2. [root@dlp ~]# vi /etc/cron.d/aide
  3. 00 01 * * * /usr/sbin/aide --update | mail -s 'Daily Check by AIDE' root
复制代码


Tripwire 简介

Tripwire是目前最为著名的unix下文件系统完整性检查的软件工具,这一软件采用的技术核心就是对每个要监控的文件产生一个数字签名,

保留下来。当文件现在的数字签名与保留的数字签名不一致时,那么现在这个文件必定被改动过了。


  1. Tripwire 官网: http://www.tripwire.com/
复制代码


安装Tripwire

  1. # install from EPEL
  2. [root@linuxprobe ~]# yum --enablerepo=epel -y install tripwire
复制代码



创建密钥和数据库

  1. # generate keys
  2. [root@linuxprobe ~]# tripwire-setup-keyfiles
  3. .....
  4. .....
  5. Enter the site keyfile passphrase:# set site keyfile passphrase
  6. Verify the site keyfile passphrase:# confirm
  7. ....
  8. .....
  9. Enter the local keyfile passphrase:# set local keyfile passphrase
  10. Verify the local keyfile passphrase:# confirm
  11. .....
  12. .....
  13. Please enter your site passphrase: # answer with site keyfile passphrase
  14. .....
  15. .....
  16. Please enter your site passphrase: # answer with site keyfile passphrase
  17. .....
  18. .....
  19. [root@linuxprobe ~]# cd /etc/tripwire
  20. [root@linuxprobe tripwire]# vi twcfg.txt
  21. # line 12: report level (4 is max)
  22. REPORTLEVEL =4
  23. # generate config
  24. [root@linuxprobe tripwire]# twadmin -m F -c tw.cfg -S site.key twcfg.txt
  25. Please enter your site passphrase:# answer with site keyfile passphrase
  26. Wrote configuration file: /etc/tripwire/tw.cfg
  27. # optimize policy file with the script below
  28. [root@linuxprobe tripwire]# vi twpolmake.pl
  29. #!/usr/bin/perl
  30. # Tripwire Policy File customize tool
  31. # ----------------------------------------------------------------
  32. # Copyright (C) 2003 Hiroaki Izumi
  33. # This program is free software; you can redistribute it and/or
  34. # modify it under the terms of the GNU General Public License
  35. # as published by the Free Software Foundation; either version 2
  36. # of the License, or (at your option) any later version.
  37. # This program is distributed in the hope that it will be useful,
  38. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  39. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  40. # GNU General Public License for more details.
  41. # You should have received a copy of the GNU General Public License
  42. # along with this program; if not, write to the Free Software
  43. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  44. # ----------------------------------------------------------------
  45. # Usage:
  46. #     perl twpolmake.pl {Pol file}
  47. # ----------------------------------------------------------------
  48. #
  49. $POLFILE=$ARGV[0];
  50. open(POL,"$POLFILE") or die "open error: $POLFILE" ;
  51. my($myhost,$thost) ;
  52. my($sharp,$tpath,$cond) ;
  53. my($INRULE) = 0 ;

  54. while (<POL>) {
  55.     chomp;
  56.     if (($thost) = /^HOSTNAME\s*=\s*(.*)\s*;/) {
  57.         $myhost = `hostname` ; chomp($myhost) ;
  58.         if ($thost ne $myhost) {
  59.             $_="HOSTNAME="$myhost";" ;
  60.         }
  61.     }
  62.     elsif ( /^{/ ) {
  63.         $INRULE=1 ;
  64.     }
  65.     elsif ( /^}/ ) {
  66.         $INRULE=0 ;
  67.     }
  68.     elsif ($INRULE == 1 and ($sharp,$tpath,$cond) = /^(\s*\#?\s*)(\/\S+)\b(\s+->\s+.+)$/) {
  69.         $ret = ($sharp =~ s/\#//g) ;
  70.         if ($tpath eq '/sbin/e2fsadm' ) {
  71.             $cond =~ s/;\s+(tune2fs.*)$/; \#$1/ ;
  72.         }
  73.         if (! -s $tpath) {
  74.             $_ = "$sharp#$tpath$cond" if ($ret == 0) ;
  75.         }
  76.         else {
  77.             $_ = "$sharp$tpath$cond" ;
  78.         }
  79.     }
  80.     print "$_\n" ;
  81. }
  82. close(POL) ;
  83. [root@linuxprobe tripwire]# perl twpolmake.pl twpol.txt > twpol.txt.new
  84. [root@linuxprobe tripwire]# twadmin -m P -c tw.cfg -p tw.pol -S site.key twpol.txt.new
  85. Please enter your site passphrase:
  86. Wrote policy file: /etc/tripwire/tw.pol
复制代码


创建数据库

  1. [root@linuxprobe tripwire]# tripwire -m i -s -c tw.cfg
  2. Please enter your local passphrase:
复制代码


手动执行检查。 (Cron的每日检查脚本包含在包中)



您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

关注

0

粉丝

9021

主题
精彩推荐
热门资讯
网友晒图
图文推荐

Powered by Pcgho! X3.4

© 2008-2022 Pcgho Inc.