关于 deploying-osquery-for-endpoint-monitoring
面向安全运维人员的 osquery 部署与监控指南,涵盖多平台端点安装、SQL 威胁狩猎和 FleetDM 集中管理。也介绍日志、调度及差分结果配置。
主要功能
- 01跨平台部署 osquery
- 02使用 SQL 查询端点状态
- 03配置周期性查询与日志
- 04通过 FleetDM 集中管理
- 05排查查询性能与事件表
适用场景
- 01为多平台终端部署 osquery
- 02狩猎无磁盘进程和异常端口
- 03检查软件、服务与端口合规性
- 04将结果日志接入集中分析流程
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill deploying-osquery-for-endpoint-monitoring安装后在 Claude Code 中输入/deploying-osquery-for-endpoint-monitoring确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
LICENSEassets/template.mdreferences/api-reference.mdstandards.mdworkflows.mdscripts/agent.pyprocess.py详细介绍
为终端监控部署 Osquery
何时使用
在以下场景使用本技能:
- 在 Windows、macOS 和 Linux 终端上部署 osquery,实现全舰队可见性
- 使用 osquery 的 SQL 接口构建威胁狩猎查询
- 监控终端合规性(已安装软件、开放端口、运行中的服务)
- 将 osquery 数据与 SIEM 或 Kolide/Fleet 集成,实现集中管理
请勿使用本技能进行实时告警(osquery 是周期性/按需执行的;实时场景请使用 EDR)。
前置条件
- 目标操作系统的 Osquery 包(https://osquery.io/downloads)
- 用于企业部署的舰队管理服务(Kolide Fleet 或 FleetDM)
- 用于 Agent 到服务端安全通信的 TLS 证书
- 用于 osquery 结果日志的日志聚合流水线(Filebeat、Fluentd)
工作流
步骤 1:安装 Osquery
# Ubuntu/Debian
export OSQUERY_KEY=1484120AC4E9F8A1A577AEEE97A80C63C9D8B80B
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys $OSQUERY_KEY
add-apt-repository 'deb [arch=amd64] https://pkg.osquery.io/deb deb main'
apt-get update && apt-get install osquery -y
# Windows (MSI)
# Download from https://osquery.io/downloads/official
msiexec /i osquery-5.12.1.msi /quiet
# macOS
brew install osquery
步骤 2:配置 Osquery
// /etc/osquery/osquery.conf (Linux/macOS) or C:\ProgramData\osquery\osquery.conf
{
"options": {
"config_plugin": "filesystem",
"logger_plugin": "filesystem",
"logger_path": "/var/log/osquery",
"disable_logging": "false",
"schedule_splay_percent": "10",
"events_expiry": "3600",
"verbose": "false",
"worker_threads": "2",
"enable_monitor": "true",
"disable_events": "false",
"disable_audit": "false",
"audit_allow_config": "true",
"host_identifier": "hostname",
"enable_syslog": "true"
},
"schedule": {
"process_monitor": {
"query": "SELECT pid, name, path, cmdline, uid, parent FROM processes WHERE on_disk = 0;",
"interval": 300,
"description": "Detect processes running without on-disk binary (fileless)"
},
"listening_ports": {
"query": "SELECT DISTINCT p.name, p.path, lp.port, lp.protocol, lp.address FROM listening_ports lp JOIN processes p ON lp.pid = p.pid WHERE lp.port != 0;",
"interval": 600,
"description": "Monitor listening network ports"
},
"persistence_check": {
"query": "SELECT name, path, source FROM startup_items;",
"interval": 3600,
"description": "Monitor persistence mechanisms"
},
"installed_packages": {
"query": "SELECT name, version, source FROM deb_packages;",
"interval": 86400,
"description": "Daily software inventory"
},
"users_and_groups": {
"query": "SELECT u.username, u.uid, u.gid, u.shell, u.directory FROM users u WHERE u.uid >= 1000;",
"interval": 3600
},
"crontab_monitor": {
"query": "SELECT * FROM crontab;",
"interval": 3600,
"description": "Monitor scheduled tasks"
},
"suid_binaries": {
"query": "SELECT path, username, permissions FROM suid_bin;",
"interval": 86400,
"description": "Detect SUID binaries"
}
},
"packs": {
"incident-response": "/usr/share/osquery/packs/incident-response.conf",
"ossec-rootkit": "/usr/share/osquery/packs/ossec-rootkit.conf",
"vuln-management": "/usr/share/osquery/packs/vuln-management.conf"
}
}
步骤 3:威胁狩猎查询
-- Detect processes with no on-disk binary (potential fileless malware)
SELECT pid, name, path, cmdline FROM processes WHERE on_disk = 0;
-- Find listening ports not associated with known services
SELECT lp.port, lp.protocol, p.name, p.path
FROM listening_ports lp JOIN processes p ON lp.pid = p.pid
WHERE lp.port NOT IN (22, 80, 443, 3306, 5432);
-- Detect unauthorized SSH keys
SELECT * FROM authorized_keys WHERE NOT key LIKE '%admin-team%';
-- Find recently modified system binaries
SELECT path, mtime, size FROM file
WHERE path LIKE '/usr/bin/%' AND mtime > (strftime('%s', 'now') - 86400);
-- Detect processes connecting to external IPs
SELECT DISTINCT p.name, p.path, pn.remote_address, pn.remote_port
FROM process_open_sockets pn JOIN processes p ON pn.pid = p.pid
WHERE pn.remote_address NOT LIKE '10.%'
AND pn.remote_address NOT LIKE '172.16.%'
AND pn.remote_address NOT LIKE '192.168.%'
AND pn.remote_address != '127.0.0.1'
AND pn.remote_address != '0.0.0.0';
-- Windows: Detect unsigned running executables
SELECT p.name, p.path, a.result AS signature_status
FROM processes p JOIN authenticode a ON p.path = a.path
WHERE a.result != 'trusted';
步骤 4:部署 FleetDM 实现集中管理
# FleetDM provides centralized osquery management
# Deploy FleetDM server, configure agents to report to it
# Agents use TLS enrollment and config from Fleet
# Agent configuration for Fleet:
# --tls_hostname=fleet.corp.com
# --tls_server_certs=/etc/osquery/fleet.pem
# --enroll_secret_path=/etc/osquery/enroll_secret
关键概念
| 术语 | 定义 |
|---|---|
| Osquery | 开源终端 Agent,将操作系统状态暴露为可查询的 SQL 表 |
| Schedule | 按定义间隔运行的周期性查询,并记录结果 |
| Pack | 为特定用例(IR、合规)分组的相关查询集合 |
| FleetDM | 开源 osquery 舰队管理平台 |
| Differential Results | Osquery 仅记录查询执行之间的变更,从而减少数据量 |
工具与系统
- Osquery:https://osquery.io/ - 终端可见性 Agent
- FleetDM:https://fleetdm.com/ - 集中式舰队管理
- Kolide:基于云的 osquery 管理,支持 Slack 集成
- osquery-go:用于 osquery 扩展的 Go 客户端库
常见陷阱
- 查询性能:涉及大表扫描的复杂查询会影响终端性能。使用 WHERE 子句,并用
EXPLAIN测试查询开销。 - Schedule 间隔过于激进:每 60 秒运行重型查询会导致 CPU 峰值。大多数查询应使用 300-3600 秒的间隔。
- 未使用差分模式:若不使用差分日志记录,osquery 会在每个间隔记录所有结果。差分模式仅记录变更。
- 缺少事件表:部分 osquery 表需要启用事件框架(process_events、socket_events)。使用
--disable_events=false启用。
评论
支持 Markdown