微算力 · API 导航与自营网关
API 接入 EN
未登录登录
🛡️

Linux安全事件响应与取证修复指南

Linux Incident Remediator · v1.0.0
专业技能 安全 A 级 作者 kiaraho 公开目录收录
下载 1.4k 安装 0 收藏 4.2k 浏览 13
原始页面

简介

Linux主机安全事件响应与可控修复框架,支持多发行版、非破坏性取证、防火墙管控与完整性验证,适合安全运维与应急响应场景。

原始描述

Provides forensically-safe Linux threat detection, network and process analysis, integrity verification, controlled firewall and service remediation preservi...

中文使用说明 来自收录源

核心用法

sys-guard-linux-remediator 是一套面向Linux主机的结构化安全事件响应框架,专注于在安全事件期间或之后进行威胁检测、取证分析与系统修复。该技能采用纯文档指导模式,无嵌入可执行代码,完全通过标准化命令参考实现操作指引。

主要操作模块包括:

  1. 网络态势感知:使用ss -tulpn枚举监听服务,tcpdump进行短时抓包,支持iptables/nftables/firewalld多后端防火墙状态检查
  2. 进程与运行时分析:通过ps auxww --forest查看进程树,lsof检查文件句柄,strace谨慎追踪系统调用
  3. 恶意软件检测:集成rkhunter、chkrootkit、ClamAV及Lynis系统审计工具
  4. 文件完整性验证:支持AIDE、RPM-Va、Debsums等包管理器级完整性检查
  5. 取证分析工具:内置Didier Stevens Suite部署指南,支持Base64解码、IOC搜索、ZIP/PDF/Office文档静态分析、Cobalt Strike配置提取
  6. 认证与用户活动审计:涵盖who、last、journalctlSSH失败登录追踪、ausearch审计日志查询
  7. 受控修复操作:提供IP封禁、进程终止(TERM→STOP→KILL分级)、服务隔离(stop/disable/mask)、持久化后门检查等标准流程

技能特别强调分布感知命令使用,针对Debian/Ubuntu、RHEL/CentOS/Rocky/Alma、Fedora、Arch等系统提供差异化日志路径与包管理指令。

显著优点

专业深度与学术背书:作者Edwin Kairu使用CMU(卡内基梅隆大学)学术邮箱,技能内容符合企业级SOC(安全运营中心)事件响应标准,涵盖从初始取证到完整修复的全生命周期。

取证安全性优先设计:所有操作遵循"非破坏性证据收集"原则,强制要求操作前哈希计算、quarantine隔离、UTC时间戳记录,确保事件链可审计、可重现。

完备的安全防护机制:内置7大强制性安全护栏(Safety Guardrails),包括状态验证前后比对、禁止通配符删除/批量终止、持久化机制检查、防火墙防锁出保护、变更日志记录等,大幅降低误操作风险。

多防火墙架构兼容:独特支持iptables-legacy、iptables-nft、原生nftables、firewalld共存环境,避免单一后端假设导致的规则遗漏。

SELinux与systemd原生支持:针对RHEL系提供SELinux审计日志查询,完整覆盖systemd服务、定时器、用户级单元的持久化检查。

潜在缺点与局限性

外部工具依赖未固定版本:Didier Stevens Suite通过wget从GitHub raw链接直接下载,未指定commit hash,上游更新可能导致工具行为变化,影响取证结果可重复性(RISK-001)。

纯文档模式无自动化:作为Markdown指导型技能,所有命令需人工复制执行,在高压事件响应场景下效率低于自动化剧本(如Ansible、Sigma规则)。

容器环境受限明确:文档明确声明不支持Docker/Kubernetes/LXC等容器环境,防火墙与审计命令无法反映宿主机状态,适用范围受限。

T3来源可信度:虽作者使用学术邮箱,但属个人开发者项目,无GitHub开源仓库,缺乏社区持续审查机制,未达到T1/T2组织级可信度。

许可证未指定:当前未声明开源许可证,用户权利边界模糊。

适合的目标群体

  • 企业安全运维工程师:需标准化Linux事件响应 playbook 的中小型企业SOC团队
  • 安全审计与合规人员:执行定期主机安全审计、基线核查的从业者
  • 红队/渗透测试后修复:攻防演练后的系统加固与后门清理
  • 高校网络安全实验室:CMU背景适合作为教学参考材料
  • 独立安全顾问:为客户提供可复现的Linux取证报告模板

