參考連結
前言
請注意,我的安裝教學不是用正式環境,因為certs都是使用相同的,僅供教學快速安裝使用 。
注意:目前教學內所使用的wazuh-manager版本是4.4.4,所以如果你的wazuh-manager是其他版本像是4.5,請務必修改以下所有含有4.4的script內容為4.5
1 2 3 4 5 curl -so /etc/elasticsearch/elasticsearch.yml https://packages.wazuh.com/4.4/tpl/elastic-basic/elasticsearch_all_in_one.yml curl -so /etc/elasticsearch/elasticsearch.yml https://packages.wazuh.com/4.5/tpl/elastic-basic/elasticsearch_all_in_one.yml
ElasticStack 安裝
filebeat是跟wazuh安裝在一起
安裝需要一些額外的包,例如curl或unzip,將在後續步驟中使用。
1 apt-get install apt-transport-https zip unzip lsb-release curl gnupg
Adding the Elastic Stack repository:這兩個指令是用於將Elasticsearch的GPG公鑰導入到系統中,以便於系統驗證Elasticsearch的APT軟件包。具體來說,這兩個指令完成了以下操作:
1 2 3 4 5 6 7 curl -s https://artifacts.elastic.co/GPG-KEY-elasticsearch | gpg --no-default-keyring --keyring gnupg-ring:/usr/share/keyrings/elasticsearch.gpg --import && chmod 644 /usr/share/keyrings/elasticsearch.gpg echo "deb [signed-by=/usr/share/keyrings/elasticsearch.gpg] https://artifacts.elastic.co/packages/7.x/apt stable main" | tee /etc/apt/sources.list.d/elastic-7.x.listapt-get update
安裝elasticSearch package
1 apt-get install elasticsearch=7.17.6
Download the configuration file /etc/elasticsearch/elasticsearch.yml as follows:
如果要開放給外面的人使用要記得使用network.host=0.0.0.0,否則預設會拒絕一切非127.0.0.1的使用者
1 2 3 4 5 6 curl -so /etc/elasticsearch/elasticsearch.yml https://packages.wazuh.com/4.4/tpl/elastic-basic/elasticsearch_all_in_one.yml vim /etc/elasticsearch/elasticsearch.yml
Download the configuration file for creating the certificates:
instances.yml裡面的ip記得要改成自己的實體ip,否則跨機器的連線會出錯
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 curl -so /usr/share/elasticsearch/instances.yml https://packages.wazuh.com/4.4/tpl/elastic-basic/instances_aio.yml vim /usr/share/elasticsearch/instances.yml instances: - name: "elasticsearch" ip: - "<elastic-ip>" /usr/share/elasticsearch/bin/elasticsearch-certutil cert ca --pem --in instances.yml --keep-ca-key --out ~/certs.zip unzip ~/certs.zip -d ~/certs
The next step is to create the directory /etc/elasticsearch/certs, and then copy the CA file, the certificate and the key there:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 mkdir /etc/elasticsearch/certs/ca -pcp -R ~/certs/ca/ ~/certs/elasticsearch/* /etc/elasticsearch/certs/chown -R elasticsearch: /etc/elasticsearch/certschmod -R 500 /etc/elasticsearch/certschmod 400 /etc/elasticsearch/certs/ca/ca.* /etc/elasticsearch/certs/elasticsearch.*rm -rf ~/certs/ ~/certs.zip
啟動服務並且Generate credentials for all the Elastic Stack pre-built roles and users:
1 2 3 4 5 6 systemctl daemon-reload systemctl enable elasticsearch systemctl start elasticsearch /usr/share/elasticsearch/bin/elasticsearch-setup-passwords auto
就會看到以下角色與密碼被建立,類似下面的結果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Changed password for user apm_system PASSWORD apm_system = rj5cEOP5ahI5lNNDVuG6 Changed password for user kibana_system PASSWORD kibana_system = Jqi6Q0UKiOkntBikCBSe Changed password for user kibana PASSWORD kibana = Jqi6Q0UKiOkntBikCBSe Changed password for user logstash_system PASSWORD logstash_system = Y6NzFN8qelmUjEXIsBtr Changed password for user beats_system PASSWORD beats_system = 8Y7JmIyfgyfBvUduyYiM Changed password for user remote_monitoring_user PASSWORD remote_monitoring_user = XBXvJEu2PG5dD8H8L9X7 Changed password for user elastic PASSWORD elastic = dWAntWBQeyMIuPNFxydS
To check that the installation was made successfully, run the following command replacing <elastic_password> with the password generated in the previous step for elastic user:
1 2 3 4 5 6 curl -XGET https://localhost:9200 -u elastic:<elastic_password> -k curl -XGET https://localhost:9200 -u elastic:dWAntWBQeyMIuPNFxydS -k
安裝Wazuh
adding wazuh repository
1 2 3 4 5 curl -s https://packages.wazuh.com/key/GPG-KEY-WAZUH | gpg --no-default-keyring --keyring gnupg-ring:/usr/share/keyrings/wazuh.gpg --import && chmod 644 /usr/share/keyrings/wazuh.gpg echo "deb [signed-by=/usr/share/keyrings/wazuh.gpg] https://packages.wazuh.com/4.x/apt/ stable main" | tee -a /etc/apt/sources.list.d/wazuh.listapt-get update
安裝wazuh manager
1 2 3 4 5 6 7 8 9 apt-get install wazuh-manager systemctl daemon-reload systemctl enable wazuh-manager systemctl start wazuh-manager /var/ossec/bin/wazuh-control -j info
檢查服務是否有起來
1 systemctl status wazuh-manager
安裝Filebeat
安裝filebeat
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - sudo apt-get install apt-transport-https echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.listecho "deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.listsudo apt-get update apt-get install filebeat=7.17.6 curl -so /etc/filebeat/filebeat.yml https://packages.wazuh.com/4.4/tpl/elastic-basic/filebeat_all_in_one.yml
Download the alerts template for Elasticsearch:
1 2 3 4 5 6 7 curl -so /etc/filebeat/wazuh-template.json https://raw.githubusercontent.com/wazuh/wazuh/4.4/extensions/elasticsearch/7.x/wazuh-template.json chmod go+r /etc/filebeat/wazuh-template.json
Download the Wazuh module for Filebeat:
1 curl -s https://packages.wazuh.com/4.x/filebeat/wazuh-filebeat-0.2.tar.gz | tar -xvz -C /usr/share/filebeat/module
更改filebeat.yaml裡面elastic的ip和帳號密碼
1 2 3 vim /etc/filebeat/filebeat.yml output.elasticsearch.password: <elasticsearch_password>
Copy the certificates into /etc/filebeat/certs/
(我這邊是透過scp把vm2的certs.zip copy過去)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 scp {vm2_user_name}@{vm2-ip}:/home/user/certs.zip ~/ unzip ~/certs.zip -d ~/certs mkdir /etc/elasticsearch/certs/ca -pcp -R ~/certs/ca/ ~/certs/elasticsearch/* /etc/elasticsearch/certs/cp -r /etc/elasticsearch/certs/ca/ /etc/filebeat/certs/cp /etc/elasticsearch/certs/elasticsearch.crt /etc/filebeat/certs/filebeat.crtcp /etc/elasticsearch/certs/elasticsearch.key /etc/filebeat/certs/filebeat.key
Enable and start the Filebeat service:
1 2 3 4 5 6 systemctl daemon-reload systemctl enable filebeat systemctl start filebeat filebeat test output
安裝Kibana
要先安裝這些repository apt-get才會是安裝特定或是最新版本
1 2 3 4 5 6 7 8 curl -s https://artifacts.elastic.co/GPG-KEY-elasticsearch | gpg --no-default-keyring --keyring gnupg-ring:/usr/share/keyrings/elasticsearch.gpg --import && chmod 644 /usr/share/keyrings/elasticsearch.gpg echo "deb [signed-by=/usr/share/keyrings/elasticsearch.gpg] https://artifacts.elastic.co/packages/7.x/apt stable main" | tee /etc/apt/sources.list.d/elastic-7.x.listapt-get update apt-get install kibana=7.17.6
這邊我都是使用elasticSearch.key跟crt當作kibana的key還有crt,certs.zip就沿用elasticSearch的
1 2 3 4 5 6 7 8 9 10 11 12 cp -r /etc/elasticsearch/certs/ca/ /etc/kibana/certs/ca/cp /etc/elasticsearch/certs/elasticsearch.crt /etc/kibana/certs/kibana.crtcp /etc/elasticsearch/certs/elasticsearch.key /etc/kibana/certs/kibana.keychown -R kibana: /etc/kibana/certschmod -R 500 /etc/kibana/certschmod 400 /etc/kibana/certs/ca/ca.* /etc/kibana/certs/kibana.*rm -rf ~/certs ~/certs.zip
幫kibana下載wazuh的模板
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 curl -so /etc/kibana/kibana.yml https://packages.wazuh.com/4.4/tpl/elastic-basic/kibana.yml server.host: <kibana_ip> elasticsearch.hosts: "https://<elasticsearch_DN>:9200" elasticsearch.password: <elasticsearch_password> mkdir /usr/share/kibana/datachown -R kibana:kibana /usr/share/kibanacd /usr/share/kibanasudo -u kibana /usr/share/kibana/bin/kibana-plugin install https://packages.wazuh.com/4.x/ui/kibana/wazuh_kibana-4.4.4_7.17.6-1.zip setcap 'cap_net_bind_service=+ep' /usr/share/kibana/node/bin/node
啟動的時候就會開始把/usr/share/kibana裡面所需要的東西wazuh相關的plugin下載
1 2 3 systemctl daemon-reload systemctl enable kibana systemctl start kibana
等到啟動之後,就可以去修改wazuh.yml檔案,這樣才會call對,檔案位置在 /usr/share/kibana/data/wazuh/config/wazuh.yml
1 2 3 4 5 6 7 8 9 vim /usr/share/kibana/data/wazuh/config/wazuh.yml hosts: - default: url: https://localhost port: 55000 username: wazuh-wui password: wazuh-wui run_as: false
Access the web interface using the password generated during the Elasticsearch installation process:
1 2 3 URL: https://<kibana_ip> user: elastic password: <PASSWORD_elastic>
踩坑1: wazuh 版本太新 kibana 太舊的問題
wazuh API 4.4.4 但是 App 是 4.3.10 的版本不對,這是因為 kibana 的 wazuh plugin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 sudo su /usr/share/kibana/bin/kibana-plugin list /usr/share/kibana/bin/kibana-plugin remove wazuh sudo -u kibana /usr/share/kibana/bin/kibana-plugin install https://packages.wazuh.com/4.x/ui/kibana/wazuh_kibana-4.4.4_7.17.6-1.zip setcap 'cap_net_bind_service=+ep' /usr/share/kibana/node/bin/nodesystemctl restart kibana