IDS入侵檢測系統部署

 

IDS是英文“Intrusion Detection Systems”的縮寫,中文意思是“入侵檢測系統”。專業上講就是依照一定的安全策略,通過軟、硬件,對網絡、系統的運行狀況進行監視,儘可能發現各種攻擊企圖、攻擊行爲或者攻擊結果,以保證網絡系統資源的機密性、完整性和可用性。做一個形象的比喻:假如防火牆是一幢大樓的門鎖,那麼IDS就是這幢大樓裏的監視系統。一旦小偷爬窗進入大樓,或內部人員有越界行爲,只有實時監視系統才能發現情況併發出警告。

原理

入侵檢測可分爲實時入侵檢測和事後入侵檢測兩種。

實時入侵檢測在網絡連接過程中進行,系統根據用戶的歷史行爲模型、存儲在計算機中的專家知識以及神經網絡模型對用戶當前的操作進行判斷,一旦發現入侵跡象立即斷開入侵者與主機的連接,並收集證據和實施數據恢復。這個檢測過程是不斷循環進行的。而事後入侵檢測則是由具有網絡安全專業知識的網絡管理人員來進行的,是管理員定期或不定期進行的,不具有實時性,因此防禦入侵的能力不如實時入侵檢測系統。

一個入侵檢測系統(I DS)的通用模型。它將一個入侵檢測系統分爲以下組件:

事件產生器(Event generators)

事件分析器(Event analyzers)

響應單元(Response units )

事件數據庫(Event databases )

將IDS需要分析的數據統稱爲事件(event),它可以是網絡中的數據包,也可以是從系統日誌等其他途徑得到的信息。

 

配置安裝

涉及軟件有suricata,logstash,elasticsearch,kibana,evebox,nginx

因爲軟件會經常更新所以本文會精確到版本號,以免以後讀者看教程時對不上號就說文章寫的不對。centos7版本

elasticsearch-7.10.0-x86_64.rpm   這個是用來存取事件的

evebox-latest-x86_64.rpm             這個是用來分析的

kibana-7.10.0-x86_64.rpm              這個可裝可不裝,只是用來查詢歷史的

logstash-7.10.0-x86_64.rpm            這個是用來收集事件的

suricata-6.0.0.tar.gz                         這個是產生事件的


 

 
# yum install epel-release# yum -y install gcc libpcap-devel pcre-devel libyaml-devel file-devel \  zlib-devel jansson-devel nss-devel libcap-ng-devel libnet-devel tar make \  libnetfilter_queue-devel lua-devel PyYAML libmaxminddb-devel rustc cargo \  lz4-devel# tar xzvf suricata-6.0.0.tar.gz# cd suricata-6.0.0# ./configure# make# make install# make install-full
 

啓動 ens192 是網卡名,可以加入到/etc/rc.local

# /usr/local/bin/suricata -c /usr/local/etc/suricata/suricata.yaml -i ens192 >> /dev/null 2>&1 &

 

# rpm -ihv elasticsearch-7.10.0-x86_64.rpm# rpm -ihv logstash-7.10.0-x86_64.rpm# rpm -ihv kibana-7.10.0-x86_64.rpm# rpm -ihv evebox-latest-x86_64.rpm# systemctl enable kibana# systemctl enable elasticsearch# systemctl enable logstashsystemctl enable evebox

 

# vim /etc/logstash/conf.d/suricata.conf  

加下入以下內容

