AIDE使用

AIDE使用

2017年09月13日 16:27:19 Hai__Yun 閱讀數:3020 標籤: 管理木馬 更多node

我的分類: linuxlinux

版權聲明:感謝閱讀,一直在努力。有什麼建議或者不足之處還望多多見諒,能夠留言告訴小編,小編會虛心接受你們的意見 https://blog.csdn.net/Hai__Yun/article/details/77967748算法

目錄:

 

 

AIDE簡介

當一個入侵者進入了你的系統而且種植了木馬,一般會想法來隱蔽這個木馬(除了木馬自身的一些隱蔽特性外,他會盡可能給你檢查系統的過程設置障礙),一般入侵者會修改一些文件,好比管理員一般用ps -aux來查看系統進程,那麼入侵者極可能用本身通過修改的ps程序來替換掉你係統上的ps程序,以使用ps命令查不到正在運行的木馬程序。若是入侵者發現管理員正在運行crontab做業,也有可能替換掉crontab程序等等。因此由此能夠看出對於系統文件或是關鍵文件的檢查是很必要的。目前就係統完整性檢查的工具用的比較多的有兩款: TripwireAIDE,前者是一款商業軟件,後者是一款免費的但功能也很強大的工具。sql

  • AIDE(Advanced Intrusion Detection Environment,高級入侵檢測環境)是個入侵檢測工具,主要用途是檢查文檔的完整性。數據庫

  • AIDE可以構造一個指定文件的數據庫,它使用aide.conf做爲其配置文件。 AIDE數據庫可以保存文件的各類屬性,包括:權限(permission)、索引節點序號(inode number)、所屬用戶(user)、所屬用戶組(group)、文件大小、最後修改時間(mtime)、建立時間(ctime)、最後訪問時間(atime)、增長的大小以及鏈接數。 AIDE還可以使用下列算法: sha1、 md5、 rmd160、 tiger,以密文形式創建每一個文件的校驗碼或散列號.vim

  • 這個數據庫不該該保存那些常常變更的文件信息,例如:日誌文件、郵件、 /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
。。。省略後面內容
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

修改配置文件,定義監控目錄

配置文件路徑:/etc/aide.conf安全

定義監控/app目錄,但不監控/app目錄下的f3文件。規則爲:權限+全部者+所屬組+sha512+修改時間+訪問時間+改變時間app

[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文件不監控,「!」表示忽略這個文件的檢查
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92

初始化數據庫

[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.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

生成檢查數據庫

把當前初始化的數據庫做爲開始的基礎數據庫(建議初始數據庫存放到安全的地方)ide

[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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

檢測

[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的 SHA5十二、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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

更新數據庫

若是是合法的修改,那麼也會被檢測出有問題。此時就須要更新數據了。工具

[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!
相關文章
相關標籤/搜索