Remove persistence through scheduled tasks and WMI objects
Knowing how to remove persistence via scheduled tasks and WMI objects is essential after an attacker has entered a Windows environment. Scheduled tasks and WMI event subscriptions let malware survive reboots and logons, then relaunch under an operating-system service. Removing the active malware without removing those launch points leaves the attacker an execution path back into the host.
The two mechanisms serve different purposes. A scheduled task stores an action, trigger, principal and security context in Task Scheduler. WMI persistence normally links an event filter to an executable consumer through a binding. Attackers abuse both to run PowerShell, scripts or binaries, often using encoded commands, living-off-the-land tools and accounts that appear legitimate.
Treat cleanup as incident response rather than routine administration. Disable or isolate the host first, preserve volatile and disk evidence, identify the associated identity and entry route, and establish why each artefact is malicious before deleting it. An over-broad cleanup can interrupt management agents or remove evidence needed to scope the breach.
Australian context adds practical constraints. The ASD Essential Eight and ACSC guidance provide a common baseline for hardening, patching and logging, while many Australian organisations depend on managed service providers to administer those controls. In a shared MSP environment, persistence may sit in a customer tenant under a partner’s automation, making remediation a matter of technical and contractual coordination.
Understand the persistence mechanisms
A scheduled task is not inherently malicious. Product updaters, backup software, inventory scanners and endpoint agents routinely use it. Suspicion rises when ownership is unknown, an interpreter runs from a temporary or user-writable path, arguments are encoded, the task is hidden, or it runs with the highest privileges. Compare its action and account with change records and software deployment baselines.
A WMI event subscription forms a three-part chain. An __EventFilter defines when something happens, an __EventConsumer defines what runs, and a __FilterToConsumerBinding connects them. A typical malicious chain watches process-start or instance-creation events before launching a command-line or script consumer. This allows the payload to remain dormant until a process or object meets its query.
Defenders should map the trigger, payload, principal, persistence location and creation source. Deleting one component may leave an orphaned filter that can later be bound, while deleting the wrong consumer may damage legitimate management software. Containment, evidence capture and eradication should therefore be treated as separate decisions.
Establish a controlled response
Begin by containing the affected endpoint without destroying evidence. Where business and safety permit, leave it powered for memory collection, then isolate it from production networks while retaining administrator access through a known-clean path. Capture running processes, network connections, logged-on sessions, Security, Sysmon, Task Scheduler and WMI-Activity logs, and create a forensic image or volume snapshot. Record every action in UTC.
Use a clean administrative workstation and an account the adversary is unlikely to control. Rotate exposed service-account credentials only after capturing volatile data, because an immediate reset can terminate an active session and remove useful context. Search identity-provider, VPN, EDR, DNS, proxy and Microsoft 365 telemetry for the same account, command line, task name, WMI namespace and destination.
Australian teams should also confirm who controls the machine. Many mid-market organisations buy security operations, patching or tenant administration from local MSPs, leaving persistence in a customer tenant but under a partner’s automation. Record timestamps in UTC and convert them to AEST or AEDT for Sydney and Melbourne and AEST for Brisbane; a promise to “sort it before arvo” is not an auditable handover.
Investigate scheduled tasks
Begin with full enumeration, including hidden tasks and tasks outside default folders. Useful views include schtasks /query /fo LIST /v, Get-ScheduledTask and Get-ScheduledTaskInfo. For suspicious entries, use Export-ScheduledTask to obtain the XML. Review the task path, description, principal, run level, triggers, repetition settings, executable, arguments, working directory and last-run result. The XML often reveals details absent from the console.
Check the task files under C:\Windows\System32\Tasks, relevant TaskCache registry data, Security events 4698 and 4702 when auditing is enabled, and the Microsoft-Windows-TaskScheduler/Operational log. Process-creation telemetry can reveal the interpreter or payload launched by the task. Encoded PowerShell, rundll32, mshta, wmic, remote downloaders and execution from %TEMP%, ProgramData, Downloads or a user profile warrant urgent review, although context still matters.
Record the task XML, owner, creation and last-run times, account, referenced payload hashes and any child-process output before changing its state. Compare creation timestamps with initial access, lateral movement and endpoint alerts. A task named like a familiar updater may still be hostile if it points to a temporary script; naming alone is no proof of legitimacy.
Investigate WMI persistence
WMI persistence usually lives in the root\subscription namespace, although objects can be created elsewhere. Query __EventFilter, __EventConsumer and __FilterToConsumerBinding with Get-CimInstance -Namespace root/subscription -ClassName .... Examine the filter’s WQL query, consumer type, executable path, command-line template, script text, working directory and binding references. Relevant consumer classes include CommandLineEventConsumer and ActiveScriptEventConsumer.
A suspicious filter may watch Win32_ProcessStartTrace, __InstanceCreationEvent, __InstanceModificationEvent or __InstanceDeletionEvent and act on a broad process, user or file condition. Broad triggers can look normal, so inspect what the consumer executes rather than relying on the filter alone. Review Microsoft-Windows-WMI-Activity/Operational events, especially permanent-consumer activity, and correlate them with process and network telemetry from the same timestamp.
The WMI repository under C:\Windows\System32\wbem\Repository is a forensic treasure, but it is not a file to edit casually. Repository objects may be malformed, and manual deletion can leave provider state inconsistent. If a clean baseline shows corruption, treat recovery or reset as a separate restoration project with application owners involved, rather than the first response to one suspicious subscription.
Remove confirmed malicious artifacts
Before removal, export the task XML and capture the exact WMI objects, their properties and references. For a confirmed malicious scheduled task, disable it to stop execution, then remove it through the supported interface: Disable-ScheduledTask, followed by Unregister-ScheduledTask with the precise task name and path. Use schtasks /delete only with the exact task identifier. Do not hand-delete TaskCache entries or Microsoft task folders.
Remove WMI chains in dependency order: remove the specific binding, then the malicious consumer, then the unused filter. Select exact instances rather than piping every object of a class into Remove-CimInstance, and verify that no legitimate filter still references the consumer. Capture the original MOF or equivalent export first, because some hostile consumers can survive simplistic cleanup.
Account for re-creation before declaring success. Malware running as SYSTEM, a domain administrator or an MSP automation account can immediately rebuild what was deleted. Hunt for related scheduled tasks, services, registry run keys, startup items, WMI filters in other namespaces, hijacked DLL search paths and the original persistence script. If repository corruption is confirmed, winmgmt /resetrepository is a disruptive last resort requiring dependency re-registration and a clean restoration plan.
Validate eradication and reduce recurrence
Rerun the task and WMI inventories from a trusted console, then monitor the affected endpoint for task-creation, WMI, process and outbound-network events. Check that the account and payload paths remain absent and that no service reinstalls them. Preserve before-and-after results in the incident record with host identifiers, query outputs and hashes. A quiet ten-minute window is not proof when persistence may trigger monthly.
Removal alone does not close the intrusion path. Review how the attacker obtained administrative rights, exposed service credentials or abused a management channel, then invalidate those secrets and rotate dependent keys. Hunt across identity, endpoint and network telemetry for the same command line, script hash, mutex, IP address or domain. Block confirmed infrastructure at the controls where those indicators can be enforced.
Reduce recurrence with restricted administrative roles, protected management accounts, application control and workload-appropriate PowerShell logging. Audit task creation and changes, alert on unusual WMI permanent subscriptions, and ensure endpoint security cannot be disabled by the same identity used for administration. This aligns with the ASD Essential Eight: privileged access, application control, patching and monitoring provide the durable layer after the current artefacts are gone.
Coordinate close-out and preserve assurance
Coordinate close-out with legal, privacy, insurance and system owners. For personal information, assess the Privacy Act 1988 and the OAIC Notifiable Data Breaches scheme; a notifiable breach generally involves substantial personal information and relevant harm, with notification required as soon as practicable and generally no later than three months after awareness. APRA-regulated entities must consider CPS 230 operational-risk obligations, while NSW Health and Victorian health services may have additional state escalation and clinical-continuity duties. Record which regulator, customer or MSP was informed, when, and why.
The mechanisms differ in visibility and potential impact, so remediation evidence should reflect both:
| Control point | Scheduled tasks | WMI event subscriptions |
|---|---|---|
| Trigger | Logon, startup, schedule or recurring interval | WMI event query involving processes, users, files or objects |
| Core evidence | Exported XML, task file, TaskCache metadata and event logs | Exported CIM objects, filter query, consumer properties and WMI-Activity logs |
| Supported cleanup | Disable, then unregister the exact task | Remove the exact binding, consumer and unused filter |
| Validation | Task remains absent, no recreation event appears and its payload is inactive | No matching objects remain and no new consumer or related execution appears |
| Primary risk | A privileged agent recreates it or removal breaks a legitimate service | An object is orphaned, respawned or protected inside a damaged repository |
Before returning the endpoint to normal service, obtain a signed close-out record listing every removed task and WMI object, supporting evidence, restored dependencies, monitored indicators, residual risk owners and required notifications. The next concrete step is to create a tracked close-out item in the incident system and assign it to the named host owner.