Blog10 min read
BITS Persistence: SetNotifyCmdLine and Retry Delays
How BITS jobs give persistence (ATT&CK T1197): notify command lines, retry delays, owner logons, the 90-day limit, and what bitsadmin, PowerShell and COM leave behind.
TL;DR. A BITS job can carry a notify command line: a program that BITS starts, with CreateProcessAsUser and as the user who set it, when the job reaches the transferred or error state. If the program neither completes nor cancels the job and exits with a non-zero code, BITS starts it again after the job's minimum retry delay. The job lives in the BITS queue, survives reboots and runs while its owner is logged on, until it is completed, cancelled, or left without activity for 90 days by default. bitsadmin leaves process, Prefetch and event log traces; PowerShell leaves its own logs; a program calling the COM interface leaves little more than event 3 and the job itself. The notify program starts as a child of the BITS svchost.exe. BITS Parser shows every job's notify command line and flags it.
The mechanism, step by step
Microsoft's SetNotifyCmdLine page and the job life cycle give the rules:
- Create a job. It starts suspended.
- Add a file: a remote name over HTTP, HTTPS or SMB, and a local name.
- Set the notify command line: a program, with its full path, and a parameter string whose first parameter must be the program. The program is limited to
MAX_PATHcharacters and the parameters to 4,000. The search path is not used and environment variables are not expanded. - Optionally set the notify flags (transferred and error by default), the minimum retry delay and the no-progress timeout.
- Resume the job.
- When the job enters the transferred or error state, BITS calls
CreateProcessAsUserto start the program in the context of the user who set it. It does so even if the command was set after the job reached that state. - If the program returns a non-zero exit code and has not completed or cancelled the job, BITS calls it again after the minimum retry delay. BITS 1.5 and earlier called it only once.
If the job also has a COM callback registered, the command line only runs when the callback fails.
Why attackers use it: in Mandiant's words, the command data lives in a database rather than the registry, so tools that list persistence locations, and investigators, can overlook it. ATT&CK T1197 lists Persistence, Execution and Stealth among its tactics.
Two ways to reach the trigger
The transfer fails. A URL that cannot be reached puts the job in the transient error state. BITS retries after each minimum retry delay until the no-progress timeout expires, 14 days by default, then moves the job to error, and the command runs. Two settings shorten this, per Microsoft: a minimum retry delay longer than the no-progress timeout sends the job to error without retrying, and a no-progress timeout of zero does the same for any error. Mandiant's example and its KEGTAP case both point the job at 127.0.0.1.
The transfer succeeds. The job reaches the transferred state and the command runs. If nobody completes the job, it stays in the queue and the downloaded data stays in the BIT*.tmp file, since only Complete renames it.
In both cases, the minimum retry delay sets how often BITS starts the program again while it keeps returning a non-zero code. A long delay means fewer launches and less noise.
The settings that matter
| Setting | bitsadmin | PowerShell | Default | Why it matters |
|---|---|---|---|---|
| Notify command | /setnotifycmdline <job> <program> [parameters] | -NotifyCmdLine (recent versions) | None | What runs |
| Notify flags | /setnotifyflags | -NotifyFlags | 1 and 2: transferred, error | Which states start it |
| Minimum retry delay | /setminretrydelay | -RetryInterval | 600 seconds | How often it runs again; above the no-progress timeout, the job goes straight to error |
| No-progress timeout | /setnoprogresstimeout | -RetryTimeout | 1,209,600 seconds (14 days) | When retries end in error; zero means at once |
| Inactivity timeout | Group Policy JobInactivityTimeout | 90 days | When BITS cancels the job; progress or property changes reset the timer |
Two details: the API accepts a retry delay down to 5 seconds, while -RetryInterval accepts 60 at least, per the Start-BitsTransfer page. And the -NotifyCmdLine and -NotifyFlags parameters appear in the Windows Server 2022 and 2025 versions of that documentation, and of Set-BitsTransfer, but not in the 2016 and 2019 versions.
How these values are stored in the job record is in the qmgr.db format.
Conditions and limits
- The owner must be logged on. Microsoft states that BITS transfers files only when the job owner is logged on, through the Welcome screen, a Remote Desktop session, fast user switching or, since Windows 10 1607, Remote PowerShell. Running a program with RunAs does not count. BITS stops working on a user's jobs at logoff and resumes them at the next logon, so a job owned by a user wakes up with that user's sessions.
- Service accounts. Microsoft also states that no command-line callback runs for jobs in a service account context: LocalSystem, LocalService or NetworkService. Yet Dor Azouri's BITSInject, presented at DEF CON 25 in 2017, injected a LocalSystem job into the queue file and ran its command line as SYSTEM, with administrator rights, on Windows 7 and 10. Whether Microsoft changed the behaviour since, or the check applies only to jobs made through the API, is not public. Read a notify command on a SYSTEM-owned job instead of dismissing it.
- Taking ownership removes the command. Microsoft's page says that
TakeOwnershipremoves command-line notification from the job. An administrator who takes a job over to inspect it destroys the evidence in the live queue. - Ninety days, renewable. BITS cancels a job after 90 days without activity, and activity resets the timer. Whether a relaunch of the notify program counts as activity is not documented. Secureworks found two such jobs still pending in May 2016 on a host infected in early March (republished by Sophos).
With bitsadmin
Mandiant's example of the persistence pattern:
bitsadmin /create persistence
bitsadmin /addfile persistence http://127.0.0.1/invalid.exe c:\windows\i.exe
bitsadmin /SetNotifyCmdLine persistence c:\windows\malware.exe NULL
bitsadmin /resume persistence
NULL stands for no parameters. With parameters, Microsoft's setnotifycmdline page requires the first one to match the program name, so the stored parameters usually repeat the program path. A one-off download uses bitsadmin /transfer instead, which completes the job when the files arrive and cancels it on a critical error, so nothing stays in the queue.
What it leaves:
- One
bitsadmin.exeprocess per command, in Security 4688 when command-line auditing is on, or Sysmon 1, with the job name, URL and notify command in clear. - Prefetch for
BITSADMIN.EXE, with its run count and last run times. - Event 3 with
bitsadmin.exeas the creating process on recent builds. - The job itself, with every setting.
Nardella's SANS paper and Mertens's ISC diary describe bitsadmin as deprecated in favour of the PowerShell cmdlets. It still ships with Windows, and its use on a modern workstation stands out.
With PowerShell
Start-BitsTransfer is synchronous by default: it returns when the transfer is complete or in error, and the job does not stay in the queue. Its documentation notes one exception: if the BITS service stops during a synchronous transfer, the job is not removed. -Asynchronous or -Suspended keep the job, and Set-BitsTransfer changes it later. Defaults worth knowing:
- The name is
BITS Transferwhen none is given, as Nardella's paper and JPCERT's test show. - The priority is Foreground, per the documentation.
What it leaves: powershell.exe as the creating process in event 3 on recent builds, script block logging (4104) and module logging (4103) when enabled, and the PSReadLine history file of the user, which JPCERT saw written during its test.
With COM and other clients
BITS is a COM service, so any program can create and configure jobs without bitsadmin or PowerShell. Malware that does so leaves no command line to find; the creating process in event 3, where the build records it, and the job record are what remain. Built-in programs use BITS too: Atomic Red Team test 4 abuses desktopimgdownldr.exe, and notes that the connection and the file write come from the BITS svchost.exe. BITSInject writes the queue file directly; we found no public test of what that leaves in the event log.
What each method leaves
| Method | Job queue | Bits-Client log | Elsewhere |
|---|---|---|---|
bitsadmin /transfer | Removed when done; remnants can be carved | 3, 59, 60, 4 | 4688 or Sysmon 1, Prefetch |
bitsadmin /create, /setnotifycmdline, /resume | The job, with its command, until cancelled or expired | 3, then 59 with 60 or 61; 64 if a launch fails | One process event per command, Prefetch |
Start-BitsTransfer, synchronous | Removed when done | 3, 59, 60, 4; name BITS Transfer by default | PowerShell logging, PSReadLine history |
Start-BitsTransfer -Asynchronous, Set-BitsTransfer | The job, until completed or cancelled | 3, 59, 60 or 61 | PowerShell logging |
| A program using COM | The job | 3, naming the program on recent builds | The program's own traces |
| The notify program starting | Unchanged | 64 only if the launch fails | A process whose parent is svchost.exe -k netsvcs -p -s BITS; its Prefetch |
The event IDs are covered in Bits-Client event IDs.
Removing a job without losing it
- Record it first. Save
bitsadmin /list /allusers /verboseandGet-BitsTransfer -AllUsers | Format-List *, and copy the Downloader folder and the event log, as in collecting BITS evidence. - Copy the
BIT*.tmpfile. Cancel deletes the job's transferred and partly transferred files, per Microsoft's life cycle page. - Do not take ownership before the job is recorded.
- Cancel it from an elevated prompt with
bitsadmin /cancel {job-GUID}. Use the GUID: display names need not be unique. - Avoid
bitsadmin /reset /allusersas a fix. It cancels every job, and Microsoft's reset page says it cannot reset jobs created by Local System. - Then deal with the program and look for the same command line in other persistence locations.
FAQ
How does BITS persistence work?
A BITS job can carry a notify command line, a program that BITS starts when the job reaches the transferred or error state. If the program neither completes nor cancels the job and returns a non-zero exit code, BITS starts it again after the job's minimum retry delay. The job lives in the BITS queue, not in the registry or the task scheduler.
Does a BITS notify command run as SYSTEM?
Microsoft says no: BITS starts the program with CreateProcessAsUser in the context of the user who set the command, and no command-line callback runs for jobs in a service account context. Dor Azouri's BITSInject showed in 2017 that a job injected into the queue file could run a program as LocalSystem, so do not dismiss a notify command on a SYSTEM-owned job.
How long does a malicious BITS job survive?
Until someone completes or cancels it, or until BITS cancels it after 90 days without activity, the default JobInactivityTimeout. Transfer progress and property changes reset that timer. Jobs survive reboots, but a job owned by a user only runs while that user is logged on interactively.
Can PowerShell set a BITS notify command line?
In recent versions, yes: the Windows Server 2022 and 2025 documentation of Start-BitsTransfer and Set-BitsTransfer lists a NotifyCmdLine parameter, while the 2016 and 2019 versions do not. bitsadmin /setnotifycmdline and the COM interface work on older systems.
Related articles
Frequently asked questions
How does BITS persistence work?
A BITS job can carry a notify command line, a program that BITS starts when the job reaches the transferred or error state. If the program neither completes nor cancels the job and returns a non-zero exit code, BITS starts it again after the job's minimum retry delay. The job lives in the BITS queue, not in the registry or the task scheduler.
Does a BITS notify command run as SYSTEM?
Microsoft says no: BITS starts the program with CreateProcessAsUser in the context of the user who set the command, and no command-line callback runs for jobs in a service account context. Dor Azouri's BITSInject showed in 2017 that a job injected into the queue file could run a program as LocalSystem, so do not dismiss a notify command on a SYSTEM-owned job.
How long does a malicious BITS job survive?
Until someone completes or cancels it, or until BITS cancels it after 90 days without activity, the default JobInactivityTimeout. Transfer progress and property changes reset that timer. Jobs survive reboots, but a job owned by a user only runs while that user is logged on interactively.
Can PowerShell set a BITS notify command line?
In recent versions, yes: the Windows Server 2022 and 2025 documentation of Start-BitsTransfer and Set-BitsTransfer lists a NotifyCmdLine parameter, while the 2016 and 2019 versions do not. bitsadmin /setnotifycmdline and the COM interface work on older systems.