Communitygithub.com

分析 Linux 审计日志以检测入侵

使用 Linux Audit 框架(auditd)结合 ausearch 和 aureport 工具,检测主机入侵行为。

分析 Linux 审计日志以检测入侵 是什么?

该技能专注于利用 Linux 审计框架(auditd)检测和调查入侵行为。它指导用户验证审计守护进程状态、部署针对入侵指标的审计规则(例如监控凭据文件、SSH 密钥、进程注入、可疑目录执行、内核模块加载以及网络连接),然后使用 `ausearch` 搜索特定事件(如失败的登录、命令执行、文件访问),并使用 `aureport` 生成摘要报告。技能还提供了重建攻击时间线的方法,包括识别初始访问、跟踪攻击者活动、提取执行命令、检查持久化机制和横向移动。最后,它涵盖了将审计日志转发到 SIEM 系统(通过 audisp-remote 或 Auditbeat)的配置。该技能适用于 Linux 主机上的事件响应、取证分析和合规审计,支持 Ubuntu、Debian、RHEL、CentOS 等发行版,需要 root 或 sudo 权限以及基本的系统调用知识。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/mukul975/Anthropic-Cybersecurity-Skills/tree/main/skills/analyzing-linux-audit-logs-for-intrusion

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

分析 Linux 审计日志以检测入侵 是做什么的?

适用场景

  • 调查 Linux 主机上疑似未授权访问或权限提升的事件
  • 寻找漏洞利用、后门安装或持久化机制的痕迹
  • 针对需要系统调用监控的安全基线(CIS、STIG、PCI-DSS)进行合规审计
  • 在事件响应过程中重建攻击者的行为时间线
  • 检测关键系统文件(如 /etc/passwd、/etc/shadow 或 SSH 密钥)的篡改行为

请勿使用 于网络层入侵检测;网络流量分析请使用 Suricata 或 Zeek。Auditd 工作于单个主机的内核层面。

