Chromium’s sandboxed course of mannequin defends properly from malicious net content material, however there are limits to how properly the appliance can defend itself from malware already on the pc. Cookies and different credentials stay a excessive worth goal for attackers, and we try to deal with this ongoing risk in a number of methods, together with engaged on net requirements like
DBSC
that can assist disrupt the cookie theft business since exfiltrating these cookies will not have any worth.
The place it isn’t doable to stop the theft of credentials and cookies by malware, the subsequent neatest thing is making the assault extra observable by antivirus, endpoint detection brokers, or enterprise directors with fundamental log evaluation instruments.
This weblog describes one set of indicators to be used by system directors or endpoint detection brokers that ought to reliably flag any entry to the browser’s protected knowledge from one other software on the system. By rising the chance of an assault being detected, this adjustments the calculus for these attackers who might need a powerful need to stay stealthy, and would possibly trigger them to rethink finishing up a lot of these assaults towards our customers.
Background
Chromium based mostly browsers on Home windows use the DPAPI (Information Safety API) to safe native secrets and techniques akin to cookies, password and so on. towards theft. DPAPI safety relies on a key derived from the person’s login credential and is designed to guard towards unauthorized entry to secrets and techniques from different customers on the system, or when the system is powered off. As a result of the DPAPI secret is certain to the logged in person, it can not defend towards native malware assaults — malware executing because the person or at a better privilege degree can simply name the identical APIs because the browser to acquire the DPAPI secret.
Since 2013, Chromium has been making use of the CRYPTPROTECT_AUDIT flag to DPAPI calls to request that an audit log be generated when decryption happens, in addition to tagging the info as being owned by the browser. As a result of all of Chromium’s encrypted knowledge storage is backed by a DPAPI-secured key, any software that needs to decrypt this knowledge, together with malware, ought to at all times reliably generate a clearly observable occasion log, which can be utilized to detect a lot of these assaults.
There are three most important steps concerned in making the most of this log:
- Allow logging on the pc working Google Chrome, or some other Chromium based mostly browser.
- Export the occasion logs to your backend system.
- Create detection logic to detect theft.
This weblog may also present how the logging works in apply by testing it towards a python password stealer.
Step 1: Allow logging on the system
DPAPI occasions are logged into two locations within the system. Firstly, there may be the
4693 occasion that may be logged into the Safety Log. This occasion may be enabled by turning on “Audit DPAPI Exercise” and the steps to do that are described
right here, the coverage itself sits deep inside Safety Settings -> Superior Audit Coverage Configuration -> Detailed Monitoring.
Here’s what the 4693 occasion seems like:
<Occasion xmlns=”http://schemas&interval;microsoft&interval;com/win/2004/08/occasions/occasion”>
 <System>
 <Supplier Identify=”Microsoft-Home windows-Safety-Auditing” Guid=”{&interval;&interval;&interval;}” />
 <EventID>4693</EventID>
 <Model>0</Model>
 <Degree>0</Degree>
 <Process>13314</Process>
 <Opcode>0</Opcode>
 <Key phrases>0x8020000000000000</Key phrases>
 <TimeCreated SystemTime=”2015-08-22T06:25:14&interval;589407700Z” />
 <EventRecordID>175809</EventRecordID>
 <Correlation />
 <Execution ProcessID=”520″ ThreadID=”1340″ />
 <Channel>Safety</Channel>
 <Laptop>DC01&interval;contoso&interval;native</Laptop>
 <Safety />
 </System>
 <EventData>
 <Information Identify=”SubjectUserSid”>S-1-5-21-3457937927-2839227994-823803824-1104</Information>
 <Information Identify=”SubjectUserName”>dadmin</Information>
 <Information Identify=”SubjectDomainName”>CONTOSO</Information>
 <Information Identify=”SubjectLogonId”>0x30d7c</Information>
 <Information Identify=”MasterKeyId”>0445c766-75f0-4de7-82ad-d9d97aad59f6</Information>
 <Information Identify=”RecoveryReason”>0x5c005c</Information>
 <Information Identify=”RecoveryServer”>DC01&interval;contoso&interval;native</Information>
 <Information Identify=”RecoveryKeyId” />
 <Information Identify=”FailureId”>0x380000</Information>
 </EventData>
