收集 Apache 日志
解析器版本:20.0
本文档介绍了如何使用 Bindplane 代理将 Apache 日志注入 Google Security Operations。
Apache HTTP Server 是一款开源 Web 服务器,可处理 HTTP 请求并生成访问和错误日志。解析器可处理标准组合/通用日志格式和 JSON 格式的日志,并提取 HTTP 请求详细信息、响应代码和客户端信息。
准备工作
请确保满足以下前提条件:
- Google SecOps 实例
- Windows Server 2016 或更高版本,或者具有
systemd的 Linux 主机 - Bindplane 代理与 Apache 服务器之间的网络连接
- 如果在代理后面运行,请确保按照 Bindplane 代理要求打开防火墙端口
- 对 Apache 服务器的特权访问权限(root 或 sudo)
获取 Bindplane 代理的 Google SecOps 凭证
如需向 Google SecOps 验证 Bindplane 代理,请选择以下方法之一:
- 新部署:使用 Chronicle API(选项 1)。
- 旧版部署:继续使用提取身份验证文件(方法 2),直到提取 API 于 2027 年 7 月 20 日停用。
方法 1:为 Chronicle API 创建服务账号(推荐)
- 登录 Google Cloud 控制台,然后选择与您的 Google SecOps 实例关联的 Google Cloud 项目。
- 前往 IAM 和管理 > 服务账号。
- 点击创建服务账号。
- 提供以下配置详细信息:
- 服务账号名称:输入账号的名称(例如
bindplane-ingest)。 - 服务账号说明:输入说明(例如
Bindplane agent log ingestion)。
- 服务账号名称:输入账号的名称(例如
- 点击创建并继续。
- 在向此服务账号授予对项目的访问权限部分,点击选择角色,然后选择 Chronicle Editor。
- 点击继续,然后点击完成。
- 点击您创建的服务账号,然后前往密钥标签页。
- 依次点击添加密钥 > 创建新密钥。
- 选择 JSON,然后点击创建。密钥文件会下载到您的计算机上。
- 将密钥文件另存为 Bindplane 收集器目录(Linux 上的
/opt/observiq-otel-collector/ingestion-auth.json或 Windows 上的C:\Program Files\observIQ OpenTelemetry Collector\ingestion-auth.json)中的ingestion-auth.json,或更新config.yaml中的creds_file_path以匹配您保存该文件的路径。 - 前往 IAM 和管理 > 设置,然后复制项目编号。您需要此信息才能配置导出器。
方法 2:下载数据注入身份验证文件(旧版)
- 登录 Google SecOps 控制台。
- 前往 SIEM 设置> 收集代理。
- 下载数据注入身份验证文件。
- 将文件安全地保存在将安装 Bindplane 代理的系统上。
获取 Google SecOps 客户 ID
- 登录 Google SecOps 控制台。
- 依次前往 SIEM 设置 > 配置文件。
从组织详细信息部分复制并保存客户 ID。
安装 Bindplane 代理
根据以下说明,在 Windows 或 Linux 操作系统上安装 Bindplane 代理。
Windows 安装
- 以管理员身份打开命令提示符或 PowerShell。
运行以下命令:
msiexec /i "https://github.com/observIQ/bindplane-agent/releases/latest/download/observiq-otel-collector.msi" /quiet等待安装完成。
运行以下命令,验证安装是否成功:
sc query observiq-otel-collector该服务应显示为正在运行。
Linux 安装
- 打开具有 root 或 sudo 权限的终端。
运行以下命令:
sudo sh -c "$(curl -fsSlL https://github.com/observiq/bindplane-agent/releases/latest/download/install_unix.sh)" install_unix.sh等待安装完成。
运行以下命令,验证安装是否成功:
sudo systemctl status observiq-otel-collector该服务应显示为 active (running)。
其他安装资源
如需了解其他安装选项和问题排查,请参阅 Bindplane 代理安装指南。
配置 Bindplane 代理以注入 syslog 并发送到 Google SecOps
找到配置文件
Linux:
sudo nano /opt/observiq-otel-collector/config.yamlWindows:
notepad "C:\Program Files\observIQ OpenTelemetry Collector\config.yaml"
修改配置文件
将
config.yaml的全部内容替换为以下配置:receivers: udplog: listen_address: "0.0.0.0:514" exporters: chronicle/apache: protocol: https # Region of your instance, for example us, europe, asia-southeast1 location: <LOCATION> # Project number of the Google Cloud project linked to the instance project: '<PROJECT_NUMBER>' compression: gzip creds_file_path: '/opt/observiq-otel-collector/ingestion-auth.json' customer_id: '<customer_id>' endpoint: chronicle.googleapis.com log_type: APACHE raw_log_field: body service: pipelines: logs/apache_to_chronicle: receivers: - udplog exporters: - chronicle/apache
配置参数
替换以下占位符:
接收器配置:
listen_address:要监听的 IP 地址和端口:0.0.0.0在所有接口上监听(推荐)- 端口
514是标准 syslog 端口(在 Linux 上需要 root 权限;对于非 root 用户,请使用1514)
导出器配置:
creds_file_path:服务账号 JSON 密钥文件的完整路径(选项 1):- Linux:
/opt/observiq-otel-collector/ingestion-auth.json - Windows:
C:\Program Files\observIQ OpenTelemetry Collector\ingestion-auth.json
- Linux:
customer_id:从 Google SecOps 控制台复制的客户 IDlocation:将<LOCATION>替换为 Google SecOps 实例所在的区域(例如us、europe或asia-southeast1)。导出工具会在此值前面加上chronicle.googleapis.com。如需查看完整列表,请参阅区域级端点。project:将<PROJECT_NUMBER>替换为 IAM 和管理 > 设置中的项目编号。endpoint:保持设置为chronicle.googleapis.com。
旧版提取 API 导出工具
如果您使用选项 2 中的数据注入身份验证文件,请将
exporters代码块替换为以下内容。将creds_file_path设置为提取身份验证文件的路径,如果您的实例位于美国境外,请将malachiteingestion-pa.googleapis.com替换为您的区域端点(例如europe-malachiteingestion-pa.googleapis.com)。exporters: chronicle/apache: compression: gzip creds_file_path: '/opt/observiq-otel-collector/ingestion-auth.json' customer_id: '<customer_id>' endpoint: malachiteingestion-pa.googleapis.com log_type: APACHE raw_log_field: body
保存配置文件
- 修改后,保存文件:
- Linux:依次按
Ctrl+O、Enter和Ctrl+X - Windows:依次点击文件 > 保存
- Linux:依次按
重启 Bindplane 代理以应用更改
如需在 Linux 中重启 Bindplane 代理,请运行以下命令:
sudo systemctl restart observiq-otel-collector验证服务是否正在运行:
sudo systemctl status observiq-otel-collector检查日志中是否存在错误:
sudo journalctl -u observiq-otel-collector -f
如需在 Windows 中重启 Bindplane 代理,请选择以下选项之一:
以管理员身份运行命令提示符或 PowerShell:
net stop observiq-otel-collector && net start observiq-otel-collector“服务”控制台:
- 按
Win+R,输入services.msc,然后按 Enter 键。 - 找到 observIQ OpenTelemetry 收集器。
- 右键点击并选择重启。
验证服务是否正在运行:
sc query observiq-otel-collector检查日志中是否存在错误:
type "C:\Program Files\observIQ OpenTelemetry Collector\log\collector.log"
- 按
在 Apache 中配置 syslog
- 使用 SSH 登录托管 Apache 的服务器。
在
/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_IP>:<BINDPLANE_PORT> module(load="imfile" PollingInterval="10" statefile.directory="/var/spool/rsyslog") input(type="imfile" File="/var/log/apache2/error.log" Tag="http_error" Severity="error" Facility="local7") Local7.error @<BINDPLANE_IP>:<BINDPLANE_PORT>- 将
<BINDPLANE_IP>和<BINDPLANE_PORT>替换为为 Bindplane 代理配置的 IP 地址和端口。 - 如果您使用的是 TCP 协议,请在主机行中额外附加
@(例如@@<BINDPLANE_IP>:<BINDPLANE_PORT>)。
- 将
重启 rsyslog 服务:
sudo service rsyslog restart
UDM 映射表
| 日志字段 | UDM 映射 | 逻辑 |
|---|---|---|
bytes |
network.received_bytes |
从客户端接收的字节数。 |
bytes |
network.sent_bytes |
发送到客户端的字节数。 |
bytes_out |
network.sent_bytes |
发送到客户端的字节数。 |
bytes_received |
network.received_bytes |
从客户端接收的字节数。 |
Content |
network.http.method |
从“内容”字段中提取的 HTTP 方法。 |
Content |
target.url |
从“内容”字段中提取的目标网址。 |
cookie |
additional.fields.value.string_value |
“cookie”字段的值。 |
dest_ip |
target.ip |
目标的 IP 地址。 |
dest_name |
target.hostname |
目标的 hostname。 |
dest_port |
target.port |
目标的端口。 |
description |
metadata.description |
事件的说明。 |
duration_microseconds |
additional.fields.value.string_value |
“duration_microseconds”字段的值。 |
file_full_path |
target.file.full_path |
目标文件的完整路径。 |
hostname |
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.csURL |
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 |
安全结果的类别详情。 |
method |
network.http.method |
HTTP 方法。 |
pid |
principal.process.pid |
主体的进程 ID。 |
Port |
target.port |
目标的端口。 |
proto |
network.application_protocol |
应用协议。 |
referer |
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 |
目标的资源类型。 |
response |
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 版本协议。 |
status |
network.http.response_code |
HTTP 响应代码。 |
target |
target.url |
目标网址。 |
target_ip |
target.ip |
目标的 IP 地址。 |
target_port |
target.port |
目标端口。 |
time |
metadata.event_timestamp |
事件时间戳。 |
uri_path |
target.process.file.full_path |
目标文件的完整路径。 |
user |
principal.user.userid |
主账号的用户 ID。 |
useragent |
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”。如果仅存在 principal,则事件类型会设置为“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”。 | |
client_ip_address |
event.idm.read_only_udm.principal.ip和event.idm.read_only_udm.principal.asset.ip之间 |
从更新日志映射 |
server |
event.idm.read_only_udm.target.hostname和event.idm.read_only_udm.target.asset.hostname之间 |
从更新日志映射 |
bytes_in |
event.idm.read_only_udm.network.received_bytes |
从更新日志映射 |
PHPSESSID |
event.idm.read_only_udm.additional.fields |
从更新日志映射 |
AuthToken |
event.idm.read_only_udm.additional.fields |
从更新日志映射 |
response_time_microseconds |
event.idm.read_only_udm.additional.fields |
从更新日志映射 |
hostname |
event.idm.read_only_udm.intermediary.hostname |
从更新日志映射 |
Filename |
event.idm.read_only_udm.principal.process.file.full_path |
从更新日志映射 |
kv_key |
event.idm.read_only_udm.additional.fields |
从更新日志映射 |
info |
event.idm.read_only_udm.additional.fields |
从更新日志映射 |
SourceModuleName |
event.idm.read_only_udm.additional.fields |
从更新日志映射 |
SourceModuleType |
event.idm.read_only_udm.additional.fields |
从更新日志映射 |
src_ip |
event.idm.read_only_udm.target.ip和event.idm.read_only_udm.target.asset.ip之间 |
从更新日志映射 |
tls_version |
event.idm.read_only_udm.network.tls.version |
从更新日志映射 |
version_protocol |
event.idm.read_only_udm.network.tls.version_protocol |
从更新日志映射 |
syncAccuracy |
event.idm.read_only_udm.security_result.detection_fields |
从更新日志映射 |
isSynced |
event.idm.read_only_udm.security_result.detection_fields |
从更新日志映射 |
tzKnown |
event.idm.read_only_udm.additional.fields |
从更新日志映射 |
user_location |
principal.location.country_or_region |
从更新日志映射 |
proto", "proto_version", "uri_path", and "uri_query |
additional.fields |
从更新日志映射 |
ip_msg |
principal.ip |
从更新日志映射 |
msg_method |
network.http.method |
从更新日志映射 |
useragentvalue |
network.http.user_agent |
从更新日志映射 |
bytes_out |
network.sent.bytes |
从更新日志映射 |
XForwardedForIP" and "RemoteHost |
principal.ip |
从更新日志映射 |
Remoteuser |
principal.user.userid |
从更新日志映射 |
更新日志
需要更多帮助?获得社区成员和 Google SecOps 专业人士的解答。