Advanced Intrusion Detection Environment(AIDE) 入門介紹


介紹

AIDE(Adevanced Intrusion Detection Environment)高級(jí)入侵檢測(cè)環(huán)境)是個(gè)入侵檢測(cè)工具凳寺,主要用途是檢查文本的完整性虑灰。AIDE能夠構(gòu)造一個(gè)指定文檔的數(shù)據(jù)庫(kù),使用aide.conf作為配置文檔。AIDE數(shù)據(jù)庫(kù)能夠保存文檔的各種屬性谷醉,包括:權(quán)限(permission)能颁、索引節(jié)點(diǎn)序號(hào)(inode number)若债、所屬用戶(user)充坑、所屬用戶組(group)蒂秘、文檔大小泽本、最后修改時(shí)間(mtime)、創(chuàng)建時(shí)間(ctime)姻僧、最后訪問時(shí)間(atime)规丽、增加的大小連同連接數(shù)。AIDE使用下列算法:sha256撇贺,sha512赌莺,rmd160,haval松嘶,gost艘狭,crc32,tiger翠订,以密文形式建立每個(gè)文檔的校驗(yàn)碼或散列號(hào)巢音。
AIDE是用以代替收費(fèi)商業(yè)版軟件tripwire的一款新產(chǎn)品。

文件系統(tǒng)入侵檢測(cè)的原理:

1尽超、當(dāng)系統(tǒng)處于健康狀態(tài)時(shí)官撼,把系統(tǒng)所有的文件做各種指紋的檢驗(yàn),得出一個(gè)檢驗(yàn)基準(zhǔn)數(shù)據(jù)庫(kù)似谁。

2傲绣、不是所有的文件都需要保存指紋,臨時(shí)文件(/var/log | /tmp | /var/tmp | /proc | /sys | /dev/shm...)

3巩踏、需要檢驗(yàn)文件是否被更改秃诵,只需要把基準(zhǔn)數(shù)據(jù)對(duì)應(yīng)指紋值做對(duì)比,就可以得知哪些文件被更改過塞琼。

4菠净、每天把檢驗(yàn)的結(jié)果以郵件或者其它方式發(fā)送管理員。

安裝

安裝AIDE可以直接從倉(cāng)庫(kù)中安裝:

admin@debian ~> sudo aptitude  install aide
The following NEW packages will be installed:
  aide aide-common{a} 
0 packages upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/836 kB of archives. After unpacking 2,416 kB will be used.
Do you want to continue? [Y/n/?] 

安裝時(shí),會(huì)自動(dòng)生成常用配置文件嗤练,如下所示:

Creating config file /etc/aide/aide.conf.d/30_aide_apache2 with new version

Creating config file /etc/aide/aide.conf.d/31_aide_console-log with new version

Creating config file /etc/aide/aide.conf.d/31_aide_anacron with new version

Creating config file /etc/aide/aide.conf.d/31_aide_torrus with new version

Creating config file /etc/aide/aide.conf.d/70_aide_dev with new version

Creating config file /etc/aide/aide.conf.d/31_aide_amanda-client with new version

Creating config file /etc/aide/aide.conf.d/31_aide_privoxy with new version

Creating config file /etc/aide/aide.conf.d/31_aide_apache with new version

Creating config file /etc/aide/aide.conf.d/31_aide_fcron with new version

Creating config file /etc/aide/aide.conf.d/31_aide_x11-xkb-utils with new version

Creating config file /etc/aide/aide.conf with new version

Creating config file /etc/aide/aide.settings.d/31_aide_svn-server_settings with new version

Creating config file /etc/aide/aide.settings.d/31_aide_apt_settings with new version

Creating config file /etc/aide/aide.settings.d/31_aide_trac_settings with new version

Creating config file /etc/aide/aide.settings.d/10_aide_sourceslist with new version

Creating config file /etc/cron.daily/aide with new version

這些配置文件都是通過aide-common這個(gè)包生成的榛了,同時(shí)這個(gè)軟件包還包括aide的初始化工具aideinit,方便用戶使用煞抬。

AIDE的配置

AIDE的配置文件所在的位置為:/etc/aide/aide.conf霜大。

默認(rèn)的配置文件:

# AIDE conf