前置条件

  • 已安装 auditd 软件包且审计守护进程正在运行的 Linux 系统(systemctl status auditd)
  • 具备 root 或 sudo 权限以配置审计规则和查询日志
  • 通过 /etc/audit/rules.d/*.rules 部署的审计规则,或使用 auditctl 加载的规则
  • 推荐:从 GitHub 获取 Neo23x0/auditd 规则集以获得全面的基线覆盖
  • 熟悉 Linux 系统调用(execve、open、connect、ptrace 等)
  • 具有足够保留空间的日志存储(默认位置:/var/log/audit/audit.log)

工作流程

步骤 1:验证审计守护进程状态和配置

确认审计系统正在运行,并检查当前规则集:

# 检查 auditd 服务状态
systemctl status auditd

# 显示内核中当前加载的审计规则
auditctl -l

# 显示审计守护进程配置
cat /etc/audit/auditd.conf | grep -E "log_file|max_log_file|num_logs|space_left_action"

# 检查审计积压是否超限(是否存在丢弃事件)
auditctl -s

如果即将达到积压限制,请增加积压大小:

auditctl -b 8192

步骤 2:部署入侵聚焦的审计规则

添加针对常见入侵指标的规则。将这些规则放入 /etc/audit/rules.d/intrusion.rules:

# 监控凭据文件的未授权读取或修改
-w /etc/passwd -p wa -k credential_access
-w /etc/shadow -p rwa -k credential_access
-w /etc/gshadow -p rwa -k credential_access
-w /etc/sudoers -p wa -k privilege_escalation
-w /etc/sudoers.d/ -p wa -k privilege_escalation

# 监控 SSH 配置和授权密钥
-w /etc/ssh/sshd_config -p wa -k sshd_config_change
-w /root/.ssh/authorized_keys -p wa -k ssh_key_tampering

# 监控用户和组管理命令
-w /usr/sbin/useradd -p x -k user_management
-w /usr/sbin/usermod -p x -k user_management
-w /usr/sbin/groupadd -p x -k user_management

# 检测通过 ptrace 进行的进程注入
-a always,exit -F arch=b64 -S ptrace -F a0=0x4 -k process_injection
-a always,exit -F arch=b64 -S ptrace -F a0=0x5 -k process_injection
-a always,exit -F arch=b64 -S ptrace -F a0=0x6 -k process_injection

# 监控从非常规目录执行的程序
-a always,exit -F arch=b64 -S execve -F exe=/tmp -k exec_from_tmp
-a always,exit -F arch=b64 -S execve -F exe=/dev/shm -k exec_from_shm

# 检测内核模块加载(Rootkit 安装)
-a always,exit -F arch=b64 -S init_module -S finit_module -k kernel_module_load
-a always,exit -F arch=b64 -S delete_module -k kernel_module_remove
-w /sbin/insmod -p x -k kernel_module_tool
-w /sbin/modprobe -p x -k kernel_module_tool

# 监控用于反向 Shell 的网络套接字创建
-a always,exit -F arch=b64 -S socket -F a0=2 -k network_socket_created
-a always,exit -F arch=b64 -S connect -F a0=2 -k network_connection

# 检测 cron 作业修改(持久化)
-w /etc/crontab -p wa -k cron_persistence
-w /etc/cron.d/ -p wa -k cron_persistence
-w /var/spool/cron/ -p wa -k cron_persistence

# 监控日志删除或篡改
-w /var/log/ -p wa -k log_tampering

编辑后重新加载规则:

augenrules --load
auditctl -l | wc -l   # 确认规则数量

步骤 3:使用 ausearch 搜索入侵指标

使用 ausearch 查询审计日志以查找特定事件:

# 搜索过去 24 小时内所有失败的登录尝试
aureport -m USER_LOGIN --success no -ts recent

# 搜索特定用户执行的命令
aureport -ua 1001 -m EXECVE -ts today

# 搜索 /etc/shadow 上的所有文件访问事件
aureport -f /etc/shadow -ts this-week

# 搜索通过 sudo 进行的权限提升
aureport -m USER_CMD -ts today

# 搜索内核模块加载事件
aureport -k kernel_module_load -ts this-month

# 搜索从 /tmp 执行的进程(常见攻击暂存位置)
aureport -k exec_from_tmp -ts this-week

# 搜索 SSH 密钥修改
aureport -k ssh_key_tampering -ts this-month

# 按审计事件 ID 搜索特定事件
aureport -a 12345

# 搜索特定时间范围内的事件
aureport -ts 03/15/2026 08:00:00 -te 03/15/2026 18:00:00

# 解释系统调用编号并以可读格式输出
aureport -k credential_access -i -ts today

步骤 4:使用 aureport 生成摘要报告

使用 aureport 生成聚合摘要以进行分类:

# 所有认证事件摘要
aureport -au -ts this-week --summary

# 所有失败事件报告(登录、访问等)
aureport --failed --summary -ts today

# 可执行文件运行报告
aureport -x --summary -ts today

# 所有异常事件报告(段错误、混杂模式等)
aureport --anomaly -ts this-week

# 文件访问事件报告
aureport -f --summary -ts today

# 按密钥报告所有事件(映射到您的自定义规则密钥)
aureport -k --summary -ts this-month

# 所有系统调用报告
aureport -s --summary -ts today

# 按用户分组的事件报告
aureport -u --summary -ts this-week

# 用于时间线构建的详细时间事件报告
aureport -ts 03/15/2026 08:00:00 -te 03/15/2026 18:00:00 --summary

步骤 5:重建攻击时间线

结合 ausearch 查询,构建一个按时间顺序叙述的事件脉络:

# 步骤 5a:识别初始访问时间戳
aureport -m USER_LOGIN -ua 0 --success yes -ts this-week -i | head -50

# 步骤 5b:追踪攻击者在获得访问权限后所做的事情
# 获取在事件窗口内来自受损账户的所有事件
aureport -ua <UID> -ts "03/15/2026 14:00:00" -te "03/15/2026 18:00:00" -i \
  | aureport -f -i

# 步骤 5c:提取在事件窗口期间执行的所有命令
aureport -m EXECVE -ts "03/15/2026 14:00:00" -te "03/15/2026 18:00:00" -i

# 步骤 5d:检查是否安装了持久化机制
aureport -k cron_persistence -ts "03/15/2026 14:00:00" -i
aureport -k ssh_key_tampering -ts "03/15/2026 14:00:00" -i

# 步骤 5e:检查横向移动(出站连接)
aureport -k network_connection -ts "03/15/2026 14:00:00" -i

步骤 6:将审计日志转发到 SIEM

配置 audisp-remote 或 auditbeat 将日志发送到中央 SIEM 进行关联分析:

# 选项 A:使用 audisp-remote 插件
# 编辑 /etc/audit/plugins.d/au-remote.conf
active = yes
direction = out
path = /sbin/audisp-remote
type = always

# 在 /etc/audit/audisp-remote.conf 中配置远程目标
remote_server = siem.internal.corp
port = 6514
transport = tcp

# 选项 B:使用 Elastic Auditbeat
# 安装 auditbeat 并配置 /etc/auditbeat/auditbeat.yml
# Auditbeat 直接从内核审计框架读取

关键概念

术语定义
auditdLinux 审计守护进程,从内核接收审计事件并将其写入 /var/log/audit/audit.log
auditctl控制审计系统的命令行工具:添加/删除规则、检查状态、设置积压大小
ausearch查询工具,可按消息类型、用户、文件、密钥、时间范围或事件 ID 搜索审计日志
aureport报告工具,生成审计事件的聚合摘要,用于分类和合规
审计规则密钥 (-k)用户定义的标签,附加到审计规则上,可使用 ausearch 和 aureport 快速过滤相关事件
系统调用审计内核级别的系统调用监控(execve、open、connect、ptrace),捕获进程和文件活动
augenrules将 /etc/audit/rules.d/ 中的所有文件合并到 /etc/audit/audit.rules 并加载到内核中的工具

验证

  • auditd 正在运行且规则已加载(auditctl -l 返回预期的规则数量)
  • 没有审计积压溢出(auditctl -s 显示 backlog: 0 或低值,lost: 0)
  • ausearch 为每个自定义密钥返回事件(ausearch -k <key> -ts today 返回结果)
  • aureport 为认证、可执行文件和文件事件生成非空摘要
  • 时间线重建产生连贯的、按时间顺序的攻击者行为序列
  • 对测试修改,关键文件监控会触发警报(touch /etc/shadow 生成事件)
  • 日志正在转发到中央 SIEM(通过测试事件验证并确认接收)
  • 审计规则在重启后持久化(规则位于 /etc/audit/rules.d/,而不仅仅通过 auditctl)

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

abusing-dpapi-for-credential-access

Extract and decrypt Windows DPAPI-protected secrets (Credential Manager, browser logins/cookies, Wi-Fi credentials, KeePass keys) online or offline using SharpDPAPI, SharpChrome, Mimikatz, or Impacket

abusing-shadow-credentials-for-privesc

Take over Active Directory accounts by writing attacker-controlled public keys to msDS-KeyCredentialLink (Shadow Credentials) with pyWhisker, Whisker, or Certipy, then authenticate via PKINIT to recover the target

achieving-cmmc-level-2-compliance

>-

acquiring-disk-image-with-dd-and-dcfldd

Create forensically sound bit-for-bit disk images with dd or dcfldd on a Linux forensic workstation, preserving evidence integrity through hash verification (MD5/SHA) during acquisition. Use when imaging a suspect drive, USB device, or memory card for investigation, preserving volatile disk evidence during incident response, or producing a verified copy for legal or law-enforcement proceedings before any destructive analysis.

analyzing-active-directory-acl-abuse

Detect dangerous ACL misconfigurations in Active Directory using ldap3

analyzing-android-malware-with-apktool

Perform static analysis of Android APK malware using apktool for resource decompilation, jadx for Java source recovery, and androguard for manifest inspection, dangerous permission-combination detection, and identification of obfuscated code, dynamic code loading, and reflection-based API calls. Use to statically triage a suspicious APK without executing it or to build mobile malware detection rules.

analyzing-api-gateway-access-logs

Parses API Gateway access logs (AWS API Gateway, Kong, Nginx) to detect

analyzing-apt-group-with-mitre-navigator

Query ATT&CK data with attackcti, mitreattack-python, and stix2, then build MITRE ATT&CK Navigator layers and multi-layer heatmap overlays mapping one or more APT groups

analyzing-azure-activity-logs-for-threats

Queries Azure Monitor activity logs and sign-in logs via azure-monitor-query

analyzing-bootkit-and-rootkit-samples

Analyzes bootkit and advanced rootkit malware infecting the Master

analyzing-browser-forensics-with-hindsight

Parse Chromium-based browser databases with Hindsight to extract and correlate browsing history, downloads, cookies, cached content, autofill data, saved passwords, and extensions from Chrome, Edge, Brave, Opera, and Vivaldi into a unified timeline (XLSX, JSON, or SQLite output). Use during incident response, insider-threat investigations, or criminal cases when you need to reconstruct a user

analyzing-campaign-attribution-evidence

Systematically evaluate cyber-campaign evidence to attribute an operation to a threat actor, using the Diamond Model and Analysis of Competing Hypotheses (ACH) to weigh infrastructure overlaps, TTP consistency, malware code similarity, and timing/language artifacts into confidence-weighted attribution assessments. Use when an incident investigation needs a defensible attribution confidence level.

analyzing-certificate-transparency-for-phishing

Monitor Certificate Transparency logs using crt.sh and Certstream to

analyzing-cloud-storage-access-patterns

Detect abnormal access in AWS S3, GCS, and Azure Blob Storage by analyzing CloudTrail Data Events, GCS audit logs, and Azure Storage Analytics for after-hours bulk downloads, new-IP access, and API-call spikes (e.g. GetObject) via statistical baselines and time-series anomaly detection. Use when investigating suspected cloud data exfiltration or building related detection rules.

analyzing-cobalt-strike-beacon-configuration

Extract and analyze Cobalt Strike beacon configuration from PE files

analyzing-cobaltstrike-malleable-c2-profiles

Parse and analyze Cobalt Strike Malleable C2 profiles with dissect.cobaltstrike (profiles and beacon-payload configs) and pyMalleableC2 (AST parsing) to extract HTTP/DNS transforms, URIs, headers, sleep/jitter, and injection behavior, then generate network detection signatures. Use when reverse-engineering a captured malleable profile or building detections against Cobalt Strike Beacon traffic.

analyzing-command-and-control-communication

Analyzes malware C2 communication over HTTP, HTTPS, DNS, and custom

analyzing-cyber-kill-chain

Analyzes intrusion activity against the Lockheed Martin Cyber Kill Chain

analyzing-disk-image-with-autopsy

Perform comprehensive forensic analysis of raw (dd), E01, or AFF disk images with Autopsy and The Sleuth Kit, recovering deleted files, examining metadata and embedded artifacts, keyword searching, and building investigation timelines with visual reports. Use for structured analysis of a forensic disk image or when stakeholders need visual reports from evidence.

analyzing-dns-logs-for-exfiltration

Analyzes DNS query logs to detect data exfiltration via DNS tunneling,

相关技能