使用风险

风险类别 具体描述 缓解建议
权限相关 大量命令需root/sudo,误操作可能导致系统不可用 遵循最小权限,先在测试环境验证
防火墙锁出 错误的DROP规则可能阻断SSH管理通道 强制先验证SSH端口与规则,禁用iptables -F
取证污染 strace等工具改变进程时序,大型扫描修改访问时间戳 严格按文档"Minimal-Impact Principle"执行
外部供应链 Didier Stevens Suite直接下载,存在供应链投毒理论风险 下载后验证SHA256,或内部镜像部署
误报处理 rkhunter等工具可能产生误报,导致过度修复 强制要求人工验证后再执行删除/隔离
持久化遗漏 未彻底检查systemd timer、user-level单元等隐蔽持久化 严格遵循"Persistence & Re-Spawn Inspection"清单

总体而言,该技能在Linux事件响应领域具备专业深度,适合作为人工响应的标准操作参考,但需注意外部依赖版本固定与权限管控。

技能正文


name: sys-guard-linux-remediator description: Host-based Linux incident response and remediation skill focused on precise threat detection, forensic-safe data collection, firewall control (iptables/nftables), integrity validation, and controlled remediation while preserving system stability. metadata: author: Edwin Kairu (ekairu@cmu.edu)

Linux Threat Mitigation and Incident Remediation (Hardened Edition)

This skill provides a structured, forensically-aware framework for analyzing and securing a Linux host during or after a security event.

It emphasizes:

  • Non-destructive evidence collection
  • Accurate threat detection
  • Firewall-aware containment
  • Integrity verification
  • Controlled, reversible remediation
  • Distribution-aware command usage

Environment Context

Supported Systems

  • Debian / Ubuntu
  • RHEL / CentOS / Rocky / Alma
  • Fedora
  • Arch Linux (limited package guidance)

Execution Assumptions

  • Shell: bash or POSIX sh
  • Privilege: Root or sudo
  • Host-level access (NOT container-restricted environments)
  • systemd-based systems preferred

⚠️ If running inside Docker, Kubernetes, LXC, or other containers, firewall, audit, and service commands may not reflect the host system.


Firewall Architecture Awareness

Modern Linux systems may use:

  • iptables-legacy
  • iptables-nft (compatibility wrapper)
  • Native nftables
  • firewalld (RHEL-family default)

Identify Firewall Backend

iptables --version
which nft
systemctl status firewalld

If nftables is active:

nft list ruleset

Do NOT assume iptables -L represents the full firewall state.


Logging Differences by Distribution

Distribution Primary Log File
Ubuntu/Debian /var/log/syslog
RHEL/CentOS/Fedora /var/log/messages
All modern systemd journalctl

Always prefer:

journalctl -xe

Operational Toolkit (Hardened)

1. Network Inspection

Listening Services

ss -tulpn

Active Connections

ss -antp | grep ESTABLISHED

Firewall State

iptables

iptables -L -n -v --line-numbers
iptables -S

nftables

nft list ruleset

Local Service Enumeration (Low Noise)

ss -lntup

Avoid unnecessary full scans of localhost unless required.

Conservative Network Scan

nmap -sV -T3 -p- localhost

Packet Capture (Short Snapshot)

tcpdump -i any -nn -c 100

2. Process & Runtime Analysis

Process Tree

ps auxww --forest

High CPU / Memory

top

Open File Handles

lsof -p <PID>

System Call Trace (Caution: Alters Timing)

strace -p <PID>

⚠️ strace may change process behavior. Use carefully during live compromise.

Kernel Modules

lsmod

Kernel Messages

dmesg | tail -50

3. Rootkit & Malware Scanning

Rootkit Scanners

rkhunter --check
chkrootkit

May produce false positives. Validate findings manually.

Antivirus Scan (Targeted)

clamscan -r /home

Use selectively; large scans increase I/O and may alter access timestamps.

Lynis System Audit

lynis audit system

4. File Integrity & Package Verification

AIDE (After Initialization)

Install:

apt install aide
# or
dnf install aide