# The daily cron job depends on these paths
database=file:/var/lib/aide/aide.db
database_out=file:/var/lib/aide/aide.db.new
database_new=file:/var/lib/aide/aide.db.new
gzip_dbout=yes

# Set to no to disable summarize_changes option.
summarize_changes=yes

# Set to no to disable grouping of files in report.
grouped=yes

# standard verbose level
verbose = 6

# Set to yes to print the checksums in the report in hex format
report_base16 = no

# if you want to sacrifice security for speed, remove some of these
# checksums. Whirlpool is broken on sparc and sparc64 (see #429180,
# #420547, #152203).
Checksums = sha256+sha512+rmd160+haval+gost+crc32+tiger

# The checksums of the databases to be printed in the report
# Set to 'E' to disable.
database_attrs = Checksums

# check permissions, owner, group and file type
OwnerMode = p+u+g+ftype

# Check size and block count
Size = s+b

# Files that stay static
InodeData = OwnerMode+n+i+Size+l+X
StaticFile = m+c+Checksums

# Files that stay static but are copied to a ram disk on startup
# (causing different inode)
RamdiskData = InodeData-i

# Check everything
Full = InodeData+StaticFile

# Files that change their mtimes or ctimes but not their contents
VarTime = InodeData+Checksums

# Files that are recreated regularly but do not change their contents
VarInode = VarTime-i

# Files that change their contents during system operation
VarFile = OwnerMode+n+l+X

# Directories that change their contents during system operation
VarDir = OwnerMode+n+i+X

# Directories that are recreated regularly and change their contents
VarDirInode = OwnerMode+n+X

# Directories that change their mtimes or ctimes but not their contents
VarDirTime = InodeData

# Logs are special: they are continously written to, may be compressed
# have their file name changed in different, mutually incompatibly ways
# and apprear and vanish at will. Handling this is a a complex and error-
# prone issue.
#
# This is best broken down in a number of small tasks:
#
#
# (A)
# While a live log is being written to, it doesn't change its mode and
# inode and its size only increases.
#
# (B)
# When a live log is rotated for the first time, it should not change
# its mode, may change its inode, and its size decreases. The size
# decrease may not be noticed by aide if the file had size x at the last
# aide run, was rotated in the mean time and was written to so that it
# had a size > x at the next aide run.
#
# (C)
# When a log is compressed, this looks to aide like the uncompressed
# file vanished (or was replaced by another file) and the compressed
# file appeared out of the blue. There is (currently) no way to
# associate the (gone) uncompressed file's contents with the (new)
# compressed file's contents
#
# (D)
# The actual log rotation may rename foo.{x}.bar to foo.{x+1}.bar without
# changing the other properties of the file
#
# (E)
# If only a given number of log generations is to be kept, foo.{y}.bar may
# vanish, but usually only when no foo.{z}.bar exists for z>y.
#
# (F)
# The set of files foo.{x}.bar to foo.{y}.bar is called a "log series"
# in aide terms, with the lowest x being called the "LoSerMember" element
# and the highest y being called the "HiSerMember" element, and the z
# with x<z<y simple called "SerMember". The Lo and Hi members need to
# be special cased in aide configuration.
#
#
# This is an example of the normal life of a log named foo in a logrotate
# configuration using a configuration at it is commonly used in Debian
# (from old to new):
#     1 logrotate deletes HiSerMember foo.{y}.gz
#     2 logrotate rotates SerMember foo.{z-1}.gz to foo.{z}.gz for all
#       z with 3<z<=y. This includes rotation of foo.{y-1}.gz to
#       foo.{y}.gz and foo.2.gz to foo.3.gz
#     3 logrotate compresses foo.1 to foo.2.gz, creating LoSerMember foo.2.gz
#     4 logrotate rotates foo to foo.1 (a simple rename)
#     5 logrotate creates new, empty foo
#     6 foo daemon logs to foo - foo grows in size
#
# we need the following rules:
# /var/log/foo$ Log
# /var/log/foo$ FreqRotLog
#    this takes care of the growing live log (step 7). The "Log" rule
#    is appropriate for logs that are not rotated daily as rotation
#    might be reported (if the file size has decreased since the last
#    aide run). For daily rotated logs, the "FreqRotLog" may be more
#    appropriate.
# /var/log/foo\.1$ LowLog
#    this takes care of step 5.
# /var/log/foo\.2\.gz$ LoSerMemberLog
#    this allows yet unknown new files to appear with a \.2\.gz extension,
#    covering step 3.
# /var/log/foo\.[3..y-1]\.gz$ SerMemberLog
#    this watches the log files as they wander through the Series,
#    changing only their file name but not their contents or metadata,
#    covering step 2.
#    Please note that [3..y-1] needs to be a manually crafted regexp covering
#    all numbers between 3 and y-1.
# /var/log/foo\.y\.gz$ HiSerMemberLog
#    finally, the last element of the Series is allowed to vanish without
#    being reported, covering step 1.
#
# Please note that these example rules need to be adapted to the logrotate
# configuration for the log. Compression may be disabled or lead to a different
# extension, the dateext option may be used, old logs might be held in a
# different place, a log series does not necessarily need to be compressed etc.
#
# Please note that savelog rotates the live log to .0 and not to .1 as it
# is logrotates (changeable) default.


