incident-response · phishing · entra-id · device-code · identity · threat-hunting

Device-Code Phishing Through a Salesforce Redirect

A Microsoft Entra ID Protection alert landed in our queue for one user: high risk, "activity linked to a compromised user session or stolen token(s)". It looked like a single account. By the end of the day it was several compromised accounts, one failed attempt and a larger group of people who had clicked the same link and gone no further.

We saw no malware in this one. A device-code sign-in succeeded for the user, and around the same time the user's browser loaded a phishing link for a fake app. The likeliest explanation is that the user entered an attacker-supplied code on a real Microsoft page and Microsoft issued the tokens, though we can't prove the code entry. Below we go through the sign-in logs, how a failed sign-in for an app that does not exist ended up as our click counter, and what we would do differently. We removed everything that could identify the customer. Users are not named, the laptop is WS-1, and times are UTC.

The alert

Entra ID Protection raised an investigationsThreatIntelligence risk event with state atRisk, level high, mapped to T1078 (Valid Accounts). The sign-in behind it came from a hosting provider address in California, 172[.]86[.]125[.]122. This user normally signed in from two office networks and from a phone on a mobile carrier.

The alert's correlation ID matched a device-code sign-in in the sign-in logs, and our own rule for device-code authentication to a Microsoft first-party app fired on it too. Across the user's thousands of sign-ins in the previous five days, this was the only one from that address, that network or the device-code flow.

What the attacker did with the account

The Entra sign-in log shows seven attempts from that address in under two minutes, from 10:55:34 to 10:57:11. All of them used the Microsoft Authentication Broker as the client and Microsoft Graph as the resource.

Time Result Device Method
10:55:34 Success WS-1 deviceCode
10:55:48 Error 70000 none none
10:56:11 Error 70000 none none
10:56:20 Error 50132 WS-1 deviceCodeFlow
10:56:20 Error 50199 WS-1 deviceCodeFlow
10:56:45 Success none deviceCodeFlow
10:57:11 Success none deviceCodeFlow

The first row carries the user's own device and session details, with single-factor authentication. Either the user typed the attacker's code into the Microsoft device login page, or something replayed their session. The next section covers why we can't say which. The last two rows are the ones to look at: successful token requests with no device attached, which looks like the attacker's tooling redeeming the code and refreshing it. After 10:57:11 that address never signed in successfully again.

On the error codes, going by Microsoft's reference: 70000 is an invalid grant, 50132 is a session Microsoft no longer treated as valid, and 50199 is the "please confirm this sign-in" prompt.

The timestamps need a note. The Office 365 audit log has a UserLoggedIn event for the same correlation ID at 10:54:42, plus a failed UserLoginFailed at 10:54:28 with error 50199 (CmsiInterrupt, the "please confirm this sign-in" step). The Entra sign-in log stamps that correlation ID about a minute later, at 10:55:34. We have no explanation for the gap. The user's first failed sign-in on the phishing app, which is the click we describe below, is at 10:55:03, between the two times. If the order was click, then code, that fits the later time better, but we can't settle it, and the table uses the sign-in log times. The durations in the text below are measured from the 10:54:42 time the alert carries.

The IT team revoked the user's refresh tokens at 11:01:10 and disabled the account at 11:02:13, about seven and a half minutes after the flagged sign-in. In those minutes the attacker got tokens. That is as far as we can go with certainty.

How the user got there

The sign-in record has the user's own device name, device ID, session ID and an Edge user agent, and it shows a primary refresh token as the incoming token type. That looks like the user's own live session. In the Office 365 audit log, the same session ID was reading mail from the office address seconds later.

Two stories fit. Someone replayed a session that was already open on the PC, or the user entered a code the attacker had generated and the device details came along because the user's own browser did the sign-in. The logs can't separate them. Our sensor on WS-1 saw no connection to the attacker address between 10:20 and 11:10, and no malware or script activity. Out of thousands of DNS and process events, it showed only management agents, group-policy scripts and the user's browser and collaboration apps. That leans toward the second story, since the device-code flow never touches the endpoint, but it doesn't prove it. We asked the customer to ask the user whether they entered a code at the device login page around 10:54, and we never got an answer. Whether the user entered the code is still an inference.

The sign-in logs do show the click. This user has two failed sign-ins for the attacker's app, at 10:55:03 and 10:57:07, both from the user's own office address. That is the user's browser loading the link, so the lure is direct evidence and not a guess. It doesn't show a code being entered.

We don't know what message carried the link. The only lead is in the mailbox. Five messages were moved to Deleted Items during the incident, all from the user's own PC and office address. The first was at 10:56:10, about 90 seconds after the 10:54:42 flagged sign-in, and its subject read like an automatic audio transcript notification. Fake voicemails and transcripts are a common way to deliver a link or a code, so we asked the customer to look at it. It could also be routine cleanup, and the PC runs a legitimate phone app that sends messages like that. We never saw the sender or any link, and the case has no reply on it, so we can't say whether it was the lure.

