簡單威脅檢測系統(tǒng)搭建
簡介:本次實(shí)驗(yàn)基于開組件Suricata + ELK 進(jìn)行搭建乡话,運(yùn)行系統(tǒng)為centos。Suricata為開源檢測引擎挽霉,并將檢測數(shù)據(jù)傳入ES中進(jìn)行大數(shù)據(jù)檢索儒老。
圖比較詳細(xì):https://zhuanlan.zhihu.com/p/140397901
Suricata檢測引擎搭建
參考鏈接https**://linux.cn/article-6985-1.html
官網(wǎng)下載suricata安裝包仲义,并進(jìn)行解壓:
安裝依賴包:
sudo yum install wget libpcap-devel libnet-devel pcre-devel gcc-c++ automake autoconf libtool make libyaml-devel zlib-devel file-devel jansson-devel nss-devel
./configure --sysconfdir=/etc --localstatedir=/var
進(jìn)行編譯:
make
sudo make install
sudo make install-conf
sudo make install-rules
編譯后,配置文件默認(rèn)存放在/etc/Suricata议谷。
官方默認(rèn)規(guī)則更新下載:
pip install Suricata-updata 然后執(zhí)行 suricat-updata
自定義規(guī)則添加:
在rules 目錄下添加自定義規(guī)則 venus.rules.
通過vim將下面規(guī)則寫入,該規(guī)則是針對隧道軟件NPS特征進(jìn)行編寫踪危。
Nsp工具:http:*//github.com/ehang-io/nps
以下是pcap包中的特征
根據(jù)特征編寫相應(yīng)規(guī)則檢測
alert tcp any any -> any any (msg:"nps_socks"; flow:established; content:"{|22|ConnType|22||3a|"; content:"|22|Host|22|"; distance:0; content:"|22|Crypt|22|"; distance:0; sid:2003; rev:1;)
然后在/etc/Suricata.yaml 配置文件中加入venus.rules。
Suricata檢測執(zhí)行:
suricata -c /etc/suricata/suricata.yaml -i enp0s31f6
然后測試機(jī)上運(yùn)行nps的客戶端铝耻,與服務(wù)端通信誊爹。當(dāng)然你也可以寫一些簡單的規(guī)則進(jìn)行測試蹬刷,其實(shí)我已經(jīng)很簡單了。
查看告警日志:
詳細(xì)告警數(shù)據(jù)存放在/var/log/suricata/eve.json中(之后需要將其導(dǎo)入ELK中進(jìn)行檢索)频丘,簡單告警日志存放在/var/log/Suricata/fast.log中办成。
Jdk1.8環(huán)境部署
官方下載壓縮包并解壓至/opt:
添加環(huán)境變量:
Vim /etc/profile
完成后執(zhí)行./etc/profile,成功運(yùn)行java搂漠。
Elasticsearch數(shù)據(jù)庫搭建
官方下載壓縮包并解壓至/opt中:
創(chuàng)建新用戶
Es數(shù)據(jù)庫迂卢,默認(rèn)無法使用root進(jìn)行啟動(dòng),所以需要使用非root進(jìn)行啟動(dòng)或者修改配置文件桐汤,推薦使用非root啟動(dòng)而克。
useradd -d /opt/ -m ela
創(chuàng)建ela用戶,并為其授權(quán)/opt
修改ES配置文件:
允許任意用戶訪問怔毛,端口為9200.
啟動(dòng)ES常見錯(cuò)誤:
參考鏈接:https**://blog.csdn.net/zhang89xiao/article/details/68925294
1员萍、can not run elasticsearch as root
切換到非root用戶
2、main ERROR Could not register mbeans java.security.AccessControlException: access denied ("javax.management.MBeanTrustPermission" "register")
改變elasticsearch文件夾所有者到當(dāng)前用戶
sudo chown -R noroot:noroot elasticsearch
3拣度、max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
sudo vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并執(zhí)行命令:
sudo sysctl -p
4碎绎、max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
sudo vi /etc/security/limits.conf
添加如下內(nèi)容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
sudo vi /etc/pam.d/common-session
添加 session required pam_limits.so
sudo vi /etc/pam.d/common-session-noninteractive
添加 session required pam_limits.so
ES數(shù)據(jù)庫啟動(dòng)運(yùn)行
Su ela 切換到ela用戶中。
執(zhí)行./opt/elasticsearch-5.6.0/binelasticsearch蜡娶。
Curl測試es正常運(yùn)行混卵。
Kibana可視化搭建
官方下載壓縮包并解壓至/opt:
修改配置文件:
/opt/kibana-5.6.9-linux-x86_64/config/kibana.yml
運(yùn)行啟動(dòng)kibana:
./kibana
訪問192.168.31.220:5601
Logstash日志收集搭建
簡介:主要功能為收集suricata告警日志,在進(jìn)行篩選過濾傳人ES窖张。
官方下載壓縮包并解壓至/opt:
編寫logstach.conf配置文件:
[root@localhost bin]# cat logstash.conf
input{
? ? file{
? ? ? ? type => ["void_feedback"]
? ? ? ? path => ["/var/log/suricata/eve.json"]
? ? ? ? start_position => "beginning"
? ? }
}
//通過fitler 對message信息進(jìn)行json過濾幕随,不然es無法檢索
filter {
? ? if [type] == "void_feedback" {
? ? ? ? json {
? ? ? ? ? ? source => "message"
? ? ? ? ? ? #target => "doc"
? ? ? ? ? ? #remove_field => ["message"]
? ? ? ? }? ? ? ?
? ? }
}
output{
? ? elasticsearch {
? ? ? index => "suricata-%{+YYYY.MM.dd}"
? ? ? hosts => ["127.0.0.1:9200"]
}
stdout{
? ? ? ? codec => rubydebug
? ? }
}
Logstach啟動(dòng)運(yùn)行:
./logstash -f logstash.conf
數(shù)據(jù)成功導(dǎo)入ES中
完成測試OK
訪問192.168.31.220(已使用nginx進(jìn)行端口轉(zhuǎn)發(fā)),通過kibana查看告警宿接。
YLL
2020-5-13