# Logs grow in size. Log rotation of these logs will be reported, so
# this should only be used for logs that are not rotated daily.
Log = OwnerMode+n+S+X

# Logs that are frequently rotated
FreqRotLog = Log-S

# The first instance of a rotated log: After the log has stopped being
# written to, but before rotation
LowLog = Log-S

# Rotated logs change their file name but retain all their other properties
SerMemberLog  = Full+I

# The first instance of a compressed, rotated log: After a LowLog was
# compressed.
LoSerMemberLog = SerMemberLog+ANF

# The last instance of a compressed, rotated log: After this name, a log
# will be removed
HiSerMemberLog = SerMemberLog+ARF

# Not-yet-compressed log created by logrotate's dateext option:
# These files appear one rotation (renamed from the live log) and are gone
# the next rotation (being compressed)
LowDELog = SerMemberLog+ANF+ARF

# Compressed log created by logrotate's dateext option: These files appear
# once and are not touched any more.
SerMemberDELog = Full+ANF

# For daemons that log to a variable file name and have the live log
# hardlinked to a static file name
LinkedLog = Log-n

根據(jù)配置文件的說明,可以將需要監(jiān)控的文件以及需要監(jiān)控的等級(jí)寫入配置文件中

比如需要對(duì)/etc目錄下的所有配置做全面的監(jiān)控革答,可以寫:

/etc Full

參考配置文件中的說明战坤,可以對(duì)log文件進(jìn)行監(jiān)控,可以使用正則表達(dá)式來精確定位文件:

/var/log/foo$ Log

在這里残拐,F(xiàn)ull 和Log都對(duì)應(yīng)規(guī)則途茫,截取配置文件中的內(nèi)容:

Checksums = sha256+sha512+rmd160+haval+gost+crc32+tiger

# check permissions, owner, group and file type
OwnerMode = p+u+g+ftype

# Check size and block count
Size = s+b

# Files that stay static
InodeData = OwnerMode+n+i+Size+l+X
StaticFile = m+c+Checksums

# Check everything
Full = InodeData+StaticFile

規(guī)則列表參考如下,參考在線手冊(cè)

 # Here are all the things we can check - these are the default rules
   #
   #p:      permissions
   #ftype:  file type
   #i:      inode
   #n:      number of links
   #l:      link name
   #u:      user
   #g:      group
   #s:      size
   #b:      block count
   #m:      mtime
   #a:      atime
   #c:      ctime
   #S:      check for growing size
   #I:      ignore changed filename
   #md5:    md5 checksum
   #sha1:   sha1 checksum
   #sha256: sha256 checksum
   #sha512: sha512 checksum
   #rmd160: rmd160 checksum
   #tiger:  tiger checksum
   #haval:  haval checksum
   #crc32:  crc32 checksum
   #R:      p+ftupe+i+l+n+u+g+s+m+c+md5
   #L:      p+ftype+i+l+n+u+g
   #E:      Empty group
   #>:      Growing file p+ftype+l+u+g+i+n+S
   #The following are available if you have mhash support enabled:
   #gost:   gost checksum
   #whirlpool: whirlpool checksum
   #The following are available and added to the default groups R, L and >
   #only when explicitly enabled using configure:
   #acl:    access control list
   #selinux SELinux security context
   #xattrs:  extended file attributes
   #e2fsattrs: file attributes on a second extended file system

   # You can also create custom rules - my home made rule definition goes like this
   # 你可以創(chuàng)建屬于自己的規(guī)則:
   MyRule = p+i+n+u+g+s+b+m+c+md5+sha1

