The Mailbox Was Used. Now, by Whom?
Part 1 ended with a narrow, defensible conclusion: my mailbox had been used through authenticated access, rules had hidden my inbound mail, and Exchange Online had sent the campaign. That justified containment. It didn't explain anything.
The questions that came next were all identity questions. When did the unauthorized access start? Which sign-ins were mine and which weren't? Were there devices I didn't own? Was anyone else in the tenant hit? Those answers live in Microsoft Entra ID, and they're easy to get wrong in two ways: pulling the wrong logs, and following the wrong identifier.
If you haven't read it, the post-mortem, The Email Really Was From Me, has the whole timeline. This post is about how we built it.
About the Code in This Post
Everything here is read-only. Run it from a privileged access workstation (PAW), in PowerShell 7, with the Microsoft Graph PowerShell SDK and the ExchangeOnlineManagement module.
| Step | Source | Needs |
|---|---|---|
| Pull sign-ins, both kinds | Graph beta/auditLogs/signIns | AuditLog.Read.All, Directory.Read.All |
| Group by session | The same data, in PowerShell | — |
| List the user's devices | Graph v1.0 devices | Directory.Read.All |
| Join sessions to the mailbox | Search-UnifiedAuditLog | View-Only Audit Logs in Purview |
Gotcha #1: You Might Only Have Half the Sign-Ins
Entra ID records two kinds of user sign-in. Interactive sign-ins are the ones a person performs: a password, an MFA prompt, a code. Non-interactive sign-ins are the ones a client performs on the person's behalf, mostly refreshing tokens in the background. In a compromise, the attacker's day-to-day activity is mostly the second kind.
Here's the trap: Microsoft Graph returns only interactive sign-ins unless you ask for the others. The v1.0 endpoint can't return non-interactive sign-ins at all. The beta endpoint can, but only when your filter asks for them by signInEventTypes.
Our first identity export for the account came back with 224 sign-ins, and all 224 were interactive. It was a useful export, and it was missing the category of activity that mattered most. When the attacker came back in October and replayed old tokens 278 times, those requests were non-interactive. An export built the same way would never have shown them.
Ask for both kinds explicitly:
Connect-MgGraph -Scopes 'AuditLog.Read.All', 'Directory.Read.All'
$user = Get-MgUser -UserId 'jd**@*****************re.com'
$since = (Get-Date).ToUniversalTime().AddDays(-30).ToString('s') + 'Z'
$types = "signInEventTypes/any(t: t eq 'interactiveUser' or " +
"t eq 'nonInteractiveUser')"
$filter = "userId eq '$($user.Id)' and createdDateTime ge $since and $types"
$uri = 'https://graph.microsoft.com/beta/auditLogs/signIns?$filter=' +
[uri]::EscapeDataString($filter)
$signIns = @(while ($uri) {
$page = Invoke-MgGraphRequest -Uri $uri -OutputType PSObject
$page.value
$uri = $page.'@odata.nextLink'
})
$signIns | Group-Object isInteractive -NoElement
The last line is the check. If it only shows True, you don't have the whole picture. Fix the filter before you draw any conclusions.
The other limit is time. Entra ID kept 30 days of sign-in history in our tenant. The attack started two weeks before anyone noticed it, so the July sign-ins were already close to aging out by the time we pulled them. Export first, analyze second. You can rerun an analysis; you can't re-collect a log that has expired.
Follow the Session, Not the IP
The instinct with a suspicious sign-in is to look at the IP address. It's the most visible field, it has a location next to it, and it's the least reliable way to connect events.
The persistent attack session in our case lasted two weeks and came from four different IP addresses. It was created on July 23 and came back on August 6 to create the inbox rule that hid all incoming mail, minutes before the campaign. An IP-based search would have shown four unrelated-looking visitors. The session ID showed one.
Every Entra sign-in carries a sessionId, and later sign-ins that refresh tokens from the same session keep it. Group by it and the account's history becomes a short list of sessions instead of hundreds of rows:
$signIns | Group-Object sessionId | ForEach-Object {
$s = $_.Group | Sort-Object createdDateTime
[pscustomobject]@{
Session = $_.Name
First = $s[0].createdDateTime
Last = $s[-1].createdDateTime
SignIns = $_.Count
Addresses = @($s.ipAddress | Sort-Object -Unique).Count
Apps = (@($s.appDisplayName | Sort-Object -Unique) -join ', ')
DeviceCode = @($s |
Where-Object originalTransferMethod -eq 'deviceCodeFlow').Count
Devices = (@($s.deviceDetail.displayName | Where-Object { $_ } |
Sort-Object -Unique) -join ', ')
}
} | Sort-Object First | Format-Table -AutoSize
How to read it:
- A session that spans days and several addresses isn't suspicious on its own. Laptops roam between home, office, hotel, and phone hotspot. What matters is what else the session shows.
- The
DeviceCodecolumn is where to look first. It counts sign-ins whoseoriginalTransferMethodisdeviceCodeFlow, meaning the session started with a device code. In our export, 22 sign-ins had device-code ancestry, but only 7 of them showeddeviceCodeas their authentication protocol. Search on the protocol and you miss two-thirds of them. Part 3 explains why the flow behaves this way. - Label your own sessions. Four sessions had device-code ancestry, and only two were the attacker's. The other two were mine: Microsoft Graph command-line sign-ins from my own workstation, one of them the investigation itself on August 9. Admin tooling uses device code legitimately, which is why "any device-code sign-in" isn't the finding. Note your own sign-ins as you make them, or you'll end up investigating yourself.
As for the IP addresses, the two that mattered geolocated to two different countries, neither of them mine. That's context, not attribution. Geolocation describes where traffic left a network, not where a person sat.
The Alerts That Didn't Fire
It's worth being blunt about this, because it's the part most tenants assume they're covered for. Across all 22 device-code sign-ins:
- Conditional Access status was
successon every one. The policies that applied were satisfied. MFA had genuinely been completed once, and every later sign-in inherited that result. - Sign-in risk was
noneon every one. Identity Protection raised nothing.
That isn't a product failure. A device-code phish produces sign-ins that are, mechanically, legitimate. But it means "no alerts" is not evidence of "no compromise." If you're waiting for a risk detection to start an investigation, this kind of attack won't give you one. The originalTransferMethod query from the post-mortem's audit is something you have to run yourself.
The Devices You Didn't Buy
Within a minute of the first device-code sign-in, a new Windows device object appeared on the account. By August 6 there were five. These weren't just registered devices. Their trust type was Entra joined, enrolled through the Intune enrollment app, as if someone had set up a company laptop.
List the devices tied to the user:
$sel = 'displayName,registrationDateTime,trustType,isManaged,isCompliant,' +
'operatingSystemVersion,accountEnabled,approximateLastSignInDateTime'
$uri = "https://graph.microsoft.com/v1.0/users/$($user.Id)" +
"/registeredDevices/microsoft.graph.device?`$select=$sel"
(Invoke-MgGraphRequest -Uri $uri -OutputType PSObject).value |
Sort-Object registrationDateTime |
Format-Table displayName, registrationDateTime, trustType, isManaged,
isCompliant, operatingSystemVersion, accountEnabled
The names were no help. They were generic DESKTOP- names, which Windows generates by itself, and the tenant had six devices named that way. Five belonged to this incident. The sixth was a perfectly normal machine registered years earlier. What separated them was everything else:
| Signal | The five attack devices | The legitimate one |
|---|---|---|
| Registered | July 22 and August 6, within minutes of device-code sign-ins | Years earlier |
| OS build | All identical, and badly out of date | Different, current for its age |
| Managed / compliant | No / no | Consistent with its history |
| Seen in suspicious sign-ins | Three directly; two by timing and build | Never |
No single row condemns a device. The combination does. That's why containment disabled the five rather than deleting them: their registration time, build, and owner were evidence, and a deleted device object takes all of that with it. Disabling also paid off later. The approximateLastSignInDateTime on one of the disabled devices is what flagged the October replay attempt.
Tie the Session to the Mailbox
Here's the join that turned two investigations into one story. The Entra session ID also appears in the Exchange Online audit records for actions taken in that session. Take a session ID from the table above and search the Purview audit log for it:
Connect-ExchangeOnline -ShowBanner:$false
$sid = '<session ID from the table above>'
Search-UnifiedAuditLog -StartDate '2026-07-20' -EndDate '2026-08-10' `
-FreeText $sid -ResultSize 5000 | ForEach-Object {
$d = $_.AuditData | ConvertFrom-Json
[pscustomobject]@{
TimeUtc = $_.CreationDate
Workload = $d.Workload
Op = $d.Operation
Client = ($d.ClientInfoString -split ';')[0]
}
} | Sort-Object TimeUtc | Format-Table -AutoSize
For the persistent session, that ID turned up on the August 6 New-InboxRule record that hid all incoming mail, and on the mailbox access records around it. Same session ID, sign-in log to mailbox audit, no IP address required.
One honest limit: the six send records carried a different, Exchange-side session ID, so the search alone didn't return them. We tied the sends in the way Part 1 did, by time, client, and source address, minutes after the rule. Expect some workloads to log their own session IDs, and use the Entra session as the spine of the timeline rather than the only key.
That's the payoff of following the session. Each piece on its own (a sign-in, a device, a rule, a send) has an innocent explanation. Joined on a session ID, they don't.
Scope the Tenant, Not Just the Mailbox
The last identity question is whether anyone else was hit. We ran the same two checks across every account:
- Device-code sign-ins tenant-wide for the incident window. Only the affected account appeared, plus our own investigation sign-in.
- Generic
DESKTOP-device names tenant-wide, checked for owner, registration time, and build. Only the five devices already found matched the pattern.
That's a scoped conclusion: within the evidence we collected, no other account showed the same pattern. It's not a guarantee. Say it that way in your report, too, because the difference matters to anyone who reads it later.
What This Stage Proved
| Question | How we answered it | Result |
|---|---|---|
| Did we have all the sign-ins? | Grouped by isInteractive | No: the first export was interactive only. Fixed the filter |
| Which sessions were the attacker's? | Grouped by sessionId, looked at originalTransferMethod | Two attack sessions; the other two device-code sessions were my own admin tooling |
| Did any alert catch it? | Checked CA status and sign-in risk | No: CA succeeded, risk was none, on every sign-in |
| Were there rogue devices? | Listed the user's devices, compared on every signal | Five Entra-joined devices, all disabled as evidence |
| Did the session touch the mailbox? | Searched the audit log for the session ID | Yes: the rule and mailbox access; sends tied in by time, client, and source |
| Was anyone else hit? | Tenant-wide device-code and device-name checks | Not within the evidence collected |
Next: How the Front Door Opened
Every session in this post started the same way, with a device-code sign-in. Part 3 goes into the flow itself: why a genuine Microsoft sign-in page and genuine MFA can hand an attacker valid tokens, why originalTransferMethod outlives the first sign-in, and how to block the flow with Conditional Access without locking out the devices that legitimately need it.
Found a session in your own logs you can't explain, or want help reading one? Leave a comment below, or get in touch.