AIDE使用

目录:

AIDE简介

当一个入侵者进入了你的系统并且种植了木马,通常会想法来隐蔽这个木马(除了木马自身的一些隐蔽特性外,他会尽量给你检查系统的过程设置障碍),通常入侵者会修改一些文件,比如管理员通常用ps -aux来查看系统进程,那么入侵者很可能用自己经过修改的ps程序来替换掉你系统上的ps程序,以使用ps命令查不到正在运行的木马程序。如果入侵者发现管理员正在运行crontab作业,也有可能替换掉crontab程序等等。所以由此可以看出对于系统文件或是关键文件的检查是很必要的。目前就系统完整性检查的工具用的比较多的有两款: TripwireAIDE,前者是一款商业软件,后者是一款免费的但功能也很强大的工具。

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

  • AIDE能够构造一个指定文件的数据库,它使用aide.conf作为其配置文件。 AIDE数据库能够保存文件的各种属性,包括:权限(permission)、索引节点序号(inode number)、所属用户(user)、所属用户组(group)、文件大小、最后修改时间(mtime)、创建时间(ctime)、最后访问时间(atime)、增加的大小以及连接数。 AIDE还能够使用下列算法: sha1md5rmd160tiger,以密文形式建立每个文件的校验码或散列号.

  • 这个数据库不应该保存那些经常变动的文件信息,例如:日志文件、邮件、 /proc文件系统、用户起始目录以及临时目录.

使用AIDE

安装AIDE
[root@A ~]# yum install -y aide            #使用yum安装
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package aide.x86_64 0:0.14-11.el6 will be installed
--> Finished Dependency Resolution
。。。省略后面内容
修改配置文件,定义监控目录

配置文件路径:/etc/aide.conf

定义监控/app目录,但不监控/app目录下的f3文件。规则为:权限+所有者+所属组+sha512+修改时间+访问时间+改变时间

[root@A ~]# cp /etc/aide.conf /etc/aide.conf.bak       #对配置文件修改前建议备份
[root@A ~]# vim /etc/aide.conf                 #编辑配置文件
# Example configuration file for AIDE.

@@define DBDIR /var/lib/aide            #数据库目录
@@define LOGDIR /var/log/aide           #日志目录

# The location of the database to be read.
database=file:@@{DBDIR}/aide.db.gz      #数据库文件

# The location of the database to be written.
#database_out=sql:host:port:database:login_name:passwd:table
#database_out=file:aide.db.new
database_out=file:@@{DBDIR}/aide.db.new.gz  

# Whether to gzip the output to database
gzip_dbout=yes

# Default.
verbose=5

report_url=file:@@{LOGDIR}/aide.log
report_url=stdout
#report_url=stderr
#NOT IMPLEMENTED report_url=mailto:root@foo.com
#NOT IMPLEMENTED report_url=syslog:LOG_AUTH

# These are the default rules.
#
#p:      permissions        #权限
#i:      inode:             #索引节点
#n:      number of links    #链接数
#u:      user               #用户
#g:      group              #组
#s:      size               #大小
#b:      block count            # 块大小
#m:      mtime          # 修改时间
#a:      atime          # 访问时间
#c:      ctime          # 改变时间
#S:      check for growing size     #检查增加的大小        
#acl:           Access Control Lists
#selinux        SELinux security context
#xattrs:        Extended file attributes
#md5:    md5 checksum       #md5校验
#sha1:   sha1 checksum      # sha1校验
#sha256:        sha256 checksum     #sha256校验
#sha512:        sha512 checksum     #sha512校验
#rmd160: rmd160 checksum        #rmd160校验
#tiger:  tiger checksum     #tiger校验
#rmd160: rmd160 checksum        #rmd160校验
#tiger:  tiger checksum     #tiger校验

#haval:  haval checksum (MHASH only)    # haval校验   
#gost:   gost checksum (MHASH only) # gost校验
#crc32:  crc32 checksum (MHASH only)    # crc32校验
#whirlpool:     whirlpool checksum (MHASH only) 

#R:             p+i+n+u+g+s+m+c+acl+selinux+xattrs+md5
#L:             p+i+n+u+g+acl+selinux+xattrs
#E:             Empty group
#>:             Growing logfile p+u+g+i+n+S+acl+selinux+xattrs

# You can create custom rules like this.
# With MHASH...
# ALLXTRAHASHES = sha1+rmd160+sha256+sha512+whirlpool+tiger+haval+gost+crc32
ALLXTRAHASHES = sha1+rmd160+sha256+sha512+tiger
# Everything but access time (Ie. all changes)
EVERYTHING = R+ALLXTRAHASHES