</Occasion>
The problem with the 4693 occasion is that whereas it’s generated if there may be DPAPI exercise on the system, it sadly doesn’t comprise details about which course of was performing the DPAPI exercise, nor does it comprise details about which specific secret is being accessed. It’s because the
Execution ProcessID
discipline within the occasion will at all times be the method id of lsass.exe as a result of it’s this course of that manages the encryption keys for the system, and there’s no entry for the outline of the info.
It was for that reason that, in current variations of Home windows a brand new occasion sort was added to assist establish the method making the DPAPI name instantly. This occasion was added to the
Microsoft-Home windows-Crypto-DPAPI
stream which manifests within the Occasion Log within the Purposes and Providers Logs > Microsoft > Home windows > Crypto-DPAPI a part of the Occasion Viewer tree.
The brand new occasion known as
DPAPIDefInformationEvent
and has id 16385, however sadly is just emitted to the Debug channel and by default this isn’t persevered to an Occasion Log, except Debug channel logging is enabled. This may be achieved by enabling it instantly in powershell:
&greenback;log = `
 New-Object System&interval;Diagnostics&interval;Eventing&interval;Reader&interval;EventLogConfiguration `
 Microsoft-Home windows-Crypto-DPAPI/Debug
&greenback;log&interval;IsEnabled = &greenback;True
&greenback;log&interval;SaveChanges()

As soon as this log is enabled then you need to begin to see 16385 occasions generated, and these will comprise the actual course of ids of functions performing DPAPI operations. Notice that 16385 occasions are emitted by the working system even for knowledge not flagged with CRYPTPROTECT_AUDIT, however to establish the info as owned by the browser, the info description is important. 16385 occasions are described later.
Additionally, you will wish to allow
Audit Course of Creation so as to have the ability to know a present mapping of course of ids to course of names — extra particulars on that later. You would possibly wish to additionally contemplate enabling logging of
full command strains.
Step 2: Acquire the occasions
The occasions you wish to acquire are:
- From Safety log:
- 4688: “A brand new course of was created.”
- From Microsoft-Home windows-Crypto-DPAPI/Debug log: (enabled above)
- 16385: “DPAPIDefInformationEvent”
These needs to be collected from all workstations, and persevered into your enterprise logging system for evaluation.
Step 3: Write detection logic to detect theft.
With these two occasions is it now doable to detect when an unauthorized software calls into DPAPI to attempt to decrypt browser secrets and techniques.
The final strategy is to generate a map of course of ids to lively processes utilizing the 4688 occasions, then each time a 16385 occasion is generated, it’s doable to establish the presently working course of, and alert if the method doesn’t match a licensed software akin to Google Chrome. You would possibly discover your enterprise logging software program can already maintain monitor of which course of ids map to which course of names, so be happy to simply use that present performance.
Let’s dive deeper into the occasions.
A 4688 occasion seems like this – e.g. right here is Chrome browser launching from explorer:
<Occasion xmlns=”http://schemas&interval;microsoft&interval;com/win/2004/08/occasions/occasion”>
 <System>
 <Supplier Identify=”Microsoft-Home windows-Safety-Auditing” Guid=”{…}” />
 <EventID>4688</EventID>
 <Model>2</Model>
 <Degree>0</Degree>
 <Process>13312</Process>
 <Opcode>0</Opcode>
 <Key phrases>0x8020000000000000</Key phrases>
 <TimeCreated SystemTime=”2024-03-28T20:06:41&interval;9254105Z” />
 <EventRecordID>78258343</EventRecordID>
 <Correlation />
 <Execution ProcessID=”4″ ThreadID=”54256″ />
 <Channel>Safety</Channel>
 <Laptop>WIN-GG82ULGC9GO&interval;contoso&interval;native</Laptop>
 <Safety />
 </System>
 <EventData>
 <Information Identify=”SubjectUserSid”>S-1-5-18</Information>
 <Information Identify=”SubjectUserName”>WIN-GG82ULGC9GO&greenback;</Information>
 <Information Identify=”SubjectDomainName”>CONTOSO</Information>
 <Information Identify=”SubjectLogonId”>0xe8c85cc</Information>
 <Information Identify=”NewProcessId“>0x17eac</Information>
 <Information Identify=”NewProcessName”>C:\Program Information\Google\Chrome\Utility\chrome&interval;exe</Information>
 <Information Identify=”TokenElevationType”>%%1938</Information>
 <Information Identify=”ProcessId”>0x16d8</Information>
 <Information Identify=”CommandLine”>”C:\Program Information\Google\Chrome\Utility\chrome&interval;exe” </Information>
 <Information Identify=”TargetUserSid”>S-1-0-0</Information>
 <Information Identify=”TargetUserName”>-</Information>
 <Information Identify=”TargetDomainName”>-</Information>
 <Information Identify=”TargetLogonId”>0x0</Information>
 <Information Identify=”ParentProcessName”>C:\Home windows\explorer&interval;exe</Information>
 <Information Identify=”MandatoryLabel”>S-1-16-8192</Information>
 </EventData>
