performing-malware-persistence-investigation
系统性地调查 Windows 和 Linux 系统上的所有持久化机制,以识别恶意软件如何在重启后存活并维持访问。
Best use case
performing-malware-persistence-investigation is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
系统性地调查 Windows 和 Linux 系统上的所有持久化机制,以识别恶意软件如何在重启后存活并维持访问。
Teams using performing-malware-persistence-investigation should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/performing-malware-persistence-investigation/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How performing-malware-persistence-investigation Compares
| Feature / Agent | performing-malware-persistence-investigation | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
系统性地调查 Windows 和 Linux 系统上的所有持久化机制,以识别恶意软件如何在重启后存活并维持访问。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 执行恶意软件持久化调查
## 适用场景
- 调查恶意软件如何在系统重启后维持存在时
- 事件响应期间识别所有持久化机制以进行完整修复时
- 威胁狩猎以发现端点上未授权的自启动条目时
- 分析恶意软件行为以了解其持久化策略时
- 验证事件修复后所有持久化是否已被清除时
## 前置条件
- 取证镜像或具有管理员权限的活动系统访问
- Autoruns(Sysinternals)用于 Windows 持久化枚举
- RegRipper 用于离线注册表分析
- 了解 Windows 和 Linux 持久化机制
- YARA 规则用于扫描持久化位置
- 已知良好自启动条目的基线用于比较
## 工作流程
### 步骤 1:枚举 Windows 注册表持久化
```bash
# 从取证镜像中提取注册表 hive
mount -o ro,loop,offset=$((2048*512)) /cases/case-2024-001/images/evidence.dd /mnt/evidence
# 关键注册表持久化位置
python3 << 'PYEOF'
from Registry import Registry
import json
results = {'registry_persistence': []}
# SYSTEM hive 分析
system_reg = Registry.Registry("/cases/case-2024-001/registry/SYSTEM")
select = system_reg.open("Select")
current = select.value("Current").value()
cs = f"ControlSet{current:03d}"
# 服务(非常常见的持久化方式)
services = system_reg.open(f"{cs}\\Services")
for svc in services.subkeys():
try:
start_type = svc.value("Start").value()
image_path = ""
try:
image_path = svc.value("ImagePath").value()
except:
pass
# 启动类型:0=Boot, 1=System, 2=Auto, 3=Manual, 4=Disabled
if start_type in (0, 1, 2) and image_path:
svc_type = svc.value("Type").value() if svc.values() else 0
results['registry_persistence'].append({
'location': f'HKLM\\SYSTEM\\{cs}\\Services\\{svc.name()}',
'type': '服务',
'value': image_path,
'start_type': start_type,
'timestamp': str(svc.timestamp())
})
except Exception:
pass
# SOFTWARE hive 分析
sw_reg = Registry.Registry("/cases/case-2024-001/registry/SOFTWARE")
# 机器 Run 键
run_keys = [
"Microsoft\\Windows\\CurrentVersion\\Run",
"Microsoft\\Windows\\CurrentVersion\\RunOnce",
"Microsoft\\Windows\\CurrentVersion\\RunServices",
"Microsoft\\Windows\\CurrentVersion\\RunServicesOnce",
"Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\Run",
"Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run",
"Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce",
]
for key_path in run_keys:
try:
key = sw_reg.open(key_path)
for value in key.values():
results['registry_persistence'].append({
'location': f'HKLM\\SOFTWARE\\{key_path}',
'type': 'Run Key',
'name': value.name(),
'value': str(value.value()),
'timestamp': str(key.timestamp())
})
except Exception:
pass
# NTUSER.DAT 分析
import glob
for ntuser in glob.glob("/cases/case-2024-001/registry/NTUSER*.DAT"):
try:
user_reg = Registry.Registry(ntuser)
user_run_keys = [
"Software\\Microsoft\\Windows\\CurrentVersion\\Run",
"Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce",
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Startup",
]
for key_path in user_run_keys:
try:
key = user_reg.open(key_path)
for value in key.values():
results['registry_persistence'].append({
'location': f'HKCU\\{key_path}',
'type': '用户 Run Key',
'name': value.name(),
'value': str(value.value()),
'timestamp': str(key.timestamp()),
'hive': ntuser
})
except Exception:
pass
except Exception:
pass
print(f"注册表持久化条目总数:{len(results['registry_persistence'])}")
for entry in results['registry_persistence']:
print(f" [{entry['type']}] {entry.get('name', '')} -> {entry.get('value', '')[:100]}")
with open('/cases/case-2024-001/analysis/registry_persistence.json', 'w') as f:
json.dump(results, f, indent=2)
PYEOF
```
### 步骤 2:检查计划任务和 WMI 持久化
```bash
# 从取证镜像中提取计划任务
mkdir -p /cases/case-2024-001/persistence/tasks/
cp -r /mnt/evidence/Windows/System32/Tasks/* /cases/case-2024-001/persistence/tasks/ 2>/dev/null
# 解析计划任务 XML 文件
python3 << 'PYEOF'
import os, xml.etree.ElementTree as ET
tasks_dir = '/cases/case-2024-001/persistence/tasks/'
suspicious_tasks = []
for root_dir, dirs, files in os.walk(tasks_dir):
for fname in files:
fpath = os.path.join(root_dir, fname)
try:
tree = ET.parse(fpath)
root = tree.getroot()
ns = {'t': 'http://schemas.microsoft.com/windows/2004/02/mit/task'}
actions = root.findall('.//t:Exec', ns)
for action in actions:
command = action.find('t:Command', ns)
args = action.find('t:Arguments', ns)
cmd_text = command.text if command is not None else ''
args_text = args.text if args is not None else ''
# 标记可疑命令
suspicious_indicators = [
'powershell', 'cmd.exe', 'wscript', 'cscript', 'mshta',
'regsvr32', 'rundll32', 'certutil', 'bitsadmin',
'/c ', '-enc', '-e ', 'hidden', 'bypass', 'downloadstring',
'invoke-', 'iex', '/tmp/', 'appdata', 'programdata',
'temp\\', '.ps1', '.vbs', '.hta', 'base64'
]
is_suspicious = any(s in (cmd_text + ' ' + args_text).lower() for s in suspicious_indicators)
task_info = {
'name': fname,
'path': fpath.replace(tasks_dir, ''),
'command': cmd_text,
'arguments': args_text,
'suspicious': is_suspicious
}
if is_suspicious:
suspicious_tasks.append(task_info)
print(f"可疑任务:{fname}")
print(f" 命令:{cmd_text}")
print(f" 参数:{args_text}")
print()
except Exception as e:
pass
print(f"\n可疑计划任务总数:{len(suspicious_tasks)}")
PYEOF
# 检查 WMI 事件订阅(常见的 APT 持久化方式)
# WMI 库:C:\Windows\System32\wbem\Repository\
cp -r /mnt/evidence/Windows/System32/wbem/Repository/ /cases/case-2024-001/persistence/wmi/ 2>/dev/null
# 使用 PyWMIPersistenceFinder 解析 WMI 持久化
python3 << 'PYEOF'
import os, re
# 在 WMI OBJECTS.DATA 中搜索事件订阅
wmi_db = '/cases/case-2024-001/persistence/wmi/OBJECTS.DATA'
if os.path.exists(wmi_db):
with open(wmi_db, 'rb') as f:
data = f.read()
# 搜索 EventFilter 字符串
filters = re.findall(b'__EventFilter.*?(?=\x00\x00)', data)
consumers = re.findall(b'CommandLineEventConsumer.*?(?=\x00\x00)', data)
bindings = re.findall(b'__FilterToConsumerBinding.*?(?=\x00\x00)', data)
print("=== WMI 持久化 ===")
print(f"事件过滤器:{len(filters)}")
print(f"命令消费者:{len(consumers)}")
print(f"过滤器-消费者绑定:{len(bindings)}")
for consumer in consumers:
decoded = consumer.decode('utf-8', errors='ignore')
print(f" 消费者:{decoded[:200]}")
else:
print("WMI 库未找到")
PYEOF
```
### 步骤 3:检查文件系统和引导持久化
```bash
# 启动文件夹
echo "=== 启动文件夹内容 ===" > /cases/case-2024-001/analysis/startup_items.txt
ls -la "/mnt/evidence/ProgramData/Microsoft/Windows/Start Menu/Programs/Startup/" \
>> /cases/case-2024-001/analysis/startup_items.txt 2>/dev/null
for userdir in /mnt/evidence/Users/*/; do
username=$(basename "$userdir")
echo "--- 用户:$username ---" >> /cases/case-2024-001/analysis/startup_items.txt
ls -la "$userdir/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup/" \
>> /cases/case-2024-001/analysis/startup_items.txt 2>/dev/null
done
# 检查 DLL 搜索顺序劫持位置
echo "=== DLL 劫持检查 ===" > /cases/case-2024-001/analysis/dll_hijack.txt
# 检查应用程序目录中只应存在于 System32 的 DLL
find /mnt/evidence/Program\ Files/ /mnt/evidence/Program\ Files\ \(x86\)/ \
-name "*.dll" -newer /mnt/evidence/Windows/System32/ntdll.dll 2>/dev/null \
>> /cases/case-2024-001/analysis/dll_hijack.txt
# 检查 COM 对象劫持
python3 << 'PYEOF'
from Registry import Registry
reg = Registry.Registry("/cases/case-2024-001/registry/SOFTWARE")
# 检查可疑的 CLSID 条目
try:
clsid = reg.open("Classes\\CLSID")
for key in clsid.subkeys():
try:
server = key.subkey("InprocServer32")
dll_path = server.value("(default)").value()
if any(s in dll_path.lower() for s in ['temp', 'appdata', 'programdata', 'downloads', 'tmp']):
print(f"可疑 COM:{key.name()} -> {dll_path}")
except:
pass
except:
pass
PYEOF
# 检查引导配置是否存在 bootkit
# BCD(启动配置数据)
ls -la /mnt/evidence/Boot/BCD 2>/dev/null
# 检查 bootmgr 或 winload.exe 是否被修改
sha256sum /mnt/evidence/Windows/System32/winload.exe 2>/dev/null
```
### 步骤 4:检查 Linux 持久化机制
```bash
# 如果分析 Linux 系统
LINUX_ROOT="/mnt/evidence"
echo "=== Linux 持久化检查 ===" > /cases/case-2024-001/analysis/linux_persistence.txt
# Cron 任务
echo "--- Cron 任务 ---" >> /cases/case-2024-001/analysis/linux_persistence.txt
cat $LINUX_ROOT/etc/crontab >> /cases/case-2024-001/analysis/linux_persistence.txt 2>/dev/null
ls -la $LINUX_ROOT/etc/cron.d/ >> /cases/case-2024-001/analysis/linux_persistence.txt 2>/dev/null
cat $LINUX_ROOT/etc/cron.d/* >> /cases/case-2024-001/analysis/linux_persistence.txt 2>/dev/null
cat $LINUX_ROOT/var/spool/cron/crontabs/* >> /cases/case-2024-001/analysis/linux_persistence.txt 2>/dev/null
# Systemd 服务
echo "--- 自定义 Systemd 服务 ---" >> /cases/case-2024-001/analysis/linux_persistence.txt
find $LINUX_ROOT/etc/systemd/system/ -name "*.service" -not -type l \
>> /cases/case-2024-001/analysis/linux_persistence.txt 2>/dev/null
# SSH 授权密钥
echo "--- SSH 授权密钥 ---" >> /cases/case-2024-001/analysis/linux_persistence.txt
find $LINUX_ROOT/home/ $LINUX_ROOT/root/ -name "authorized_keys" -exec cat {} \; \
>> /cases/case-2024-001/analysis/linux_persistence.txt 2>/dev/null
# Init 脚本和 rc.local
echo "--- RC 脚本 ---" >> /cases/case-2024-001/analysis/linux_persistence.txt
cat $LINUX_ROOT/etc/rc.local >> /cases/case-2024-001/analysis/linux_persistence.txt 2>/dev/null
# Shell profile 脚本
echo "--- Profile 脚本 ---" >> /cases/case-2024-001/analysis/linux_persistence.txt
cat $LINUX_ROOT/etc/profile.d/*.sh >> /cases/case-2024-001/analysis/linux_persistence.txt 2>/dev/null
# LD_PRELOAD
echo "--- LD_PRELOAD ---" >> /cases/case-2024-001/analysis/linux_persistence.txt
cat $LINUX_ROOT/etc/ld.so.preload >> /cases/case-2024-001/analysis/linux_persistence.txt 2>/dev/null
grep -r "LD_PRELOAD" $LINUX_ROOT/etc/ >> /cases/case-2024-001/analysis/linux_persistence.txt 2>/dev/null
# 内核模块
echo "--- 已加载的内核模块 ---" >> /cases/case-2024-001/analysis/linux_persistence.txt
cat $LINUX_ROOT/etc/modules-load.d/*.conf >> /cases/case-2024-001/analysis/linux_persistence.txt 2>/dev/null
# PAM 后门
echo "--- PAM 配置 ---" >> /cases/case-2024-001/analysis/linux_persistence.txt
find $LINUX_ROOT/etc/pam.d/ -exec grep -l "pam_exec\|pam_script" {} \; \
>> /cases/case-2024-001/analysis/linux_persistence.txt 2>/dev/null
```
### 步骤 5:编制持久化报告
```bash
# 生成全面的持久化报告
python3 << 'PYEOF'
import json
with open('/cases/case-2024-001/analysis/registry_persistence.json') as f:
reg_data = json.load(f)
report = """
恶意软件持久化调查报告
==========================================
发现的持久化机制:
1. 注册表 RUN 键:
"""
run_keys = [e for e in reg_data['registry_persistence'] if 'Run' in e.get('type', '')]
for entry in run_keys:
report += f" [{entry['timestamp']}] {entry.get('name', 'N/A')} -> {entry.get('value', '')[:100]}\n"
services = [e for e in reg_data['registry_persistence'] if e.get('type') == '服务']
report += f"\n2. 服务({len(services)} 个自启动服务):\n"
for entry in services[:20]:
report += f" {entry['location'].split(chr(92))[-1]}:{entry['value'][:100]}\n"
report += """
3. 计划任务:[见计划任务分析]
4. WMI 订阅:[见 WMI 分析]
5. 启动文件夹:[见 startup_items.txt]
6. COM 劫持:[见 COM 分析]
需要调查的可疑条目:
"""
# 标记可疑条目
for entry in reg_data['registry_persistence']:
value = str(entry.get('value', '')).lower()
suspicious_indicators = ['powershell', 'cmd /c', 'wscript', 'certutil',
'programdata', 'appdata\\local\\temp', 'base64',
'.ps1', '.vbs', '.hta', '/tmp/', 'hidden']
if any(s in value for s in suspicious_indicators):
report += f" 可疑:{entry.get('name', 'N/A')} -> {entry.get('value', '')[:100]}\n"
with open('/cases/case-2024-001/analysis/persistence_report.txt', 'w') as f:
f.write(report)
print(report)
PYEOF
```
## 关键概念
| 概念 | 描述 |
|------|------|
| Run 键(Run keys) | 在用户登录时执行程序的注册表键(HKLM 和 HKCU) |
| 计划任务(Scheduled tasks) | 在触发器(时间、事件、登录)上执行的 Windows 任务计划条目 |
| WMI 事件订阅 | 触发操作的持久性 WMI 查询(隐蔽持久化) |
| COM 劫持(COM hijacking) | 重定向 COM 对象加载以执行恶意 DLL |
| DLL 搜索顺序劫持 | 在 System32 之前被搜索的目录中放置恶意 DLL |
| 服务持久化(Service persistence) | 安装随系统自动启动的 Windows 服务 |
| 引导级持久化(Boot-level persistence) | 修改引导配置或 MBR/VBR 以在操作系统前执行 |
| 离地攻击(Living-off-the-land) | 使用合法系统工具(PowerShell、WMI、certutil)进行持久化 |
## 工具与系统
| 工具 | 用途 |
|------|------|
| Autoruns | Sysinternals 全面的自启动枚举工具 |
| RegRipper | 自动化注册表持久化制品提取 |
| KAPE | 自动化持久化制品收集和分析 |
| Velociraptor | 具有持久化狩猎制品的端点 Agent |
| OSQuery | 基于 SQL 的系统查询,用于持久化枚举 |
| PersistenceSniper | 用于 Windows 持久化检测的 PowerShell 工具 |
| RECmd | Eric Zimmerman 的注册表命令行分析工具 |
| Volatility | 用于内存中持久化的内存取证工具 |
## 常见场景
**场景 1:初始入侵后的 APT 持久化**
检查所有注册表 Run 键,枚举包含编码 PowerShell 命令的计划任务,检查 WMI 事件订阅中的事件触发执行,检查 COM 对象注册是否存在被劫持的 CLSID,审查最近安装的具有可疑映像路径的服务。
**场景 2:加密前的勒索软件持久化**
识别勒索软件如何维持访问以进行重新加密或监控,检查会重新启动加密的计划任务,检查勒索软件操作者安装的服务,在宣告修复完成前验证不存在额外的后门持久化。
**场景 3:无文件恶意软件持久化**
重点关注将有效载荷存储在注册表值中的持久化,检查从事件触发器执行 PowerShell 的 WMI 订阅,检查使用编码命令参数的计划任务,检查加载远程内容的基于 mshta/rundll32 的持久化。
**场景 4:修复后验证**
运行 Autoruns 与已知良好基线的比对,验证所有已识别的持久化机制已被删除,检查可能被遗漏的额外持久化,确认服务、任务和注册表条目已清理,监控再次感染指标。
## 输出格式
```
持久化调查摘要:
系统:DESKTOP-ABC123(Windows 10 Pro)
分析日期:2024-01-20
发现的持久化机制:
注册表 Run 键(HKLM):5 条(1 条可疑)
注册表 Run 键(HKCU):3 条(1 条可疑)
服务(自启动): 142 条(2 条可疑)
计划任务: 67 条(3 条可疑)
WMI 订阅: 1 条(可疑)
启动文件夹: 4 项(1 项可疑)
COM 对象: 0 条被劫持条目
DLL 劫持: 0 条检测到
可疑条目:
1. HKCU\Run\WindowsUpdate -> powershell -ep bypass -e <base64>
时间戳:2024-01-15 14:35:00
操作:编码的 PowerShell 下载执行
2. 服务:WinDefenderUpdate -> C:\ProgramData\svc\update.exe
时间戳:2024-01-15 14:40:00
操作:ProgramData 中的未知可执行文件
3. 任务:\Microsoft\Windows\Maintenance\SecurityUpdate
命令:cmd.exe /c powershell -w hidden -e <base64>
触发:系统启动时
4. WMI:__EventFilter "ProcessStart" -> CommandLineEventConsumer
操作:WMI 事件触发时执行 C:\Windows\Temp\svc.exe
需要修复:4 个持久化机制待删除
报告:/cases/case-2024-001/analysis/persistence_report.txt
```Related Skills
reverse-engineering-rust-malware
使用 IDA Pro 和 Ghidra 对 Rust 编译的恶意软件进行逆向工程,掌握处理非空终止字符串、提取 crate 依赖项和 Rust 特有控制流分析的专项技术。
reverse-engineering-malware-with-ghidra
使用 NSA 的 Ghidra 反汇编器和反编译器对恶意软件二进制文件进行逆向工程,在汇编和伪 C 代码层面理解其内部逻辑、密码学例程、C2 协议和规避技术。适用于恶意软件逆向工程、反汇编分析、反编译、二进制分析或理解恶意软件内部机制等请求。
reverse-engineering-dotnet-malware-with-dnspy
使用 dnSpy 反编译器和调试器对 .NET 恶意软件进行逆向工程,分析 C#/VB.NET 源代码,识别混淆技术,提取配置信息,理解包括信息窃取器、远程访问木马(RAT)和加载器在内的恶意功能。适用于 .NET 恶意软件分析、C# 恶意软件反编译、托管代码逆向工程或 .NET 混淆分析等请求。
reverse-engineering-android-malware-with-jadx
使用 JADX 反编译器对恶意 Android APK 文件进行逆向工程,分析 Java/Kotlin 源代码,识别包括数据窃取、C2 通信、权限提升和覆盖攻击在内的恶意功能。检查 Manifest 权限、Receiver、Service 及原生库。适用于 Android 恶意软件分析、APK 逆向工程、移动端恶意软件调查或 Android 威胁分析等请求。
performing-yara-rule-development-for-detection
通过识别可执行文件中的唯一字节模式、字符串和行为指标,开发精准的 YARA 恶意软件检测规则,同时将误报率降至最低。
performing-wireless-security-assessment-with-kismet
使用 Kismet 通过被动射频监控进行无线网络安全评估,检测流氓接入点(Rogue AP)、隐藏 SSID、弱加密和未授权客户端。
performing-wireless-network-penetration-test
执行无线网络渗透测试,通过捕获握手包、破解 WPA2/WPA3 密钥、检测流氓接入点以及使用 Aircrack-ng 和相关工具测试无线网络分段,评估 WiFi 安全性。
performing-windows-artifact-analysis-with-eric-zimmerman-tools
使用 Eric Zimmerman 的开源 EZ Tools 套件(包括 KAPE、MFTECmd、PECmd、LECmd、JLECmd 和 Timeline Explorer)执行全面的 Windows 取证制品分析,解析注册表 hive、预取文件、事件日志和文件系统元数据。
performing-wifi-password-cracking-with-aircrack
在授权无线安全评估中捕获 WPA/WPA2 握手包,并使用 aircrack-ng、hashcat 和字典攻击进行离线密码破解, 以评估密码短语强度和无线网络安全状况。
performing-web-cache-poisoning-attack
在授权安全测试期间,通过未纳入缓存键的头部和参数毒化缓存响应,利用 Web 缓存机制向其他用户投递恶意内容。
performing-web-cache-deception-attack
通过利用 CDN 缓存层与源服务器之间的路径规范化差异,执行 Web 缓存欺骗攻击,从而缓存并获取敏感的已认证内容。
performing-web-application-vulnerability-triage
使用 OWASP 风险评级方法论对 DAST/SAST 扫描器的 Web 应用程序漏洞发现进行分类,区分真阳性和假阳性,并确定修复优先级。