Initialize:

aideinit
mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz

Run Check:

aide --check

RHEL Package Verification

rpm -Va

Debian Package Verification

apt install debsums
debsums -s

5. Forensic Analysis (Didier Stevens Suite)

Install:

sudo mkdir -p /opt/forensics
sudo wget -P /opt/forensics https://raw.githubusercontent.com/DidierStevens/DidierStevensSuite/master/base64dump.py
sudo wget -P /opt/forensics https://raw.githubusercontent.com/DidierStevens/DidierStevensSuite/master/re-search.py
sudo wget -P /opt/forensics https://raw.githubusercontent.com/DidierStevens/DidierStevensSuite/master/zipdump.py
sudo wget -P /opt/forensics https://raw.githubusercontent.com/DidierStevens/DidierStevensSuite/master/1768.py
sudo wget -P /opt/forensics https://raw.githubusercontent.com/DidierStevens/DidierStevensSuite/master/pdf-parser.py
sudo wget -P /opt/forensics https://raw.githubusercontent.com/DidierStevens/DidierStevensSuite/master/oledump.py
sudo chmod +x /opt/forensics/*.py

Decode Base64

python3 /opt/forensics/base64dump.py file.txt

IOC Search

python3 /opt/forensics/re-search.py -n ipv4 logfile

Inspect ZIP (No Extraction)

python3 /opt/forensics/zipdump.py suspicious.zip

Extract Cobalt Strike Beacon Config

python3 /opt/forensics/1768.py payload.bin

Inspect Office/PDF Documents

python3 /opt/forensics/pdf-parser.py file.pdf
python3 /opt/forensics/oledump.py file.doc

Static inspection only. Never execute suspicious files.


6. Authentication & User Activity

Current Sessions

who -a

Login History

last -a

Failed SSH Logins

Ubuntu/Debian:

journalctl -u ssh.service | grep "Failed password"

RHEL/Fedora:

journalctl -u sshd.service | grep "Failed password"

Sudo Activity

journalctl _COMM=sudo

Audit Logs

ausearch -m USER_AUTH,USER_LOGIN,USER_CHAUTHTOK

Controlled Remediation

Blocking an IP

iptables (Immediate)

iptables -I INPUT 1 -s <IP> -j DROP

nftables

nft add rule inet filter input ip saddr <IP> drop

If firewalld is active:

firewall-cmd --add-rich-rule='rule family="ipv4" source address="<IP>" drop'

Persisting Firewall Rules

iptables (Debian):

netfilter-persistent save

iptables (manual save):

iptables-save > /etc/iptables/rules.v4

firewalld:

firewall-cmd --runtime-to-permanent

nftables:

nft list ruleset > /etc/nftables.conf

Process Containment Strategy

Preferred escalation:

  1. Observe
  2. kill -TERM <PID>
  3. If required: kill -STOP <PID> for analysis
  4. Use kill -KILL <PID> only if necessary

Avoid killall or broad pkill.


Service Isolation

systemctl stop <service>
systemctl disable <service>
systemctl mask <service>

Persistence & Backdoor Checks

Cron Jobs

crontab -l
ls -lah /etc/cron*

Systemd Persistence

ls -lah /etc/systemd/system/

Startup Scripts

cat /etc/rc.local

SELinux Awareness (RHEL/Fedora)

Check status:

getenforce

Review denials:

ausearch -m AVC

Forensic Hygiene

  1. Never execute suspicious binaries.
  2. Preserve evidence before deletion:
sha256sum file
mkdir -p /root/quarantine
mv file /root/quarantine/file.vir
  1. Log every remediation step:
date -u

Document:

  • Timestamp
  • Command executed
  • Observed outcome

Usage Examples

Routine Audit

  • Run lynis audit system
  • Verify no unknown listening services
  • Check for modified system binaries

Active Threat

  • Identify high CPU process
  • Capture short tcpdump
  • Extract file hash
  • Contain IP via firewall
  • Preserve malicious artifact

Suspicious File

  • Use zipdump
  • Extract hash
  • Move to quarantine
  • Search logs for execution attempts

Safety Guardrails

These guardrails are mandatory and apply to all remediation activity. Their purpose is to prevent self-inflicted outages, preserve forensic integrity, and ensure reversible, controlled incident response.


1. State Verification (Pre- and Post-Change Validation)

Before executing any remediation command:

  1. Record timestamp (UTC):

    date -u
    
  2. Run a discovery command to capture current state:

    • Network: ss -tulpn
    • Active connections: ss -antp
    • Firewall (iptables): iptables -L -n -v
    • Firewall (nftables): nft list ruleset
    • firewalld: firewall-cmd --list-all

After remediation:

  1. Re-run the same discovery command.
  2. Compare state change and confirm:
    • Intended effect achieved
    • No unintended service disruption
    • No management lockout (e.g., SSH access intact)

Never assume a command succeeded without verifying its effect.


2. No Wildcards or Broad Termination

To prevent catastrophic system damage:

  • NEVER use:

    • rm -rf *
    • rm -rf /
    • killall
    • Broad pkill patterns
    • Unbounded globbing in sensitive directories
  • Always:

    • Use absolute file paths (e.g., /tmp/malware.bin)
    • Target explicit PIDs (kill -TERM <PID>)
    • Confirm file existence with ls -lah <file>
    • Hash suspicious files before modification:
      sha256sum <file>
      

Wildcard deletions and pattern-based termination are prohibited during incident response.


3. Persistence & Re-Spawn Inspection

After containment of a malicious process or service, immediately inspect for persistence mechanisms.

Check:

Cron Jobs

crontab -l
ls -lah /etc/cron*

systemd Services & Timers

systemctl list-unit-files --type=service
systemctl list-timers --all
ls -lah /etc/systemd/system/

Init Scripts

ls -lah /etc/init.d/
cat /etc/rc.local

User-Level Persistence

ls -lah ~/.config/systemd/user/

SSH Backdoors

cat ~/.ssh/authorized_keys

After removal of malicious artifacts:

  • Run integrity verification:
    aide --check
    
  • On RHEL-based systems:
    rpm -Va
    
  • On Debian-based systems:
    debsums -s
    

Do not consider a threat eradicated until persistence mechanisms are eliminated.


4. Firewall Rule Safety & Persistence

A. Anti-Lockout Requirement

Before modifying firewall rules:

  1. Confirm SSH listening port:

    ss -tulpn | grep ssh
    
  2. Confirm an explicit ACCEPT rule exists for:

    • Current management IP
    • SSH port

NEVER:

iptables -F

NEVER set a default DROP policy without verifying SSH access rule exists.


B. Immediate vs Persistent Rules

Firewall rule changes are runtime by default and may not survive reboot.

iptables (Debian/Ubuntu)

Runtime only until saved:

iptables-save > /etc/iptables/rules.v4

If using netfilter-persistent:

netfilter-persistent save

RHEL (legacy iptables service)

service iptables save

firewalld

Runtime-to-permanent:

firewall-cmd --runtime-to-permanent

nftables

Persist ruleset:

nft list ruleset > /etc/nftables.conf

Document:

  • Whether rule is temporary or permanent
  • Location of saved configuration
  • Verification after reboot (if applicable)

5. Forensic Preservation Before Destruction

Before deleting or killing:

  1. Hash the artifact:

    sha256sum <file>
    
  2. Move to quarantine:

    mkdir -p /root/quarantine
    mv <file> /root/quarantine/<file>.vir
    
  3. Record:

    • Timestamp (UTC)
    • Original path
    • Hash value
    • Reason for containment

Avoid kill -9 unless absolutely required. Prefer:

  1. kill -TERM <PID>
  2. kill -STOP <PID> (if forensic inspection needed)
  3. kill -KILL <PID> only as last resort

6. Change Logging Requirement

Every remediation action must include:

  • date -u
  • Command executed
  • Justification
  • Observed outcome
  • Updated risk level (if applicable)

Remediation without documentation is non-compliant.


7. Minimal-Impact Principle

All actions must follow:

  • Smallest necessary change
  • Reversible where possible
  • No broad configuration resets
  • No service restarts without justification
  • No system-wide scans during active compromise unless scoped

Contain first. Eradicate methodically. Recover cautiously.

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

incident-responselinux-securityforensicsiptablesnftablesmalware-analysisintegrity-checkingsystem-hardeningrheldebiancobalt-strikerootkit-detection

同类 Skill