</Occasion>

The necessary half right here is the
NewProcessId, in hex
0x17eac
which is
97964.
A 16385 occasion seems like this:
<Occasion xmlns=”http://schemas&interval;microsoft&interval;com/win/2004/08/occasions/occasion”>
 <System>
 <Supplier Identify=”Microsoft-Home windows-Crypto-DPAPI” Guid=”{…}” />
 <EventID>16385</EventID>
 <Model>0</Model>
 <Degree>4</Degree>
 <Process>64</Process>
 <Opcode>0</Opcode>
 <Key phrases>0x2000000000000040</Key phrases>
 <TimeCreated SystemTime=”2024-03-28T20:06:42&interval;1772585Z” />
 <EventRecordID>826993</EventRecordID>
 <Correlation ActivityID=”{777bf68d-7757-0028-b5f6-7b775777da01}” />
 <Execution ProcessID=”1392″ ThreadID=”57108″ />
 <Channel>Microsoft-Home windows-Crypto-DPAPI/Debug</Channel>
 <Laptop>WIN-GG82ULGC9GO&interval;contoso&interval;native</Laptop>
 <Safety UserID=”S-1-5-18″ />
 </System>
 <EventData>
 <Information Identify=”OperationType“>SPCryptUnprotect</Information>
 <Information Identify=”DataDescription“>Google Chrome</Information>
 <Information Identify=”MasterKeyGUID”>{4df0861b-07ea-49f4-9a09-1d66fd1131c3}</Information>
 <Information Identify=”Flags”>0</Information>
 <Information Identify=”ProtectionFlags”>16</Information>
 <Information Identify=”ReturnValue”>0</Information>
 <Information Identify=”CallerProcessStartKey”>32651097299526713</Information>
 <Information Identify=”CallerProcessID“>97964</Information>
 <Information Identify=”CallerProcessCreationTime”>133561300019253302</Information>
 <Information Identify=”PlainTextDataSize”>32</Information>
 </EventData>
</Occasion>