The IT team found the phishing email while hunting for the source, reported it to Microsoft and blocked the URL tenant-wide. They didn't tell us the subject or sender, so we can't tie it to any message in the compromised mailboxes. The link itself looked like this, shortened:

hxxps://login[.]microsoft[.]com/common/oauth2/v2.0/authorize
  ?state=<random>
  &scope=openid+profile+https://graph.microsoft.com/User.Read
  &prompt=none
  &client_id=dbf0cdb7-72e8-42db-add6-946fe1e0a3d7
  &uri=https://developer[.]salesforce[.]com/dashboard/session/user/verify/step1&...

It is a real Microsoft sign-in URL on a real Microsoft host, so it survives a quick look and most reputation checks. The client_id belongs to an app registered in the attacker's own tenant. Entra won't sign anyone in to an app that was never added to their tenant, so it logs a failed sign-in with error 7000229. The link's uri parameter points at a page under developer[.]salesforce[.]com/dashboard/, which the IT team understood to be where the phishing code was shown. That chain comes from their copy of the link. We never captured the page or saw a redirect, and uri is not the standard OAuth redirect_uri parameter, so we can't explain from our data how a failed 7000229 sign-in hands the user on to that page. The rest of the link was several hundred characters of URL-encoded text that reads like gibberish. We don't know what it's for. It might be padding to push the useful part out of a truncated preview, or to throw off pattern matching.

We did not open the Salesforce page, so we can't say whether it was genuine Salesforce content or attacker content.

The app didn't give the attacker access. As far as we can tell it only exists to get the user to the page. The actual sign-ins went through Microsoft's own Authentication Broker using a device code. The customer asked us to get the app taken down, and there is nothing to take down on their side because the app lives in the attacker's tenant. The way to act on it is to report it to Microsoft. We filed reports for both app IDs and have not seen an outcome.

A second link turned up later the same day with the same structure and a different client_id, 830f9634-1547-4143-861f-2c5342052c88. We saw no sign-ins to it. In the copy the customer captured, the path after the host also began with a long run of extra slashes, which may be another try at slipping past URL matching. We saw that only in the second link. Blocking the first URL did nothing about the second, and an attacker with a spare app registration can make another in minutes.

A third unfamiliar app turned up later that evening, and nobody had flagged it. It is a single failed 7000229 sign-in at 18:31 from a user's office address, on an app named uhygf, another keyboard mash. It appears nowhere else in 29 days of sign-in logs. We think it belongs to the same campaign, but we never saw the link that led to it. In the 18 hours that followed, that user's sign-ins show no device-code flow and none from the attacker's address.

Counting the clicks

Every click on either link leaves a failed sign-in in the victim tenant for an app the tenant has never heard of. The first app was named hjfgjhf, which is a keyboard mash, and it logged error 7000229 every time. So "who clicked" became a one-line search.

We swept the customer's sign-in and Office 365 logs from five days before the alert through the afternoon of the following day.

Group Accounts What we saw
Signed in by the attacker Multiple Device-code sign-in from the same hosting address
Attempted, did not finish One A device-code attempt at 12:36 that never completed
Clicked, no attacker sign-in Many Failed 7000229 sign-in only

The first compromised account was the original alert at 10:54. The attacker reached the others over the next two hours, starting at 12:11, from the same address and with the same device-code flow each time.

The earliest click in the window we searched was at 00:31, more than ten hours before the first compromise, so the campaign was live well before the alert. Every compromised account shows at least one click from the user's own address, and several show more than one. The clicks and the attacker's sign-ins interleave, so we can't say the click always came first.

The attempt that didn't finish was on another account at 12:36. That account wasn't on the IT team's first list of remediated users, so we added it to the reset.

The IT team later built a second list from the same failed sign-ins on the unknown app. It matched the accounts we found, the unfinished attempt included. The IT team also named one more user as affected. In our data that account had no click and no sign-in from the attacker's address, though Entra later rated it medium risk. In fact the sign-in log has no entries for it at all between 10:00 and 16:00. A different user with a very similar name clicked at 12:26 and then signed in normally from their own address for the rest of that window. That fits the customer meaning the second user, but they never confirmed it.

We found no other sign-ins from the attacker's address or its hosting network anywhere in the tenant, and no other suspicious device-code sign-ins in that period. The only Office 365 activity from the attacker's address was the sign-ins.

What we could and couldn't see

On every compromised account we looked for the usual persistence: new inbox rules, mail forwarding, mailbox permission changes, device registration, MFA method registration and app consent. We found none. Mailbox reads in the window came from the office addresses, and nothing touched OneDrive or SharePoint from the attacker's address.

