osquery是用於記錄本機的一些系統信息,如passwd文件的改變,用戶的增加等,有了它,我們可以在系統發生改變後,能夠及時查詢出來。
curl -L https://pkg.osquery.io/rpm/GPG | tee /etc/pki/rpm-gpg/RPM-GPG-KEY-osquery
yum-config-manager --add-repo https://pkg.osquery.io/rpm/osquery-s3-rpm.repo
yum-config-manager --enable osquery-s3-rpm
yum install osquery -y
cp /usr/share/osquery/osquery.example.conf /etc/osquery/osquery.conf
osquery有兩種運行模式:
一種是交互式運行:osqueryi
還有一種是後臺進程模式:osqueryd
osquery存儲日誌的文件路徑:/var/log/osquery/
osqueryd.INFO:保存了主機差異變化信息
osqueryd.results.log
osqueryd.snapshots.log:每次查詢的結果記錄
osquery的配置文件基礎解析:osquery配置文件分爲三打段
options:osquery daemon的一些配置,日誌產生路徑,線程數等。
schedule:設置定時任務
packs:osquery的規則配置
osquery默認有些規則,但是有時候也需要新增規則,下面是一個實用規則的地址,可以參考:
https://github.com/grayddq/HIDS
這個git倉庫中,有個secrety.conf文件,該文件是系統主機的監控文件,可以放在/etc/osquery目錄下,
修改osquery.conf文件,在packs下增加一行:
"secrity": "/etc/osquery/secrity.conf"
然後重啓osquery服務:systemctl restart osqueryd
kolide fleet安裝
首先安裝mysql:
wget https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
rpm -ivh mysql80-community-release-el7-3.noarch.rpm
yum update
yum install -y mysql-community-server.x86_64 mysql-community-client.x86_64 -y
cat /var/log/mysqld.log //讀取mysql的初始化密碼
mysql -uroot -pinit_password
//修改root密碼
mysql > alter user "root"@"localhost" identified by "Root123...";
mysql > flush privileges;
mysql > create database kolide;
mysql > exit
安裝redis
注:此處安裝只爲了測試,爲了安全,切勿在生成環境如此安裝
wget http://download.redis.io/redis-stable.tar.gz
yum install -y gcc g++
tar -zxvf redis-stable.tar.gz && cd redis-stable
make && make install
cp redis.conf /etc/redis.conf
sed -i 's/daemonize no/daemonize yes/' /etc/redis.conf
redis-server /etc/redis.conf
安裝fleet
從github上下載fleet.zip文件,
下載地址爲:https://github.com/kolide/fleet/releases
下載fleet.zip後,解壓:unzip fleet.zip
cp fleet/linux/fleet /usr/bin/fleet
cp fleet/linux/fleetctl /usr/bin/fleetctl
連接數據庫:
/usr/bin/fleet prepare db --mysql_address=127.0.0.1:3306 --mysql_database=kolide --mysql_username=root --mysql_password=password
接下來配置證書
openssl genrsa -out /etc/pki/tls/private/server.key 4096
openssl req -new -key /etc/pki/tls/private/server.key -out /etc/pki/tls/certs/server.csr
openssl x509 -req -days 3650 -in /etc/pki/tls/certs/server.csr -signkey /etc/pki/tls/private/server.key -out /etc/pki/tls/certs/server.cert
創建日誌目錄:
mkdir /var/log/kolide
啓動服務
/usr/bin/fleet serve \
--mysql_address=127.0.0.1:3306 \
--mysql_database=kolide \
--mysql_username=root \
--mysql_password=password \
--redis_address=127.0.0.1:6379 \
--server_cert=/etc/pki/tls/certs/server.cert \
--server_key=/etc/pki/tls/private/server.key \
--logging_json \
--osquery_result_log_file=/var/log/kolide/osquery_result \
--osquery_status_log_file=/var/log/kolide/osquery_status
在第一次執行上面的命令後,會讓我們使用參數--auth_jwt_key進行認證,並給出一串key,
然後再上面的命令最後,加上這個參數,並附上key
/usr/bin/fleet serve \
--mysql_address=127.0.0.1:3306 \
--mysql_database=kolide \
--mysql_username=root \
--mysql_password=password \
--redis_address=127.0.0.1:6379 \
--server_cert=/etc/pki/tls/certs/server.cert \
--server_key=/etc/pki/tls/private/server.key \
--logging_json \
--osquery_result_log_file=/var/log/kolide/osquery_result \
--osquery_status_log_file=/var/log/kolide/osquery_status \
--auth_jwt_key=your_key
在啓動後,查看8080端口是否起來
然後通過https://IP:8080登陸,注意,這裏必須使用https進行登陸
登陸了fleet後,進行密碼初始化,初始化完成後,開始添加主機:
點擊右上角的add new host出現如下圖的界面:
複製下面的enroll secret
在主機上執行:echo 'your enroll secret' > /var/osquery/enroll_secret
接下來,點擊fetch fleet certificate,下載證書:
下載後,執行:mv yourCertificate.pem /var/osquery/server.pem
然後再重新執行osqueryd
/usr/bin/osqueryd \
--enroll_secret_path=/var/osquery/enroll_secret \
--tls_server_certs=/var/osquery/server.pem \
--tls_hostname=YourServerIP:8080 \
--host_identifier=hostname \
--enroll_tls_endpoint=/api/v1/osquery/enroll \
--config_plugin=tls \
--config_tls_endpoint=/api/v1/osquery/config \
--config_tls_refresh=10 \
--disable_distributed=false \
--distributed_plugin=tls \
--distributed_interval=3 \
--distributed_tls_max_attempts=3 \
--distributed_tls_read_endpoint=/api/v1/osquery/distributed/read \
--distributed_tls_write_endpoint=/api/v1/osquery/distributed/write \
--logger_plugin=tls \
--logger_tls_endpoint=/api/v1/osquery/log \
--logger_tls_period=10
執行完後,刷新頁面,可以看到有主機添加,
上面就是osquery+kolide fleet的安裝