1. 程式人生 > >利用auditbeat采集系統審計日誌並生成圖像

利用auditbeat采集系統審計日誌並生成圖像

1.5 .com 平臺 ofo 方式 完整性 必須 生成 cto

一、背景

Auditbeat是輕量型的審計日誌采集器,可以收集linux審計框架的數據、監控文件完整性。能夠組合相關消息到一個事件裏,生成標標準的結構化數據,方便分析,而且能夠與Logstash、Elasticsearch和Kibana無縫集成。

二、安裝

wget https://artifacts.elastic.co/downloads/beats/auditbeat/auditbeat-6.5.4-linux-x86_64.tar.gz
tar zxf auditbeat-6.5.4-linux-x86_64.tar.gz

三、配置auditbeat

默認的配置文件是auditbeat.yml,Linux平臺下,該文件位於解壓目錄下。

還有一個auditbeat.reference.yml文件,該文件顯示了所有的選項,可以根據需求將其拷貝到auditbeat.yml文件中。
auditbeat.yml主要的兩部分,一部分模塊,另一部分是輸出。
1、模塊
目前有兩種模塊:
auditd:auditd模塊接收來自Linux審計框架的審計事件,該框架是Linux內核的一部分。這個模塊建立對內核的訂閱,以便在事件發生時接收它們。註意使用Auditd模塊,系統需要先關閉auditd服務,執行” service auditd stop”。
模塊相關配置項如下:

- module: auditd
  audit_rule_files: [ ‘${path.config}/audit.rules.d/*.conf‘ ]
  audit_rules: |
#-a always,exit -F arch=b64 -S execve,execveat -k exec
……

audit_rule_files:從單獨的文件加載審計規則,註意默認提供了36和位64位兩種,根據本地系統選擇其一。
audit_rules:定義審計規則。

file_integrity:file_integrity模塊實時監控指定目錄下的文件更改。註意在linux系統中,需要使用inotify,因此內核必須支持inotify。Inotify最初已被合並到2.6.13 Linux內核中了。
模塊相關配置項如下:

- module: file_integrity
  paths:
  - /bin
  - /usr/bin
  - /sbin
  - /usr/sbin
  - /etc

paths:指定被監控文件路徑

想了解兩個模塊更豐富的配置項,參考官方文檔:
https://www.elastic.co/guide/en/beats/auditbeat/6.5/auditbeat-modules.html

2、輸出
內容可以輸出到Elasticsearch、Logstash、Kafka、Redis、File、Console、Cloud,註意只能配置一種輸出方式。
輸出到Elasticsearch:

output.elasticsearch:
  hosts: ["172.16.1.25:9200"]
index: "auditbeat-%{[beat.version]}-%{+yyyy.MM.dd}"
  protocol: "https"
  username: "elastic"
  password: "changeme"

輸出到Logstash

output.logstash:
  hosts: ["172.16.1.25:5044"]

輸出到Kafka

output.kafka:
  hosts: ["kafka1:9092", "kafka2:9092", "kafka3:9092"]
  topic: ‘%{[fields.log_topic]}‘
  partition.round_robin:
    reachable_only: false
  required_acks: 1
  compression: gzip
  max_message_bytes: 1000000

輸出到File

output.file:
  path: "/tmp/auditbeat"
  filename: auditbeat

想了解更詳細的配置項及含義,請參考官方文檔:
https://www.elastic.co/guide/en/beats/auditbeat/6.5/configuring-output.html

本案例是將內容輸出到了Elasticsearch

output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["172.16.1.25:9200","172.16.1.26:9200","172.16.1.27:9200"]

沒有指定索引,采用默認格式"auditbeat-%{[beat.version]}-%{+yyyy.MM.dd}",需要註意的是:如果不使用默認格式,還需要添加連個配置項:

setup.template.name: "auditbeat"
setup.template.pattern: "auditbeat-*"

三、運行auditbeat

在解壓目錄下,使用root用戶執行
nohup ./auditbeat -e &

四、kibana圖形化展示

在ES節點查看索引

#curl -XGET ‘http://127.0.0.1:9200/_cat/indices/?v‘
green  open   auditbeat-6.5.4-2019.01.17  mnkCA-QTSVS2wPkwykd_jw   3   1        468            0      2.8mb          1.5mb

kibana上創建auditbeat-6.5.4-*索引後,在Discover有數據輸出
技術分享圖片
創建儀表板
技術分享圖片
創建視圖,需要了解各個字段含義,可以參考官方文檔:
https://www.elastic.co/guide/en/beats/auditbeat/6.5/exported-fields.html

利用auditbeat采集系統審計日誌並生成圖像