收集 Apache 日志
支持的平台:
Google SecOps
SIEM
本文档介绍了如何使用 Bindplane 将 Apache 日志注入到 Google 安全运营中心。解析器代码会先尝试将原始日志消息解析为 JSON。如果失败,则使用正则表达式(grok
模式)根据常见的 Apache 日志格式从消息中提取字段。
准备工作
- 确保您拥有 Google SecOps 实例。
- 确保您使用的是 Windows 2016 或更高版本,或者使用了带有
systemd
的 Linux 主机。 - 如果在代理后面运行,请确保防火墙端口处于打开状态。
- 确保您对 Apache 实例具有特权访问权限。
获取 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: 'APACHE' 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
在 Apache 中配置 Syslog
- 使用 SSH 登录 Ubuntu 服务器。
在
/etc/rsyslog.d/
下创建一个名为02-apache2.conf
的文件:vim /etc/rsyslog.d/02-apache2.conf
在文件中添加以下代码:
module(load="imfile" PollingInterval="10" statefile.directory="/var/spool/rsyslog") input(type="imfile" File="/var/log/apache2/access.log" Tag="http_access" Severity="info" Facility="local6") Local6.info @<bindplane-agnet-ip>:<vindplane-agent-port> module(load="imfile" PollingInterval="10" statefile.directory="/var/spool/rsyslog") input(type="imfile" File="/var/log/apache2/error.log" Tag="http_error"
- 将
bindplane-agent-ip>
和bindplane-agent-port
替换为为 Bindplane Agent 配置的 IP 地址和端口 - 如果您使用的是 TCP 协议,请在主机行中附加一个
@
,使其如下所示:@@<bindplane-agnet-ip>:<vindplane-agent-port>
。
- 将
重启 RSyslog 服务:
sudo service rsyslog restart
UDM 映射表
日志字段 | UDM 映射 | 逻辑 |
---|---|---|
字节 | network.received_bytes | 从客户端接收的字节数。 |
字节 | network.sent_bytes | 发送到客户端的字节数。 |
bytes_out | network.sent_bytes | 发送到客户端的字节数。 |
bytes_received | network.received_bytes | 从客户端接收的字节数。 |
内容 | network.http.method | 从“Content”字段中提取的 HTTP 方法。 |
内容 | target.url | 从“内容”字段中提取的目标网址。 |
饼干 | additional.fields.value.string_value | “cookie”字段的值。 |
dest_ip | target.ip | 目标的 IP 地址。 |
dest_name | target.hostname | 目标的主机名。 |
dest_port | target.port | 目标的端口。 |
说明 | metadata.description | 事件说明。 |
duration_microseconds | additional.fields.value.string_value | “duration_microseconds”字段的值。 |
file_full_path | target.file.full_path | 目标文件的完整路径。 |
主机名 | target.hostname | 目标的主机名。 |
http_content_type | additional.fields.value.string_value | “http_content_type”字段的值。 |
http_host | principal.hostname | 正文的主机名。 |
http_method | network.http.method | HTTP 方法。 |
http_referrer | network.http.referral_url | HTTP 引荐来源网址。 |
http_user_agent | network.http.user_agent | HTTP 用户代理。 |
ID | metadata.id | 事件的 ID。 |
insertId | metadata.product_log_id | 商品日志 ID。 |
ip | principal.ip | 主账号的 IP 地址。 |
jsonPayload.cIP | target.ip | 目标的 IP 地址。 |
jsonPayload.cPort | target.port | 目标的端口。 |
jsonPayload.csBytes | network.sent_bytes | 发送到客户端的字节数。 |
jsonPayload.csMethod | network.http.method | HTTP 方法。 |
jsonPayload.csMimeType | target.file.mime_type | 目标文件的 MIME 类型。 |
jsonPayload.csReferer | network.http.referral_url | HTTP 引荐来源网址。 |
jsonPayload.cs网址 | target.url | 目标网址。 |
jsonPayload.csUserAgent | network.http.user_agent | HTTP 用户代理。 |
jsonPayload.sHierarchy | additional.fields.value.string_value | “sHierarchy”字段的值。 |
jsonPayload.sHostname | principal.hostname | 正文的主机名。 |
jsonPayload.sIP | principal.ip | 主账号的 IP 地址。 |
jsonPayload.scBytes | network.received_bytes | 从客户端接收的字节数。 |
jsonPayload.scHTTPStatus | network.http.response_code | HTTP 响应代码。 |
jsonPayload.scResultCode | additional.fields.value.string_value | “scResultCode”字段的值。 |
LastStatus | network.http.response_code | HTTP 响应代码。 |
log_level | security_result.severity | 安全结果的严重程度。 |
logName | security_result.category_details | 安全结果的类别详细信息。 |
方法 | network.http.method | HTTP 方法。 |
pid | principal.process.pid | 主账号的进程 ID。 |
端口 | target.port | 目标的端口。 |
proto | network.application_protocol | 应用协议。 |
引荐来源 | network.http.referral_url | HTTP 引荐来源网址。 |
RemoteHost | principal.ip | 主账号的 IP 地址。 |
RemoteUser | principal.user.userid | 主账号的用户 ID。 |
resource.labels.instance_id | target.resource.product_object_id | 目标资源的商品对象 ID。 |
resource.labels.project_id | target.resource.attribute.labels.value | “project_id”标签的值。 |
resource.labels.zone | target.resource.attribute.cloud.availability_zone | 目标资源的可用区。 |
resource.type | target.resource.resource_type | 目标的资源类型。 |
回答 | network.http.response_code | HTTP 响应代码。 |
SizeBytes | network.received_bytes | 从客户端接收的字节数。 |
src_ip | principal.ip | 主账号的 IP 地址。 |
src_port | principal.port | 主账号的端口。 |
ssl_cipher | network.tls.cipher | TLS 加密算法。 |
ssl_version | network.tls.version_protocol | TLS 版本协议。 |
状态 | network.http.response_code | HTTP 响应代码。 |
目标 | target.url | 目标网址。 |
target_ip | target.ip | 目标的 IP 地址。 |
target_port | target.port | 目标的端口。 |
时间 | metadata.event_timestamp | 事件时间戳。 |
uri_path | target.process.file.full_path | 目标文件的完整路径。 |
用户 | principal.user.userid | 主账号的用户 ID。 |
用户代理 | network.http.user_agent | HTTP 用户代理。 |
version_protocol | network.tls.version_protocol | TLS 版本协议。 |
Workername | principal.hostname | 正文的主机名。 |
x_forwarded_for | “X-Forwarded-For”标头的值。 | |
metadata.log_type | 该值在解析器代码中设置为“APACHE”。 | |
metadata.product_name | 该值在解析器代码中设置为“Apache Web Server”。 | |
metadata.vendor_name | 该值在解析器代码中设置为“Apache”。 | |
metadata.event_type | 该值取决于是否存在正文和目标信息。如果同时存在主账号和目标账号,则事件类型会设为“NETWORK_HTTP”。如果只有主账号,则事件类型设置为“STATUS_UPDATE”。否则,该值会设置为“GENERIC_EVENT”。 | |
additional.fields.key | 在解析器代码中,系统会根据字段将键设置为“keep_alive”“duration_microseconds”“cookie”“http_content_type”“sHierarchy”“scResultCode”。 | |
target.port | 如果“proto”字段为“HTTP”,则端口设置为 80。如果“proto”字段为“HTTPS”,则端口设置为 443。如果“proto”字段为“FTP”,则端口设置为 21。 | |
target.resource.attribute.labels.key | 该键在解析器代码中设置为“project_id”。 |
变化
2025-01-09
增强功能:
- 添加了新的 Grok 模式来解析新日志格式。
- 将“user_location”映射到“principal.location.country_or_region”。
- 将“proto”“proto_version”“uri_path”和“uri_query”映射到“additional.fields”。
2024-12-19
增强功能:
- 添加了 Grok 模式来解析未解析的日志。
2024-09-10
增强功能:
- 添加了对解析未解析日志的支持。
2024-08-05
增强功能:
- 添加了 Grok 模式,用于将“jsonPayload.message”字段解析为“additional.fields”。
- 将“ip_msg”映射到“principal.ip”和“principal.asset.ip”。
- 将“msg_method”映射到“network.http.method”。
- 将“response_code”映射到“network.http.response_code”。
- 将“useragentvalue”映射到“network.http.user_agent”。
2024-06-11
增强功能:
- 添加了 Grok 模式,用于解析新的 SYSLOG 格式日志模式。
2024-01-25
增强功能:
- 添加了新的 Grok 模式,用于解析包含符号“+”的 syslog 日志。
2024-01-25
增强功能:
- 添加了新的 Grok 模式,用于解析包含符号“+”的 syslog 日志。
2023-12-21
增强功能:
- 处理了未解析的 JSON 日志。
- 将“src_port”映射到“principal.port”。
- 将“x_forwarded_for”映射到“principal.ip”。
- 将“keep_alive”“duration_microseconds”“cookie”“http_content_type”映射到“additional.fields”。
- 将“user”映射到“principal.user.userid”。
- 将“http_host”映射到“principal.hostname”。
- 将“file_full_path”映射到“target.file.full_path”。
- 将“ssl_version”映射到“network.tls.version_protocol”。
- 将“ssl_cipher”映射到“network.tls.cipher”。
- 将“uri_path”映射到“target.process.file.full_path”。
- 将“http_referrer”映射到“network.http.referral_url”。
- 将“http_user_agent”映射到“network.http.user_agent”。
- 将“http_method”映射到“network.http.method”。
- 将“protocol”映射到“network.application_protocol”。
- 将“dest_port”映射到“target.port”。
- 将“dest_name”映射到“target.hostname”。
- 将“bytes_out”映射到“network.sent.bytes”。
2023-07-31
增强功能:
- 修改了 Grok 模式,以便在没有字节可用时处理连字符("-")。
2023-06-05
增强功能:
- 将“内容”映射到“target.url”“network.http.method”和“network.tls.version_protocol”。
- 将“LastStatus”映射到“network.http.response_code”。
- 将“SizeBytes”映射到“network.received_bytes”。
- 将“Workername”映射到“principal.hostname”。
- 将“Port”映射到“target.port”。
- 将“ID”映射到“metadata.id”。
- 将“XForwardedForIP”和“RemoteHost”映射到“principal.ip”。
- 将“Remoteuser”映射到“principal.user.userid”。
- 修改了 Grok 模式,以支持错误的日志解析。
2023-02-20
增强功能:
- 修改了 Grok 模式,以支持错误的日志解析。
- 将“user_agent”转换为“network.http.parsed_user_agent”。
2022-09-21
增强功能:
- 已迁移到默认解析器。
2022-09-07
增强功能:
- 添加了 Grok 模式,以解析采用 json + syslog 格式的日志。
- 将“host.name”和“hostname”字段映射到了“target.hostname”。
- 将字段“log.file.path”映射到“principal.process.file.full_path”。
- 将字段“mac”映射到“principal.mac”。
- 将字段“ip”映射到了“principal.asset.ip”。
- 将字段“os.version”映射到了“principal.platform_version”。
- 将字段“os.kernel”映射到“principal.platform_patch_level”。
- 将字段“os.platform”映射到“principal.platform”。
- 将“architecture”字段映射到了“principal.asset.hardware”。
- 将字段“id”映射到“principal.asset.asset_id”。
2022-05-12
增强功能:
- 为未解析的唯一日志添加了 Grok 模式。
- 添加了针对“network.http.user_agent”和“network.http.referral_url”的条件检查。
- 添加了对 Apache Traffic Server (ATS) 代理日志的支持。
需要更多帮助?向社区成员和 Google SecOps 专业人士寻求解答。