重慶分公司,新征程啟航
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
這篇文章主要講解了“怎么在Linux上使用Osquery設(shè)置文件完整性監(jiān)控”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么在Linux上使用Osquery設(shè)置文件完整性監(jiān)控”吧!
創(chuàng)新互聯(lián)公司是一家業(yè)務(wù)范圍包括IDC托管業(yè)務(wù),網(wǎng)站空間、主機(jī)租用、主機(jī)托管,四川、重慶、廣東電信服務(wù)器租用,四川電信科技城機(jī)房,成都網(wǎng)通服務(wù)器托管,成都服務(wù)器租用,業(yè)務(wù)范圍遍及中國(guó)大陸、港澳臺(tái)以及歐美等多個(gè)國(guó)家及地區(qū)的互聯(lián)網(wǎng)數(shù)據(jù)服務(wù)公司。
Osquery是一個(gè)SQL驅(qū)動(dòng)操作系統(tǒng)檢測(cè)和分析工具,它由Facebook創(chuàng)建,支持像SQL語句一樣查詢系統(tǒng)的各項(xiàng)指標(biāo),可以用于OSX和Linux操作系統(tǒng)。
Osquery是一個(gè)多平臺(tái)軟件,可以安裝在Linux,Windows,MacOS和FreeBSD上。它允許我們使用基于SQL的查詢來處理操作系統(tǒng)的配置文件、性能、安全檢查等。
在本教程中,我們將向您展示如何使用Osquery設(shè)置文件完整性監(jiān)控(FIM)。我們使用的linux操作系統(tǒng)是Ubuntu 18.04和CENTOS 7。
條件
Linux(Ubuntu或CentOS)
Root權(quán)限
完成了第一個(gè)osquery指南
步驟一:在Linux服務(wù)器上安裝osquery
Osquery為所有的安裝平臺(tái)提供了自己的存儲(chǔ)庫,我們要做的第一步是從官方的osquery存儲(chǔ)庫安裝osquery包。
在Ubuntu上
將osquery密鑰添加到系統(tǒng)。
Export OSQUERY_KEY = 1484120AC4E9F8A1A577AEEE97A80C63C9D8B80B
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $ OSQUERY_KEY
添加osquery存儲(chǔ)庫并安裝。
sudo add-apt-repository'deb [arch = amd64] https://pkg.osquery.io/deb deb
main'sudo apt install osquery -y
在CentOS上
將osquery密鑰添加到系統(tǒng)。
curl -L https://pkg.osquery.io/rpm/GPG | sudo tee / etc / pki / rpm-gpg / RPM-GPG-KEY-osquery
添加并啟用osquery存儲(chǔ)庫,然后安裝該軟件包。
Sudo yum-config-manager --add-repo https://pkg.osquery.io/rpm/osquery-s3-rpm.repo
sudo yum-config-manager --enable osquery-s3-rpm
sudo yum install osquery -y
等待安裝所有軟件包
注意:如果您收到關(guān)于yum-config-manager命令的錯(cuò)誤消息。
sudo: yum-config-manager: command not found
安裝'yum-utils'包。
yum -y install yum-utils
步驟二:?jiǎn)⒂肙squery的Syslog Consumption
Osquery提供了一些功能,可以使用Apple system Log (ASL)讀取Apple MacOS上的系統(tǒng)日志,對(duì)于Linux則使用syslog。
在此步驟中,我們將通過rsyslog啟用osquery的syslog consumption。
在Ubuntu上
使用如下apt命令安裝rsyslog
sudo apt install rsyslog –y
在CentOS上
使用如下yum命令安裝rsyslog包。
sudo yum install rsyslog -y
安裝完成后,轉(zhuǎn)到'/etc/rsyslog.d'目錄并創(chuàng)建一個(gè)新的配置文件osquery.conf。
cd /etc/rsyslog.d/
vim osquery.conf
然后粘貼如下配置
template( name =“OsqueryCsvFormat” type =“string” string =“%timestamp ::: date-rfc3339,csv%,%hostname ::: csv%,%syslogseverity ::: csv%,%syslogfacility-text ::: csv%,%syslogtag ::: csv%,%msg ::: csv%\ n“ ) *。* action(type =”ompipe“Pipe =”/ var / osquery / syslog_pipe“template =”O(jiān)squeryCsvFormat“)
保存并退出
步驟三: osquery基本配置
osquery默認(rèn)配置是'osquery.conf',通常位于'/ etc / osquery'目錄中。
在這一步,我們將了解osquery配置組件,創(chuàng)建自定義osquery配置,然后將osqueryd部署為服務(wù)。
格式化為JSON 文件的osquery 配置包含如下規(guī)范:
Options:osqueryd CLI命令的一部分,它決定應(yīng)用程序的啟動(dòng)和初始化。
Schedule:將計(jì)劃的查詢名稱的Flow定義到查詢?cè)斍椤?/p>
Decorators:用于向結(jié)果和快照日志添加額外的“decorations”。
Packs:一組調(diào)度查詢
More:File Path, YARA, Prometheus, Views, EC2, Chef Configuration。
轉(zhuǎn)到'/ etc / osquery'目錄并創(chuàng)建一個(gè)新的自定義配置'osquery.conf'。
cd / etc / osquery /
vim osquery.conf
粘貼以下配置。
{ “options”:{ “config_plugin”:“filesystem”, “l(fā)ogger_plugin”:“filesystem”, “l(fā)ogger_path”:“/ var / log / osquery”, “disable_logging”:“false”, “l(fā)og_result_events”:“true” , “schedule_splay_percent”:“10”, “pidfile”:“/ var / osquery / osquery.pidfile”, “events_expiry”:“3600”, “database_path”:“/ var / osquery / osquery.db”, “verbose” :“false”, “worker_threads”:“2”, “enable_monitor“:”true“, ”disable_events“:”false“, ”disable_audit“:”false“, ”audit_allow_config“:”true“, “host_identifier”:“hakase-labs”, “enable_syslog”:“true”, “syslog_pipe_path”:“/ var / osquery / syslog_pipe”, “force”:“true”, “audit_allow_sockets”:“true”, “schedule_default_interval” :“3600” }, “schedule”:{ “crontab”:{ “query”:“SELECT * FROM crontab;”, “interval”:300 }, “system_info”:{ “query”:“SELECT hostname,cpu_brand, physical_memory FROM system_info;“, “interval”:3600 }, “ssh_login”:{ “query”:“SELECT username,time,host FROM last WHERE type = 7”, “interval”:360 } }, “decorators”:{ “l(fā)oad”:[ “SELECT uuid AS host_uuid FROM system_info;”, “SELECT user AS username FROM logged_in_users ORDER BY time DESC LIMIT 1;” ] }, “packs”:{ “osquery-monitoring”:“/ usr / share / osquery / packages / osquery -monitoring.conf” } }
保存并退出
注意:
我們使用'filesystem'作為配置文件和記錄器插件
定義'/ var / log / osquery'目錄的記錄器路徑
將SysLog-PIP啟用到'/Va/ysLogy/SySalpJixBube文件中。
在調(diào)度程序中,我們定義了三個(gè)查詢來檢查crontab, system info, 和ssh login.
啟用名為“osquery-monitoring”的osquery包,并將該包放置在'/Ur/Stuts/OsQue/Pokes’目錄中。
啟動(dòng)osqueryd daemon service(使其在每次系統(tǒng)引導(dǎo)時(shí)啟動(dòng))。
systemctl start osqueryd
systemctl enable osqueryd
重新啟動(dòng)rsyslog服務(wù)
systemctl restart rsyslog
osquery基本配置完成。
步驟四:使用osquery配置文件完整性監(jiān)控(FIM)
Osquery使用Linux和FSEvents提供Linux和MacOS Darwin上的文件完整性監(jiān)控。簡(jiǎn)單地的說,它使用'file_path'檢測(cè)定義目錄上的任何一個(gè)文件的更改,然后將所有活動(dòng)存儲(chǔ)到file_events表中。
在這個(gè)步驟中,我們將配置Osquery來使用自定義FIM包監(jiān)視重要目錄,如HOST、SSH目錄,以及tmp和www web根目錄等。
轉(zhuǎn)到“/usr/share/osquery/packs”目錄,創(chuàng)建一個(gè)新的軟件包配置文件“fim.conf”。
cd / usr / share / osquery / packs
vim fim.conf
配置如下:
{ "queries": { "file_events": { "query": "SELECT * FROM file_events;", "removed": false, "interval": 300 } }, "file_paths": { "homes": [ "/root/.ssh/%%", "/home/%/.ssh/%%" ], "etc": [ "/etc/%%" ], "home": [ "/home/%%" ], "tmp": [ "/tmp/%%" ], "www": [ "/var/www/%%" ] } }
保存并退出
返回到 '/etc/osquery'配置目錄,編輯osquery.conf文件。
cd /etc/osquery/
vim osquery.conf
在 'packs' 中添加文件完整性監(jiān)控包配置。
"packs": { "osquery-monitoring": "/usr/share/osquery/packs/osquery-monitoring.conf", "fim": "/usr/share/osquery/packs/fim.conf" }
保存并退出,然后重新啟動(dòng)osqueryd服務(wù)。
systemctl restart osqueryd
注意:繼續(xù)使用JSON linter“ http://jsonlint.com/ ” 檢查JSON配置文件,確保沒有錯(cuò)誤。
步驟五:測(cè)試
我們將通過在定義的目錄“home”和“www”上創(chuàng)建一個(gè)新文件來測(cè)試文件完整性監(jiān)控包。
轉(zhuǎn)到“/var/www/”目錄,創(chuàng)建一個(gè)名為“howtoforge.md”的新文件。
cd /var/www/
touch howtoforge.md
轉(zhuǎn)到'/ home / youruser /'目錄并創(chuàng)建一個(gè)名為'hakase-labs.md'的新文件。
cd / home / vagrant /
touch hakase-labs.md
使用實(shí)時(shí)交互模式osqueryi 和osquery 的結(jié)果日志檢查所有日志監(jiān)控。
osqueryi
運(yùn)行下面的osqueryi命令。
osqueryi --config-path /etc/osquery/osquery.conf
檢查'file_events'表中文件更改的所有日志。
對(duì)于全局更改。
select * from file_events;
對(duì)于'home'目錄。
select target_path, category, action, atime, ctime, mtime from file_events WHERE category="home";
對(duì)于'www' web root目錄。
select target_path, category, action, atime, ctime, mtime from file_events WHERE category="www";
osqueryd 結(jié)果日志
轉(zhuǎn)到'/ var / log / osquery'目錄,您將獲得'osqueryd.results.log'文件。
cd / var / log / osquery /
ls -lah osqueryd.results.log
使用'grep'命令篩選osquery日志。
grep -rin howtoforge.md osqueryd.results.log
grep -rin hakase-labs.md osqueryd.results.log
你將看到所有已創(chuàng)建的文件信息
使用osquery在Linux Server Ubuntu和CentOS上安裝和配置文件完整性監(jiān)控(FIM)已成功完成。
感謝各位的閱讀,以上就是“怎么在Linux上使用Osquery設(shè)置文件完整性監(jiān)控”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)怎么在Linux上使用Osquery設(shè)置文件完整性監(jiān)控這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!