數(shù)據(jù)庫(kù)初始化

使用aide 的-i參數(shù)溪食,對(duì)數(shù)據(jù)庫(kù)進(jìn)行初始化:

sudo aide -c /etc/aide/aide.conf -i

admin@debian ~> sudo aide -c /etc/aide/aide.conf -i
Start timestamp: 2018-01-08 01:29:02 -0500 (AIDE 0.16)
AIDE initialized database at /var/lib/aide/aide.db.new
Verbose level: 6

Number of entries:      51972

---------------------------------------------------
The attributes of the (uncompressed) database(s):
---------------------------------------------------

/var/lib/aide/aide.db.new
  RMD160   : DNBI9Ac01S2jSxe61datOzbAy0A=
  TIGER    : rnQ7OHB3rqryyWHf9qAIo7LmU7rmer0/
  SHA256   : 3/oFTjV+IIkHpeb5JwcRpdbkot5EEWEf
             U83L3ng5ZSc=
  SHA512   : ZzAOSgA3l2GYXYXCUrJCAkjP+UWruyNz
             6WC2HkKJT3XzjLKwVyPSLvq/+YbcymTY
             HMRhJi1jsYNssiHPaKD9wQ==
  CRC32    : jkFdSw==
  HAVAL    : uc8r8sSDbIAWzz2mGBLiBVIplZKnmd6F
             mYTF2cwMf5I=
  GOST     : hn7RfiLqK53ufMUz7ko99L+dzQlcEsnz
             s6FR76hjp1Y=


End timestamp: 2018-01-08 01:31:21 -0500 (run time: 2m 19s)

初始化后囊卜,需要將數(shù)據(jù)庫(kù)修改一下

cd /var/lib/aide/
sudo cp aide.db.new aide.db

檢查文件是否被篡改

使用-C參數(shù)或者--check,檢查文件是否被篡改错沃。

admin@debian /v/l/aide> sudo aide -c /etc/aide/aide.conf  -C
Start timestamp: 2018-01-08 02:06:11 -0500 (AIDE 0.16)
AIDE found NO differences between database and filesystem. Looks okay!!
Verbose level: 6

Number of entries:      51972

---------------------------------------------------
The attributes of the (uncompressed) database(s):
---------------------------------------------------

/var/lib/aide/aide.db
  RMD160   : DNBI9Ac01S2jSxe61datOzbAy0A=
  TIGER    : rnQ7OHB3rqryyWHf9qAIo7LmU7rmer0/
  SHA256   : 3/oFTjV+IIkHpeb5JwcRpdbkot5EEWEf
             U83L3ng5ZSc=
  SHA512   : ZzAOSgA3l2GYXYXCUrJCAkjP+UWruyNz
             6WC2HkKJT3XzjLKwVyPSLvq/+YbcymTY
             HMRhJi1jsYNssiHPaKD9wQ==
  CRC32    : jkFdSw==
  HAVAL    : uc8r8sSDbIAWzz2mGBLiBVIplZKnmd6F
             mYTF2cwMf5I=
  GOST     : hn7RfiLqK53ufMUz7ko99L+dzQlcEsnz
             s6FR76hjp1Y=


End timestamp: 2018-01-08 02:08:32 -0500 (run time: 2m 21s)

也可以將輸出保存到指定文件中栅组,例如:

sudo aide -c /etc/aide/aide.conf  -C --report=file:/tmp/aide-report-`date +%Y%m%d`.txt

-V 參數(shù)報(bào)告的詳細(xì)程度可以通過-V選項(xiàng)來調(diào)控,級(jí)別為0-255枢析, -V0 最簡(jiǎn)略玉掸,-V255 最詳細(xì)。

正常修改系統(tǒng)文件醒叁,可以使用update來更新數(shù)據(jù)庫(kù):

#如果是正常的改動(dòng) 更新改動(dòng)到基礎(chǔ)數(shù)據(jù)庫(kù)
aide --update -c /etc/aide/aide.conf
cd /var/lib/aide/
#覆蓋替換舊的數(shù)據(jù)庫(kù)
mv aide.db.new aide.db

