欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > 服务器等保测评审计日志功能开启(auditd)和时间校准

服务器等保测评审计日志功能开启(auditd)和时间校准

2025/2/22 16:27:31 来源:https://blog.csdn.net/weixin_43258559/article/details/144912397  浏览:    关键词:服务器等保测评审计日志功能开启(auditd)和时间校准

操作系统审计日志功能开启auditd

CentOS 7 默认已经安装 auditd,如果没有,可以通过以下命令安装:

yum install audit
systemctl start auditd
systemctl enable auditd

配置审计规则

配置审计规则。添加所需的审计规则

  • 永久规则文件:/etc/audit/audit.rules 或 /etc/audit/rules.d/audit.rules
  • 临时规则:可以通过命令行动态添加规则,但重启后会失效。

监控 /etc/passwd 文件的所有访问

auditctl -w /etc/passwd -p rwxa -k passwd_watch
  • -w:指定监控的文件路径。
  • -p:定义操作类型:r 读,w 写,x 执行,a 属性更改。
  • -k:为规则设置一个标识符(方便查询)。

监控某个系统调用

auditctl -a always,exit -F arch=b64 -S chmod -k chmod_watch
  • -a always,exit:指定何时捕获事件。
  • -F arch=b64:指定体系架构(64 位系统用 b64)。
  • -S chmod:指定要监控的系统调用。
  • -k:规则标识符。

查看当前的审计规则

auditctl -l

重新加载审计规则使其生效

auditctl -R /etc/audit/audit.rules

查看审计日志

审计日志默认存储在 /var/log/audit/audit.log 文件中。使用以下命令查看日志:

ausearch -f /etc/passwd  # 按文件过滤
ausearch -k passwd_watch  # 按规则标识符过滤
ausearch -sc chmod  # 按系统调用过滤

将 audit.log 转换为更易读的格式

aureport -f  # 查看文件相关事件
aureport -u  # 查看用户相关事件
aureport -i  # 生成可读性较高的报告

配置审计策略

可以通过 /etc/audit/auditd.conf 配置 auditd 的行为。例如:

log_file = /var/log/audit/audit.log  # 指定日志文件位置
log_format = RAW  # 日志格式(RAW 或 ENRICHED)
max_log_file = 8  # 最大日志文件大小(MB)
num_logs = 5  # 保留的日志文件数量

重启生效

systemctl restart auditd

重启auditd报错
在这里插入图片描述
打开该文件检查是否存在以下配置

vim /usr/lib/systemd/system/auditd.service

这会阻止手动停止或重启服务。

RefuseManualStop=yes

调整配置

RefuseManualStop=no

重新加载 systemd 配置

systemctl daemon-reload

重启服务

systemctl restart auditd
  • 安全考虑: 不建议长期禁用 RefuseManualStop,因为这可能会削弱系统的审计能力。
  • 保持配置同步: 如果系统启用了 SELinux,确保 /etc/audit/auditd.conf 和 auditd 的规则配置正确无误。

监控用户登录

监控所有用户登录事件

auditctl -a always,exit -F arch=b64 -S execve -F key=login_events

使用 ausearch 查询相关日志

ausearch -k login_events

规则永久生效

备份规则文件

cp /etc/audit/rules.d/audit.rules /etc/audit/rules.d/audit.rules.bak

查看所有当前有效的规则

auditctl -l

在这里插入图片描述

将动态添加的规则(auditctl 命令的内容)写入到该文件中。

vim /etc/audit/rules.d/audit.rules
-w /etc/passwd -p rwxa -k passwd_watch
-a always,exit -F arch=b64 -S chmod -k chmod_watch

在这里插入图片描述

  • 文件中规则的格式与 auditctl 命令相同。
  • 每个规则应占一行,确保语法正确。

重启 auditd 服务

systemctl restart auditd

验证规则是否生效

auditctl -l

在这里插入图片描述

立即加载新的规则文件,而无需重启 auditd 服务

augenrules --load

查看某用户的审计日志

ausearch -ua $(id -u root)

在这里插入图片描述

生成审计报告

aureport -au

在这里插入图片描述

日志记录类型

  • 时间:以 audit(时间戳) 开头,精确到毫秒。
  • 用户:通过 uid 和 auid 字段标识。
  • 事件类型:通过 type= 字段标识,如 USER_AUTH。
  • 结果:通过 res= 字段标识成功或失败。

操作系统时间校准截图

Windows 和Linux 服务器时间校准

https://cloud.tencent.com/document/product/213/30393
https://cloud.tencent.com/document/product/213/30394

系统时间可以通过以下命令查看:

timedatectl status

关键字段:

  • Local time:本地时间。
  • Universal time:UTC 时间。
  • RTC time:硬件时钟时间。
  • NTP synchronized:是否启用了 NTP 时间同步(yes 表示已同步)。
  • Network time on:网络时间是否启用

在这里插入图片描述

启用 NTP 时间同步

安装 NTP 服务

yum install ntp
systemctl enable chronyd
systemctl start chronyd

检查同步状态

timedatectl

手动校准时间

如果系统时间不准确,可以手动设置时间或使用 NTP 进行同步。
手动设置时间

timedatectl set-time "2025-01-06 16:30:00"

确认设置

timedatectl

使用 NTP 同步时间:

手动强制同步时间:

ntpdate pool.ntp.org

验证时间准确性

对比网络时间: 通过以下命令与 NTP 服务器对比时间

ntpdate -q pool.ntp.org
server 162.159.200.1, stratum 3, offset -0.002664, delay 0.20970
server 162.159.200.123, stratum 3, offset 0.002552, delay 0.19284
server 78.46.102.180, stratum 2, offset 0.033635, delay 0.30667
server 193.182.111.142, stratum 2, offset -0.004059, delay 0.291606 Jan 14:35:12 ntpdate[6868]: adjust time server 193.182.111.142 offset -0.004059 sec

offset 表示本地时间与服务器时间的偏差,单位是秒。如果 offset 很小(如 0.001),说明时间准确。

检查同步状态: 查看 NTP 服务的状态:

chronyc tracking

在这里插入图片描述

操作系统重要配置备份策略截图

云服务器通常有备份,服务器内可不用备份

操作系统杀毒软件使用版本截图以及恶意代码特征库更新记录截图

云上有主机安全 或者云安全中心
腾讯云专业版与基础版:https://cloud.tencent.com/document/product/296/2222

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词