We can't see what the stolen tokens were used for. The LimaCharlie adapters don't receive Microsoft's Graph activity logs, so a mail read or file download made straight through the Graph API with those tokens never shows up for us. For most of the compromised accounts we asked the customer to check Microsoft's own logs for the times above. Our clean result is only a clean result for what we can see.

Containment, and a re-enable

The IT team disabled and revoked quickly, and after 10:57:11 the attacker never signed in successfully. The next day, from 07:13 to 14:15 UTC, the same address kept trying to sign in as the compromised accounts about once a minute, hundreds of attempts per account. Every one failed, and we saw none against the account of the unfinished attempt. The failures show the remediation was holding. We read them as the attacker retrying the stolen tokens for hours, though we can't see the attacker's intent. We asked the customer to block the address in Conditional Access or at the firewall.

The first user's account has one more detail. It was disabled at 11:02, re-enabled at 11:13 by a directory sync account, and disabled again at 11:43. The audit log adds some detail. The 11:02 disable was done by a cloud app, not by the sync account. The 11:13:56 enable came from the sync user account, nine seconds after a cloud sync import for the user. The user was also removed from a group at 11:02:42, added back at 11:14:53 and removed again at 11:45:03. Together that fits the sync service pushing an enabled on-premises state back up after a cloud-only disable. We can't see the on-premises object, so we haven't confirmed it. During those 30 minutes the account had dozens of successful sign-ins, all from the user's own phone and PC, and a session revocation followed at 11:55. In a hybrid environment, disable the account at its source too.

The blocklist

While hunting for the first email, the IT team blocked a long list of sender addresses. When we compared it with our data, most of the addresses the clicking users signed in from were on it, including the customer's own office addresses, along with several addresses that look like Microsoft mail servers. So a good part of the list was the victims' addresses, not senders. It did not include the attacker's address. We told them to recheck it before it broke normal traffic. A list of IPs that sit near the bad email mixes senders, relays and victims. Build it from an indicator you can prove, which here was the sign-in address, and check it against your own egress and your vendors' ranges before you push it.

  • Block the device-code flow with a Conditional Access policy (Conditions, then Authentication flows). A few accounts use it legitimately, such as shared Teams room devices and IT staff running the Azure CLI or Exchange PowerShell, so they need exceptions. We offered to pull that list from the sign-in logs so the exclusions come from actual use.
  • Reset passwords, re-register MFA and revoke sessions for the compromised accounts and the one attempt. MFA re-registration for some of them came from their normal addresses, which fits the IT team's reset.
  • Ask the users who clicked whether they entered a code at the device login page, and reset anyone who isn't sure.
  • Block the attacker address and both redirect links, but don't rely on the links. They are easy to replace.
  • Report every app you find to Microsoft with its app ID and the URLs, and search for new unfamiliar app IDs after you block the first ones.

Detections worth building

These are hunt ideas from this case. We haven't tested them as rules in other environments, and the first will be noisy until you tune it.

  1. Failed sign-in with error 7000229 for an app that isn't in your tenant. One of these can be a stale bookmark. Several users hitting the same unknown app ID in a short time is a click log for a campaign. In this case it found every account that had clicked, and most of them had no other signal in our data.
  2. Device-code sign-in from an address the user has never used. Look at authenticationProtocol of deviceCode and originalTransferMethod of deviceCodeFlow, especially from a hosting network with single-factor authentication.
  3. Successful sign-ins with no device attached right after a device-code success. Here it was two token requests within about two minutes of the first success.
  4. Failed sign-ins about once a minute from one address across several accounts after you revoke sessions. We assume that is the attacker retrying stolen tokens, and it is a cheap thing to block.
  5. A disabled account that gets enabled by a sync account within the hour, during an incident.

On timing: our own device-code rule fired at 10:57:36, about two minutes after the sign-in. Microsoft detected the same sign-in offline, after it happened, and its risk alert reached our queue at 12:43, about an hour and three quarters later. We don't know when Microsoft first raised the risk on its side. The failed 7000229 sign-ins began at the first click, so they would have shown the campaign sooner than either.

Indicators

Network indicators are defanged. Don't browse to them. The Salesforce path is listed so you can search your own logs, not because the site is malicious.

Type Value Note
IP 172[.]86[.]125[.]122 Device-code sign-ins, then repeated failed attempts. Hosting provider, California
App ID dbf0cdb7-72e8-42db-add6-946fe1e0a3d7 Attacker-registered app named hjfgjhf, error 7000229 in the victim tenant
App ID 830f9634-1547-4143-861f-2c5342052c88 Second link, same structure. No sign-ins seen
App ID a1465cda-b715-46de-9833-ebbf53fcc7a4 App named uhygf, one error 7000229 click that evening. Probably the same campaign, link not seen
URL path developer[.]salesforce[.]com/dashboard/session/user/verify/step1 Named in the uri parameter of both links
Sign-in error 7000229 Click on either link

References