關(guān)于aide-common

aide-common是debian為aide方便部署而提供的一個(gè)組件司浪,其中包括了aideinit腳本,update-aide.conf自動(dòng)生成配置腳本把沼,以及在/etc/aide/aide.conf.d中一系列常規(guī)配置文件啊易。

在使用時(shí),可以直接執(zhí)行

# aideinit -y

其會(huì)自動(dòng)在/var/lib/aide/下生成aide.conf.autogenerated 配置文件饮睬,并生成數(shù)據(jù)庫(kù)aide.db.new與aide.db认罩。

aide.conf.autogenerated 配置文件的自動(dòng)生成依賴與/etc/aide/aide.conf.d目錄下的文件。如果你不小心刪除了其中的文件续捂,可以重新安裝aide-common這個(gè)軟件包獲得。

在使用aideinit過程時(shí)宦搬,可能會(huì)遇到語(yǔ)法報(bào)錯(cuò)的情況牙瓢。一般可以根據(jù)輸出來定位到是aide.conf.autogenerated文件的哪一行,再對(duì)其進(jìn)行排查解決间校。

參考連接

  1. https://www.iamle.com/archives/1664.html》恕(部分內(nèi)容過時(shí))
  2. https://www.cyberciti.biz/faq/debian-ubuntu-linux-software-integrity-checking-with-aide/
  3. https://www.linux.com/learn/weekend-project-intrusion-detection-linux-AIDE
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市憔足,隨后出現(xiàn)的幾起案子胁附,更是在濱河造成了極大的恐慌酒繁,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,482評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件控妻,死亡現(xiàn)場(chǎng)離奇詭異州袒,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)弓候,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,377評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門郎哭,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人菇存,你說我怎么就攤上這事夸研。” “怎么了依鸥?”我有些...
    開封第一講書人閱讀 152,762評(píng)論 0 342
  • 文/不壞的土叔 我叫張陵亥至,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我贱迟,道長(zhǎng)姐扮,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,273評(píng)論 1 279
  • 正文 為了忘掉前任关筒,我火速辦了婚禮溶握,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘蒸播。我一直安慰自己睡榆,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,289評(píng)論 5 373
  • 文/花漫 我一把揭開白布袍榆。 她就那樣靜靜地躺著胀屿,像睡著了一般。 火紅的嫁衣襯著肌膚如雪包雀。 梳的紋絲不亂的頭發(fā)上宿崭,一...
    開封第一講書人閱讀 49,046評(píng)論 1 285
  • 那天,我揣著相機(jī)與錄音才写,去河邊找鬼葡兑。 笑死,一個(gè)胖子當(dāng)著我的面吹牛赞草,可吹牛的內(nèi)容都是我干的讹堤。 我是一名探鬼主播,決...
    沈念sama閱讀 38,351評(píng)論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼厨疙,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼洲守!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 36,988評(píng)論 0 259
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤梗醇,失蹤者是張志新(化名)和其女友劉穎知允,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體叙谨,經(jīng)...
    沈念sama閱讀 43,476評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡温鸽,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,948評(píng)論 2 324
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了唉俗。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片嗤朴。...
    茶點(diǎn)故事閱讀 38,064評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖虫溜,靈堂內(nèi)的尸體忽然破棺而出雹姊,到底是詐尸還是另有隱情,我是刑警寧澤衡楞,帶...
    沈念sama閱讀 33,712評(píng)論 4 323
  • 正文 年R本政府宣布吱雏,位于F島的核電站,受9級(jí)特大地震影響瘾境,放射性物質(zhì)發(fā)生泄漏歧杏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,261評(píng)論 3 307
  • 文/蒙蒙 一迷守、第九天 我趴在偏房一處隱蔽的房頂上張望犬绒。 院中可真熱鬧,春花似錦兑凿、人聲如沸凯力。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,264評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)咐鹤。三九已至,卻和暖如春圣絮,著一層夾襖步出監(jiān)牢的瞬間祈惶,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,486評(píng)論 1 262
  • 我被黑心中介騙來泰國(guó)打工扮匠, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留捧请,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 45,511評(píng)論 2 354
  • 正文 我出身青樓棒搜,卻偏偏與公主長(zhǎng)得像血久,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子帮非,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,802評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容