Sitemap
Detect FYI

Threat Detection Engineering and DFIR Insights

๐Ÿ”Ž ๐—ž๐—ค๐—Ÿ ๐—ผ๐—ณ ๐˜๐—ต๐—ฒ ๐—ช๐—ฒ๐—ฒ๐—ธ | ๐—›๐˜‚๐—ป๐˜๐—ถ๐—ป๐—ด ๐—ณ๐—ผ๐—ฟ ๐—ฆ๐˜‚๐˜€๐—ฝ๐—ถ๐—ฐ๐—ถ๐—ผ๐˜‚๐˜€ ๐—–๐—น๐—ถ๐—ฒ๐—ป๐˜ ๐—ฆ๐—ฒ๐—ฐ๐—ฟ๐—ฒ๐˜ ๐—”๐˜‚๐˜๐—ต๐—ฒ๐—ป๐˜๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—”๐˜๐˜๐—ฒ๐—บ๐—ฝ๐˜๐˜€

3 min read5 days ago

--

Press enter or click to view image in full size

After a few weeks away, happy to be back in the hunting field, full of energy! ๐Ÿ”Ž๐Ÿ”ฅ

When we talk about compromised identities in Microsoft Entra ID, we usually think about stolen passwords, compromised sessions, MFA bypass techniques, or suspicious user sign-ins. But what happens when the attacker doesnโ€™t need a user account at all?

A recent investigation published by Todyl ๐Ÿ”— describes a campaign where attackers are using stolen application credentials, specifically client secrets, to authenticate against Microsoft Entra ID as legitimate applications.

Get Sergio Albeaโ€™s stories inย yourย inbox

Join Medium for free to get updates fromย thisย writer.

Depending on the permissions assigned to the compromised application, an attacker could potentially access Microsoft Graph, Azure resources, Key Vault, SharePoint, or other services. And in some environments, these applications could have permissions that were granted years ago and havenโ€™t been reviewed since.

Looking for invalid and expired client secrets

As usual, I will not work or mention IOCs (Indicators of Compromise) as the IPs mentioned in the article because they can be easily rotated to new ones so a query would end obsolete. Focus on IOA (Indicators of Attack), one of the hunting opportunities mentioned in the investigation is looking at authentication failures involving application secrets. There are two Entra ID error codes worth checking:

  • AADSTS7000215: Invalid client secret.
  • AADSTS7000222: Expired client secret.

Of course, these errors are not automatically suspicious. Applications with outdated configurations, forgotten secret rotations, or deployment mistakes can generate exactly the same errors.

Assessing the Risk: Here is the key, more insights, will help to know the risk score for every results with the mentioned Entra ID Error codes. The source IP, the application involved, the frequency of the failures, and whether there are successful authentications from the same IP or involving the same application.

Hunting with KQL in Microsoft Defender XDR

For this hunt, Iโ€™m using two tables:

  • EntraIdSignInEvents โ€” Entra ID sign-in events.
  • EntraIdSpnSignInEvents โ€” Service principal sign-in events.

The idea is simple: search both tables for the two error codes over the last seven days, combine the results, and identify which table each event came from.

let UserSignIns = EntraIdSignInEvents | where Timestamp > ago(7d) | where ErrorCode in (7000215, 7000222) | project Timestamp, SourceTable = "UserSignIns", Application, IPAddress, Country, ErrorCode;
let SpnSignIns = EntraIdSpnSignInEvents | where Timestamp > ago(7d) | where ErrorCode in (7000215, 7000222) | project Timestamp, SourceTable = "ServicePrincipalSignIns", Application, IPAddress, Country, ErrorCode;
union UserSignIns, SpnSignIns
| extend ErrorDescription = case(ErrorCode == 7000215, "Invalid client secret", ErrorCode == 7000222, "Expired client secret", "Other")

This is a starting point, not a detection that should immediately generate an incident for every result. I would first review the applications involved, identify unusual source IP addresses, and check whether those same applications or IPs have successful sign-ins around the same period.

If something looks interesting, the next step would be reviewing the applicationโ€™s permissions and the resources accessed after authentication.

One detail worth remembering: Service Principals

Something I wanted to highlight with this query is the importance of including service principals in our identity hunting activities. We spend a lot of time developing detections for regular Entra ID users but if your organization uses service principals, they are also part of your identity environment.

Iโ€™m not suggesting that every detection developed for users should also run against service principals. Their authentication behavior is different, and some detection techniques simply donโ€™t apply. However, when developing a new identity-related detection, itโ€™s worth asking whether service principal activity should also be included.

Anyway, an interesting investigation and a good excuse to review how weโ€™re monitoring application authentication in our environments.

Original research: Todyl โ€” Stolen App Credentials, Real Access: An Actor Is Signing Into Entra ID and Azure DevOps as Your Workloads

--

--

Written by Sergio Albea

Microsoft Security MVP - Threat Hunter Researcher ๐Ÿ“˜ CYBER HUNTER Project โฌ‡๏ธ www.amazon.com/dp/B0HHQQLTFH ๐Ÿ“ linkedin.com/in/sergioalbea/

Published in Detect FYI

Threat Detection Engineering and DFIR Insights