The necessary elements listed here are the
OperationType, the
DataDescription
and the
CallerProcessID.
For DPAPI decrypts, the
OperationType
will probably be SPCryptUnprotect.
Every Chromium based mostly browser will tag its knowledge with the product title, e.g. Google Chrome, or Microsoft Edge relying on the proprietor of the info. It will at all times seem within the
DataDescription
discipline, so it’s doable to tell apart browser knowledge from different DPAPI secured knowledge.
Lastly, the
CallerProcessID
will map to the method performing the decryption. On this case, it’s 97964 which matches the method ID seen within the 4688 occasion above, exhibiting that this was seemingly Google Chrome decrypting its personal knowledge! Keep in mind that since these logs solely comprise the trail to the executable, for a full assurance that that is really Chrome (and never malware pretending to be Chrome, or malware injecting into Chrome), further protections akin to eradicating administrator entry, and software allowlisting may be used to offer a better assurance of this sign. In current variations of Chrome or Edge, you may additionally see logs of decryptions occurring within the elevation_service.exe course of, which is one other professional a part of the browser’s knowledge storage.
To detect unauthorized DPAPI entry, it would be best to generate a working map of all processes utilizing 4688 occasions, then search for 16385 occasions which have a CallerProcessID that doesn’t match a sound caller – Let’s strive that now.
Testing with a python password stealer
We are able to check that this works with a public script to decrypt passwords taken from
a public weblog. It generates two occasions, as anticipated:
Right here is the 16385 occasion, exhibiting {that a} course of is decrypting the “Google Chrome” key.
<Occasion xmlns=”http://schemas&interval;microsoft&interval;com/win/2004/08/occasions/occasion”>
 <System>
 < &interval;&interval;&interval; >
 <EventID>16385</EventID>
 < &interval;&interval;&interval; >
 <TimeCreated SystemTime=”2024-03-28T20:28:13&interval;7891561Z” />
 < &interval;&interval;&interval; >
 </System>
 <EventData>
 <Information Identify=”OperationType”>SPCryptUnprotect</Information>
 <Information Identify=”DataDescription”>Google Chrome</Information>
 < &interval;&interval;&interval; >
 <Information Identify=”CallerProcessID”>68768</Information>
 <Information Identify=”CallerProcessCreationTime”>133561312936527018</Information>
 <Information Identify=”PlainTextDataSize”>32</Information>
 </EventData>
</Occasion>
For the reason that knowledge description being decrypted was “Google Chrome” we all know that is an try and learn Chrome secrets and techniques, however to find out the method behind 68768 (0x10ca0), we have to correlate this with a 4688 occasion.
Right here is the corresponding 4688 occasion from the Safety Log (a course of begin for python3.exe) with the matching course of id:
<Occasion xmlns=”http://schemas&interval;microsoft&interval;com/win/2004/08/occasions/occasion”>
 <System>
 < &interval;&interval;&interval; >
 <EventID>4688</EventID>
 < &interval;&interval;&interval; >
 <TimeCreated SystemTime=”2024-03-28T20:28:13&interval;6527871Z” />
 < &interval;&interval;&interval; >
 </System>
 <EventData>
 < &interval;&interval;&interval; >
 <Information Identify=”NewProcessId”>0x10ca0</Information>
 <Information Identify=”NewProcessName”>C:\python3\bin\python3&interval;exe</Information>
 <Information Identify=”TokenElevationType”>%%1938</Information>
 <Information Identify=”ProcessId”>0xca58</Information>
 <Information Identify=”CommandLine”>“c:\python3\bin\python3&interval;exe” steal_passwords&interval;py</Information>
 < &interval;&interval;&interval; >
 <Information Identify=”ParentProcessName”>C:\Home windows\System32\cmd&interval;exe</Information>
 </EventData>
</Occasion>
On this case, the method id matches the python3 executable working a doubtlessly malicious script, so we all know that is seemingly very suspicious conduct, and may set off an alert instantly! Keep in mind course of ids on Home windows will not be distinctive so it would be best to ensure you use the 4688 occasion with the timestamp closest, however sooner than, the 16385 occasion.
Abstract
This weblog has described a method for robust detection of cookie and credential theft. We hope that every one defenders discover this publish helpful. Because of Microsoft for including the DPAPIDefInformationEvent log sort, with out which this could not be doable.