input {  file {    path => ["/usr/local/var/log/suricata/*.json"]    codec =>   json    type => "SELKS"  }}filter {  if [type] == "SELKS" {    date {      match => [ "timestamp", "ISO8601" ]    }    ruby {      code => "        if event.get('[event_type]') == 'fileinfo'          event.set('[fileinfo][type]', event.get('[fileinfo][magic]').to_s.split(',')[0])        end      "    }    ruby {      code => "        if event.get('[event_type]') == 'alert'          sp = event.get('[alert][signature]').to_s.split(' group ')          if (sp.length == 2) and /\A\d+\z/.match(sp[1])            event.set('[alert][signature]', sp[0])          end        end      "     }    metrics {      meter => [ "eve_insert" ]      add_tag => "metric"      flush_interval => 30    }  } if [http] {    useragent {       source => "[http][http_user_agent]"       target => "[http][user_agent]"    }  }  if [src_ip]  {    geoip {      source => "src_ip"      target => "geoip"      #database => "/usr/share/GeoIP/GeoIPCity.dat"      #add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ]      #add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}"  ]    }  }                                                                                                                                                                                                                                                             if [dest_ip]  {                                                                                                                                                                                                                                             geoip {                                                                                                                                                                                                                                                       source => "dest_ip"                                                                                                                                                                                                                                         target => "geoip"                                                                                                                                                                                                                                           #database => "/usr/share/GeoIP/GeoIPCity.dat"                                                                                                                                                                                                               #add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ]                                                                                                                                                                                           #add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}"  ]                                                                                                                                                                                         }                                                                                                                                                                                                                                                         }                                                                                                                                                                                                                                                         }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       output {                                                                                                                                                                                                                                                      if [event_type] and [event_type] != 'stats' {                                                                                                                                                                                                                 elasticsearch {                                                                                                                                                                                                                                               hosts => "10.66.240.72"                                                                                                                                                                                                                                     index => "logstash-%{event_type}-%{+YYYY.MM.dd}"                                                                                                                                                                                                            template_overwrite => true                                                                                                                                                                                                                                  template => "/etc/logstash/elasticsearch7-template.json"                                                                                                                                                                                                  }                                                                                                                                                                                                                                                         } else {                                                                                                                                                                                                                                                      elasticsearch {                                                                                                                                                                                                                                               hosts => "10.66.240.72"                                                                                                                                                                                                                                     index => "logstash-%{+YYYY.MM.dd}"                                                                                                                                                                                                                          template_overwrite => true                                                                                                                                                                                                                                  template => "/etc/logstash/elasticsearch7-template.json"                                                                                                                                                                                                  }                                                                                                                                                                                                                                                         }                                                                                                                                                                                                                                                         }                                             
# systemctl start elasticsearch
# chmod -R 755 /etc/logstash
# chmod -R 777 /usr/local/var/log
# systemctl start logstash# cp /etc/evebox/evebox.yaml.example /etc/evebox.yaml# systemctl start evebox # git clone https://github.com/StamusNetworks/KTS7.git#  cp KTS7/es-template/elasticsearch7-template.json  /etc/logstash/# cd KTS7/API-KIBANA7/# curl -X POST "localhost:5601/api/saved_objects/_import" -H 'kbn-xsrf: true' --form [email protected]# curl -X POST "localhost:5601/api/saved_objects/_import" -H 'kbn-xsrf: true' --form [email protected]# curl -X POST "localhost:5601/api/saved_objects/_import" -H 'kbn-xsrf: true' --form [email protected]# curl -X POST "localhost:5601/api/saved_objects/_import" -H 'kbn-xsrf: true' --form [email protected]# curl -X POST "localhost:5601/api/saved_objects/_import" -H 'kbn-xsrf: true' --form [email protected]# service kibana restart

最後安裝個nginx用於反向代理evebox ,因爲它只能是http://localhost:5636,想要遠程訪問還要走個代理纔行,nginx.conf加入以下配置即可。

   server {        listen       *:80;        server_name  localhost;        root         /usr/share/nginx/html;       location / {             proxy_set_header   Host    $host;             proxy_set_header   X-Real-IP $remote_addr;             proxy_set_header   REMOTE-HOST $remote_addr;             proxy_set_header X-Forwarded-Proto https;             proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;             proxy_pass http://127.0.0.1:5636;                }      }

 

 

 

 

                      

需要說明的是如需新增節點的話,只需要安裝suricata,logstash即可,然後打開elasticsearch遠程訪問

 

 

訂閱號定期分享技術乾貨歡迎關注。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章