1. Resources
  2. Detection sources
  3. Event ID 5059

Event ID 5059: Key migration operation

Written when a key held by the Microsoft Software or Smart Card Key Storage Provider is exported or imported. On a certification authority server, an export by a named account can be a backup or a theft of the CA private key.

Log source
Windows Security log
Detection value
Supporting
Volume
Low
Last updated
Audit subcategory
Audit Other System Events (System, Success and Failure)
Logged on
All Windows computers
Event versions
0, 1
Detects
1 attack (1 rule)
MITRE ATT&CK
1 technique in 1 tactic
Threat groups
2 groups that MITRE ATT&CK records using these techniques
Fields the rules read
SubjectUserSidOperation

When it is written

Windows writes 5059 when a cryptographic key is exported or imported through a CNG key storage provider (KSP), if Audit Other System Events is on. Microsoft says it is written only for two providers: the Microsoft Software Key Storage Provider and the Microsoft Smart Card Key Storage Provider. A key held by any other provider writes no 5059.

A successful operation has Return Code 0x0; a failed one is an Audit Failure event with the error code. Microsoft notes that the export operation is written not only on a real export, such as exporting a certificate with its private key, but also when a key is simply read for use.

How to turn it on

Advanced audit policy subcategory Audit Other System Events, Success and Failure. Set it in a Group Policy object linked to the computers that write the event:

Computer Configuration > Policies > Windows Settings > Security Settings > Advanced Audit Policy Configuration > Audit Policies > System > Audit Other System Events
Microsoft's recommendation per computer role
ComputerAuditNote
Domain controllersSuccess and FailureRecommended in both baselines, for the start, stop and failure events of the Windows Firewall service and driver.
Member serversSuccess and FailureRecommended in both baselines, for the start, stop and failure events of the Windows Firewall service and driver.
WorkstationsSuccess and FailureRecommended in both baselines, for the start, stop and failure events of the Windows Firewall service and driver.
Check the current setting
auditpol /get /subcategory:"Other System Events"
Based on vendor documentation.
Turn it on (local policy; a domain GPO overrides it)
auditpol /set /subcategory:"Other System Events" /success:enable /failure:enable
Based on vendor documentation.
The same on a Windows in another display language
auditpol /get /subcategory:"{0CCE9214-69AE-11D9-BED3-505054503030}"
Based on vendor documentation.

Run the commands in an elevated prompt on a computer that writes the event. Subcategory settings take effect only when the security option Audit: Force audit policy subcategory settings (Windows Vista or later) to override audit policy category settings is enabled (the default), and a Group Policy object that sets advanced audit policy replaces local changes at its next refresh. Microsoft's advanced audit policy reference

The subcategory is not enough on its own. Microsoft documents 5059 only for keys held by the Microsoft Software Key Storage Provider or the Microsoft Smart Card Key Storage Provider. Check which provider holds the private key of each CA (it is chosen when the CA is set up): a key held by a hardware security module's own provider, or by an older CryptoAPI provider, writes no 5059, and the rule cannot see an export of it.

To find the key container of the CA certificate, look at the certificates in the computer's personal store: Microsoft's event page shows certutil -store output, where the Key Container line gives the name that appears in KeyName.

Fields

In Event Viewer order. The field names are those of the event XML, from the event template that ships with Windows.

FieldWhat it holdsSince
Security IDSubjectUserSidSubjectRead by 1 ruleSID of the account that asked for the operation. Event Viewer shows it resolved to an account name when it can. The rule leaves out S-1-5-18, S-1-5-19 and S-1-5-20.v0
Account NameSubjectUserNameSubjectName of that account. For Local System it is the computer account, a name that ends with $.v0
Account DomainSubjectDomainNameSubjectDomain of the account, usually as a NetBIOS name, the computer name for a local account, or NT AUTHORITY for well-known principals.v0
Logon IDSubjectLogonIdSubjectHexadecimal ID of the account's logon session. It matches the Logon ID of the 4624 event on the same computer.v0
Process IDClientProcessIdProcess InformationID of the process behind the operation, in decimal (shown as Process ID). Not documented by Microsoft. Version 1.v1
Process Creation TimeClientCreationTimeProcess InformationStart time of that process (shown as Process Creation Time). With the process ID it identifies one run of the process. Not documented by Microsoft. Version 1.v1
Provider NameProviderNameCryptographic ParametersKey storage provider that performed the operation. Microsoft lists Microsoft Software Key Storage Provider and Microsoft Smart Card Key Storage Provider.v0
Algorithm NameAlgorithmNameCryptographic ParametersAlgorithm of the key, for example RSA, DSA, DH, or an ECDH or ECDSA curve such as ECDSA_P256, ECDSA_P384 or ECDSA_P521.v0
Key NameKeyNameCryptographic ParametersName of the key container the operation used. Compare it with the key container of the CA certificate to know whether the CA key was involved.v0
Key TypeKeyTypeCryptographic ParametersWhether the key belongs to a user or to the computer, as a message code. %%2500 user key, %%2499 machine key.v0
OperationAdditional InformationRead by 1 ruleOperation performed, as a message code. %%2464 export of a persistent key (also written for plain reads), %%2465 import of a persistent key. The rule matches %%2464 and its text.v0
Return CodeReturnCodeAdditional InformationResult in hexadecimal. 0x0 on success, otherwise the error code of the failure.v0

