| name | eradicating-malware-from-infected-systems |
| description | 系统性地清除受感染系统中的恶意软件、后门和攻击者持久化机制,确保彻底根除并防止再次感染。 |
| domain | cybersecurity |
| subdomain | incident-response |
| tags | ["incident-response","eradication","malware-removal","persistence","dfir"] |
| version | 1.0 |
| author | mahipal |
| license | Apache-2.0 |
从受感染系统中根除恶意软件(Eradicating Malware from Infected Systems)
适用场景
- 已确认恶意软件感染且遏制措施已到位
- 取证调查已识别所有持久化机制
- 所有受攻陷系统已识别并确定范围
- 准备好清除攻击者产物并恢复干净状态
- 遏制后阶段需要进行系统性清理
前置条件
- 已完成取证分析,识别所有恶意软件产物
- 所有受攻陷系统和账号的清单
- 部署了具有最新签名的 EDR/AV
- 针对特定恶意软件家族的 YARA 规则
- 用于恢复的干净系统镜像或已验证的备份
- 根除期间网络隔离仍然有效
工作流程
步骤 1:映射所有持久化机制
autorunsc.exe -accepteula -a * -c -h -s -v > autoruns_report.csv
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /s
reg query "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /s
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /s
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run" /s
schtasks /query /fo CSV /v > schtasks_all.csv
Get-WMIObject -Namespace root\Subscription -Class __EventFilter
Get-WMIObject -Namespace root\Subscription -Class CommandLineEventConsumer
Get-WMIObject -Namespace root\Subscription -Class __FilterToConsumerBinding
Get-Service | Where-Object {$_.Status -eq 'Running'} | Select-Object Name, DisplayName, BinaryPathName
cat /etc/crontab
ls -la /etc/cron.*/
ls -la /etc/init.d/
systemctl list-unit-files --type=service | grep enabled
cat /etc/rc.local
ls -la ~/.bashrc ~/.profile ~/.bash_profile
步骤 2:识别所有恶意软件产物
yara -r -s malware_rules/specific_family.yar C:\ 2>/dev/null
clamscan -r --infected --remove=no /mnt/infected_disk/
find / -type f -newer /tmp/baseline_timestamp -exec sha256sum {} \; 2>/dev/null | \
while read hash file; do
grep -q "$hash" known_malicious_hashes.txt && echo "MALICIOUS: $file ($hash)"
done
find /var/www/ -name "*.php" -newer /tmp/baseline -exec grep -l "eval\|base64_decode\|system\|passthru\|shell_exec" {} \;
find / -name "authorized_keys" -exec cat {} \; 2>/dev/null
步骤 3:清除恶意软件文件和产物
Remove-Item -Path "C:\Windows\Temp\malware.exe" -Force
Remove-Item -Path "C:\Users\Public\backdoor.dll" -Force
schtasks /delete /tn "MaliciousTaskName" /f
Get-WMIObject -Namespace root\Subscription -Class __EventFilter -Filter "Name='MalFilter'" | Remove-WMIObject
Get-WMIObject -Namespace root\Subscription -Class CommandLineEventConsumer -Filter "Name='MalConsumer'" | Remove-WMIObject
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "MalEntry" /f
sc stop "MalService" && sc delete "MalService"
crontab -r
rm -f /tmp/.hidden_backdoor
sed -i '/malicious_key/d' ~/.ssh/authorized_keys
systemctl disable malicious-service && rm /etc/systemd/system/malicious-service.service
步骤 4:重置受攻陷凭据
Import-Module ActiveDirectory
Get-ADUser -Filter * -SearchBase "OU=CompromisedUsers,DC=domain,DC=com" |
Set-ADAccountPassword -Reset -NewPassword (ConvertTo-SecureString "TempP@ss!$(Get-Random)" -AsPlainText -Force)
Reset-KrbtgtPassword -DomainController DC01
Reset-KrbtgtPassword -DomainController DC01
Get-ADServiceAccount -Filter * | ForEach-Object {
Reset-ADServiceAccountPassword -Identity $_.Name
}
Get-AzureADUser -All $true | ForEach-Object {
Revoke-AzureADUserAllRefreshToken -ObjectId $_.ObjectId
}
步骤 5:修补初始访问利用的漏洞
Install-WindowsUpdate -KBArticleID "KB5001234" -AcceptAll -AutoReboot
apt update && apt upgrade -y
yum update -y
Get-HotFix -Id "KB5001234"
步骤 6:验证根除效果
curl -X POST "https://api.crowdstrike.com/scanner/entities/scans/v1" \
-H "Authorization: Bearer $FALCON_TOKEN" \
-H "Content-Type: application/json" \
-d '{"ids": ["device_id"]}'
autorunsc.exe -accepteula -a * -c -h -s -v | findstr /i "unknown verified"
Get-Process | Where-Object {$_.Path -notlike "C:\Windows\*" -and $_.Path -notlike "C:\Program Files*"}
Get-NetTCPConnection -State Established |
Where-Object {$_.RemoteAddress -notlike "10.*" -and $_.RemoteAddress -notlike "172.16.*"} |
Select-Object LocalPort, RemoteAddress, RemotePort, OwningProcess
yara -r malware_rules/specific_family.yar C:\ 2>/dev/null
核心概念
| 概念 | 说明 |
|---|
| 持久化机制(Persistence Mechanism) | 攻击者用于在系统重启后维持访问的方法 |
| 根因修复(Root Cause Remediation) | 修复使初始攻陷成为可能的漏洞 |
| 凭据轮换(Credential Rotation) | 重置所有可能受攻陷的密码和令牌 |
| KRBTGT 重置 | 在黄金票据(Golden Ticket)攻击后使 Kerberos 票据失效 |
| 指标扫描(Indicator Sweep) | 在所有系统上扫描已知的恶意产物 |
| 验证扫描(Validation Scan) | 在恢复前确认根除成功 |
| 重镜像(Re-imaging) | 从干净镜像重建系统而非进行清理 |
工具与系统
| 工具 | 用途 |
|---|
| Sysinternals Autoruns | 枚举所有 Windows 自启动位置 |
| YARA | 基于自定义规则的恶意软件扫描 |
| CrowdStrike/SentinelOne | 基于 EDR 的扫描和修复 |
| ClamAV | 开源防病毒扫描 |
| PowerShell | 脚本化清理与验证 |
| Velociraptor | 远程取证采集和修复 |
常见场景
- 具有多重持久化的 RAT:使用注册表、计划任务和 WMI 订阅的远程访问木马。必须清除所有三种持久化机制。
- IIS/Apache 上的 Web Shell:Web 根目录中的 PHP/ASPX Web Shell。删除 Shell、审计所有 Web 文件、修补应用漏洞。
- Rootkit 感染:存活于清理操作的内核级 Rootkit。需要从已知良好的介质完全重镜像。
- 无文件恶意软件(Fileless Malware):基于 PowerShell 的攻击,驻留于内存和注册表。删除注册表项、清除 WMI 订阅、重启系统。
- Active Directory 攻陷:攻击者创建了后门账号和黄金票据。重置 KRBTGT、删除流氓账号、审计组成员关系。
输出格式
- 带时间戳的根除操作日志(所有已删除产物)
- 凭据轮换确认报告
- 漏洞补丁验证
- 根除后验证扫描结果
- 已清理并可进入恢复阶段的系统清单