收集 NGINX 日志
支持的平台:
Google SecOps
SIEM
此 NGINX 解析器可处理 JSON 和 syslog 格式的日志。它会从各种日志格式中提取字段,并将其标准化为 UDM 格式。解析器会使用服务器管理和网络活动(包括用户登录和 HTTP 请求)的元数据来丰富事件。它还会处理 SSH 事件的逻辑,并根据提取的数据填充 UDM 字段。
准备工作
确保您满足以下前提条件:
- Google SecOps 实例
- NGINX 正在运行并生成日志
- 对 NGINX 宿主机的 root 访问权限
获取 Google SecOps 提取身份验证文件
- 登录 Google SecOps 控制台。
- 依次前往 SIEM 设置 > 收集代理。
- 下载提取身份验证文件。将该文件安全地保存在将安装 BindPlane 的系统上。
获取 Google SecOps 客户 ID
- 登录 Google SecOps 控制台。
- 依次选择 SIEM 设置 > 配置文件。
- 复制并保存组织详细信息部分中的客户 ID。
安装 Bindplane 代理
Windows 安装
- 以管理员身份打开命令提示符或 PowerShell。
运行以下命令:
msiexec /i "https://github.com/observIQ/bindplane-agent/releases/latest/download/observiq-otel-collector.msi" /quiet
Linux 安装
- 打开具有 root 或 sudo 权限的终端。
运行以下命令:
sudo sh -c "$(curl -fsSlL https://github.com/observiq/bindplane-agent/releases/latest/download/install_unix.sh)" install_unix.sh
其他安装资源
- 如需了解其他安装选项,请参阅此安装指南。
配置 Bindplane 代理以注入 Syslog 并将其发送到 Google SecOps
访问配置文件:
- 找到
config.yaml
文件。通常,在 Linux 上,该目录位于/etc/bindplane-agent/
目录中;在 Windows 上,该目录位于安装目录中。 - 使用文本编辑器(例如
nano
、vi
或记事本)打开该文件。
- 找到
按如下方式修改
config.yaml
文件:receivers: udplog: # Replace the port and IP address as required listen_address: "0.0.0.0:514" exporters: chronicle/chronicle_w_labels: compression: gzip # Adjust the path to the credentials file you downloaded in Step 1 creds: '/path/to/ingestion-authentication-file.json' # Replace with your actual customer ID from Step 2 customer_id: <customer_id> endpoint: malachiteingestion-pa.googleapis.com # Add optional ingestion labels for better organization ingestion_labels: log_type: 'NGINX' raw_log_field: body service: pipelines: logs/source0__chronicle_w_labels-0: receivers: - udplog exporters: - chronicle/chronicle_w_labels
根据基础架构中的需要替换端口和 IP 地址。
将
<customer_id>
替换为实际的客户 ID。在获取 Google SecOps 提取身份验证文件部分中,将
/path/to/ingestion-authentication-file.json
更新为身份验证文件的保存路径。
重启 Bindplane 代理以应用更改
如需在 Linux 中重启 Bindplane 代理,请运行以下命令:
sudo systemctl restart bindplane-agent
如需在 Windows 中重启 Bindplane 代理,您可以使用服务控制台,也可以输入以下命令:
net stop BindPlaneAgent && net start BindPlaneAgent
确定 NGINX 日志文件的位置
- 通常,NGINX 日志存储在以下位置:
- 访问日志:
/var/log/nginx/access.log
- 错误日志:
/var/log/nginx/error.log
- 访问日志:
- 使用管理员凭据访问 NGINX 主机。
运行以下命令,然后在 NGINX 主机上查找日志路径:
sudo cat /etc/nginx/nginx.conf | grep log
配置 NGINX 以将日志转发到 BindPlane
打开 NGINX 配置文件(例如
/etc/nginx/nginx.conf
):sudo vi /etc/nginx/nginx.conf
修改配置,将
<BINDPLANE_SERVER>
和<BINDPLANE_PORT>
替换为您的值:http { access_log syslog:server=<BINDPLANE_SERVER>:<BINDPLANE_PORT>,facility=local7,tag=nginx_access; error_log syslog:server=<BINDPLANE_SERVER>:<BINDPLANE_PORT>,facility=local7,tag=nginx_error; }
重启 NGINX 以应用更改:
sudo systemctl reload nginx
UDM 映射表
日志字段 | UDM 映射 | 逻辑 |
---|---|---|
_Internal_WorkspaceResourceId |
target.resource.product_object_id |
直接映射 |
Computer |
principal.asset.hostname |
直接映射 |
Facility |
additional.fields[ 设施] |
直接映射 |
HostName |
principal.asset.hostname |
如果不存在 src_ip ,则直接映射 |
ProcessName |
principal.application |
直接映射 |
SeverityLevel |
security_result.severity |
如果值为 info ,则映射为 INFORMATIONAL |
SourceSystem |
principal.asset.platform |
如果值与 Linux 匹配,则映射到 LINUX |
SyslogMessage |
多个字段 | 使用 grok 进行解析,以提取 time 、method 、target_path 、protocol 、response_code 、referral_url 、user_agent 、target_ip 、target_host 和 cache |
TenantId |
additional.fields[ TenantId] |
直接映射 |
acct |
principal.user.user_id |
如果不为空或 ? ,则直接映射 |
addr |
principal.asset.ip |
直接映射 |
audit_epoch |
metadata.event_timestamp |
使用 UNIX 格式转换为时间戳。纳秒数会从原始日志消息中提取。 |
cache |
additional.fields[ 缓存] |
直接映射 |
collection_time.nanos |
metadata.event_timestamp.nanos |
用于事件时间戳的纳秒数(如果有) |
collection_time.seconds |
metadata.event_timestamp.seconds |
用于事件时间戳(如果有)的秒数 |
data |
多个字段 | 数据的主要来源,会根据日志格式(Syslog、JSON 或其他)以不同的方式解析 |
exe |
target.process.command_line |
移除反斜杠和引号后直接映射 |
hostname |
principal.asset.hostname 或 principal.asset.ip |
如果是 IP 地址,则映射到 principal.asset.ip 。否则,映射到 principal.asset.hostname |
msg |
metadata.description |
直接映射为说明 |
node |
target.asset.hostname |
直接映射 |
pid |
target.process.pid |
直接映射 |
protocol |
network.application_protocol |
如果值与 HTTP 匹配,则映射到 HTTP |
referral_url |
network.http.referral_url |
如果不为空或 - ,则直接映射 |
res |
security_result.action_details |
直接映射 |
response_code |
network.http.response_code |
直接映射并转换为整数 |
ses |
network.session_id |
直接映射 |
src_ip |
principal.asset.ip |
直接映射 |
target_host |
target.asset.hostname |
直接映射 |
target_ip |
target.asset.ip |
直接映射,即将字符串表示形式转换为 JSON 数组,然后提取各个 IP |
target_path |
target.url |
直接映射 |
time |
metadata.event_timestamp |
已解析,以使用 dd/MMM/yyyy:HH:mm:ss Z 格式提取时间戳 |
user_agent |
network.http.user_agent |
如果不为空或 - ,则直接映射 |
metadata.event_type |
最初设为 GENERIC_EVENT ,然后可能会根据 terminal 和 protocol 等其他字段进行覆盖。如果主 Grok 模式不匹配,则默认为 USER_UNCATEGORIZED 。如果 protocol 为 HTTP 且存在 target_ip ,则设置为 NETWORK_HTTP ;如果 protocol 为 HTTP 但不存在 target_ip ,则设置为 STATUS_UPDATE |
|
metadata.log_type |
设置为 NGINX |
|
metadata.product_name |
设置为 NGINX |
|
metadata.vendor_name |
设置为 NGINX |
|
network.ip_protocol |
如果 terminal 为 sshd 或 ssh ,或者主 Grok 模式不匹配,则设置为 TCP |
|
principal.asset_id |
如果 terminal 为 sshd 或 ssh ,则设置为 GCP.GCE:0001 。如果主 Grok 模式不匹配,则设置为 GCP.GCE:0002 |
|
extensions.auth.type |
如果 terminal 为 sshd 或 ssh ,则设置为 MACHINE |
变化
2022-09-10
- 创建了默认解析器并删除了特定于客户的解析器
- 初始解析器版本
需要更多帮助?向社区成员和 Google SecOps 专业人士寻求解答。