Event versions

The template has two versions. Version 0 is the one Microsoft's event page documents. Version 1 adds ClientProcessId and ClientCreationTime, the process behind the operation and its start time, shown in Event Viewer as Process ID and Process Creation Time. Microsoft does not document version 1.

  • Version 0: 10 fields
  • Version 1: 12 fields, adds ClientProcessId, ClientCreationTime

Values to know

Operation

ValueMeaningSignal
%%2464Export of persistent cryptographic keyWhat the rule matches, by code or by its text. On a CA server, by a named account and for the CA's key container, it is a backup or a copy of the CA private key. Also written when a key is only read.Attack signal
%%2465Import of persistent cryptographic keyA key was imported, for example a certificate with its private key.Worth knowing

Security ID SubjectUserSid

ValueMeaningSignal
S-1-5-18, S-1-5-19 or S-1-5-20Local System, Local Service or Network ServiceServices reading their own keys. Left out by the rule.Noise
Any other SIDA named accountOn a CA server, compare KeyName with the CA's key container. A match is a high-severity finding unless a planned backup explains it.Attack signal

Key Type KeyType

ValueMeaningSignal
%%2499Machine keyA key stored for the computer rather than for a user.Worth knowing
%%2500User keyA key stored in a user's profile.Worth knowing

Return Code ReturnCode

ValueMeaningSignal
0x0SuccessExpected
Any other valueThe operation failedWritten as an Audit Failure event with the error code.Failure

Volume and noise

Microsoft rates Audit Other System Events Low; most of the subcategory is the start and stop events of the Windows Firewall service and driver. The volume of 5059 depends on how often software uses keys held by the two providers: because a plain key read is logged as an export, services that use certificates with keys in the Microsoft Software Key Storage Provider can write it routinely, usually as Local System, Local Service or Network Service.

Keeping it manageable

  • On certification authority servers keep every 5059: the rule reads Operation and SubjectUserSid, and KeyName is what tells the CA key from the others.
  • The rule leaves out Local System, Local Service and Network Service (S-1-5-18, S-1-5-19, S-1-5-20), whose key reads are logged as exports. Dropping the same accounts at collection is safe for the rule.
  • Once you know the key containers of the other certificates on a CA server, you can exclude them by KeyName; never exclude the container of the CA certificate itself.
  • The rule is meant for CA servers only. Elsewhere, collect 5059 for your own key monitoring if you need it.

Sample event

Version 1, with made-up values.

<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="Microsoft-Windows-Security-Auditing" Guid="{54849625-5478-4994-a5ba-3e3b0328c30d}" />
    <EventID>5059</EventID>
    <Version>1</Version>
    <Level>0</Level>
    <Task>12292</Task>
    <Opcode>0</Opcode>
    <Keywords>0x8020000000000000</Keywords>
    <TimeCreated SystemTime="2026-11-18T09:30:12.4567890Z" />
    <EventRecordID>1048576</EventRecordID>
    <Correlation />
    <Execution ProcessID="712" ThreadID="2408" />
    <Channel>Security</Channel>
    <Computer>CA01.corp.example.com</Computer>
    <Security />
  </System>
  <EventData>
    <Data Name="SubjectUserSid">S-1-5-21-1004336348-1177238915-682003330-1104</Data>
    <Data Name="SubjectUserName">alice</Data>
    <Data Name="SubjectDomainName">CORP</Data>
    <Data Name="SubjectLogonId">0x5d3a41</Data>
    <Data Name="ClientProcessId">6204</Data>
    <Data Name="ClientCreationTime">2026-11-18T09:29:58.1234567Z</Data>
    <Data Name="ProviderName">Microsoft Software Key Storage Provider</Data>
    <Data Name="AlgorithmName">RSA</Data>
    <Data Name="KeyName">CORP-ISSUING-CA</Data>
    <Data Name="KeyType">%%2499</Data>
    <Data Name="Operation">%%2464</Data>
    <Data Name="ReturnCode">0x0</Data>
  </EventData>
</Event>

Attacks this event reveals

Detection rules that read this event:

Frequently asked questions

Why does event 5059 say Export when nobody exported a key?

Microsoft notes that the operation Export of persistent cryptographic key is typically written when a key is read for use, and also on real exports such as exporting a certificate with its private key. That is why the rule leaves out the built-in service accounts and asks you to compare KeyName with the CA's key container.

Why do I see no 5059 for my CA's private key?

Either Audit Other System Events is not on for the CA server, or the CA key is not held by the Microsoft Software or Smart Card Key Storage Provider. Microsoft documents the event for those two providers only, so a key in a hardware security module's provider or in an older CryptoAPI provider writes none.

How do I tell whether a 5059 event concerns the CA key?

Compare KeyName with the key container of the CA certificate, which certutil shows as Key Container for the certificates in the computer's personal store. An export of that container by a named account is a backup or a copy of the CA private key.

Is an export of the CA key always an attack?

No. A planned CA backup exports the key too. Check for a change record and for a Certificate Services backup event (4876) around the same time; an export with neither deserves an immediate look, since whoever holds the CA key can issue certificates the domain trusts.

References