# Sane, with multiple hashes
# NORMAL = R+rmd160+sha256+whirlpool
NORMAL = R+rmd160+sha256

# For directories, don't bother doing hashes
DIR = p+i+n+u+g+acl+selinux+xattrs

# Access control only
PERMS = p+i+u+g+acl+selinux

# Logfile are special, in that they often change
LOG = >

# Just do md5 and sha256 hashes
LSPP = R+sha256

# Some files get updated automatically, so the inode/ctime/mtime change
# but we want to know when the data inside them changes
DATAONLY =  p+n+u+g+s+acl+selinux+xattrs+md5+sha256+rmd160+tiger

mon = p+u+g+sha512+m+a+c        #   自定义规则监控:权限+所有者+所属组+sha512+修改时间+访问时间+改变时间
/app mon        #定义/app目录使用规则 mon
!/app/f3        #但是/app目录下的f3文件不监控,“!”表示忽略这个文件的检查
初始化数据库
[root@A app]# cp /etc/fstab /app/f1         #先把文件创建好
[root@A app]# echo 123 > f2
[root@A app]# echo www.iav18.cn > f3
[root@A app]# ls
f1  f2  f3
[root@A app]# aide --init 

AIDE, version 0.14

### AIDE database at /var/lib/aide/aide.db.new.gz initialized.
生成检查数据库

把当前初始化的数据库作为开始的基础数据库(建议初始数据库存放到安全的地方)

[root@A ~]# cd /var/lib/aide/
[root@A aide]# ls
aide.db.new.gz
[root@A aide]# cp aide.db.new.gz aide.db.gz
[root@A aide]# ls
aide.db.gz  aide.db.new.gz
检测
[root@A ~]# aide --check       #检测定义的/app目录是否被改动,没有被改动

AIDE, version 0.14

### All files match AIDE database. Looks okay!
[root@A ~]# cd /app/       #切换到/app目录
[root@A app]# ls            # 列出目录下的内容
f1  f2  f3
[root@A app]# echo > f1     #输入一个换行符到f1文件
[root@A app]# aide --check  #再次检查,发现文件f1的 SHA512、Ctime、Mtime已经被修改
AIDE found differences between database and filesystem!!
Start timestamp: 2017-09-13 15:18:54

Summary:
  Total number of files:    4
  Added files:          0
  Removed files:        0
  Changed files:        1


---------------------------------------------------
Changed files:
---------------------------------------------------

changed: /app/f1

--------------------------------------------------
Detailed information about changes:
---------------------------------------------------


File: /app/f1
  Mtime    : 2017-09-13 15:08:30              , 2017-09-13 15:18:51
  Ctime    : 2017-09-13 15:08:30              , 2017-09-13 15:18:51
  SHA512   : ej+ts/Q6q9CANmKXMfdEdCv3Lcl1otID , vmiIOMqGhuXJBom/KrWFzvETfJmbSMcL
更新数据库

如果是合法的修改,那么也会被检测出有问题。此时就需要更新数据了。

[root@A app]# aide -c /etc/aide.conf --update       #更新数据库
AIDE found differences between database and filesystem!!
Start timestamp: 2017-09-13 15:25:29

Summary:
  Total number of files:    4
  Added files:          0
  Removed files:        0
  Changed files:        1


---------------------------------------------------
Changed files:
---------------------------------------------------

changed: /app/f1

--------------------------------------------------
Detailed information about changes:
---------------------------------------------------


File: /app/f1
  Atime    : 2017-09-13 15:10:09              , 2017-09-13 15:18:54
  Mtime    : 2017-09-13 15:08:30              , 2017-09-13 15:18:51
  Ctime    : 2017-09-13 15:08:30              , 2017-09-13 15:18:51
  SHA512   : ej+ts/Q6q9CANmKXMfdEdCv3Lcl1otID , vmiIOMqGhuXJBom/KrWFzvETfJmbSMcL
[root@A app]# cd /var/lib/aide/     #cd到/var/lib/aide/目录
[root@A aide]# ls
aide.db.gz  aide.db.new.gz
[root@A aide]# cp aide.db.new.gz aide.db.gz     #覆盖基准数据库
cp: overwrite `aide.db.gz'? y
[root@A aide]# aide --check         #再次检查数据库就没问题了。

AIDE, version 0.14

### All files match AIDE database. Looks okay!
  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值