Query Details
// Overview of detected token artifacts by Exposure Management
// Hunting query to get list of PRT, Session Cookies and CLI authentication artifacts
// with details of endpoint security posture.
let PrimaryRefresh = ExposureGraphEdges
| where EdgeLabel == @"has credentials of"
| join kind = inner (
ExposureGraphNodes
| project NodeId, RawData = parse_json(NodeProperties)["rawData"], EntityIds
) on $left.SourceNodeId == $right.NodeId
| where parse_json(EdgeProperties)["rawData"]["primaryRefreshToken"]["primaryRefreshToken"] == 'true'
| extend TokenType = tostring(parse_json(EdgeProperties)["rawData"]["primaryRefreshToken"]["type"])
| project EdgeId, SourceNodeId, SourceNodeName, SourceNodeLabel, EdgeLabel, TargetNodeId, TargetNodeName, TokenType, RawData, EntityIds;
let SessionCookie = ExposureGraphNodes
// Accessing Azure Portal from this device as secondary user (seperated profile)
| where NodeLabel == "entra-userCookie"
| extend AccountObjectId = tostring(parse_json(NodeProperties)["rawData"]["entraCookiesSecretData"]["entraObjectId"])
| join kind=inner ( ExposureGraphNodes
| extend AccountObjectId = tostring(parse_json(NodeProperties)["rawData"]["accountObjectId"])
| project UserNodeId = NodeId, UserNodeName = NodeName, AccountObjectId
) on AccountObjectId
| join kind=inner (
ExposureGraphEdges
) on $left.NodeId == $right.TargetNodeId
| extend TokenType = tostring(parse_json(NodeProperties)["rawData"]["entraCookiesSecretData"]["type"])
| project EdgeId, SourceNodeId, SourceNodeName, SourceNodeLabel, EdgeLabel, TargetNodeId = UserNodeId, TargetNodeName = UserNodeName, TokenType, TokenNodeId = TargetNodeId, TokenNodeName = TargetNodeName, RawData = parse_json(NodeProperties)["rawData"], EntityIds;
let AzureCliToken = ExposureGraphNodes
// RT and AT in Azure CLI e.g., privileged account not primary user but will be used on this device
| where NodeLabel == "user-azure-cli-secret"
| extend AccountSid = tostring(parse_json(NodeProperties)["rawData"]["userAzureCliSecretData"]["userSid"])
| join kind=inner ( ExposureGraphNodes
| extend AccountSid = tostring(parse_json(NodeProperties)["rawData"]["aadSid"])
| project UserNodeId = NodeId, UserNodeName = NodeName, AccountSid
) on AccountSid
| join kind=inner (
ExposureGraphEdges
) on $left.NodeId == $right.TargetNodeId
| extend TokenType = tostring(parse_json(NodeProperties)["rawData"]["userAzureCliSecretData"]["type"])
| project EdgeId, SourceNodeId, SourceNodeName, SourceNodeLabel, EdgeLabel, TargetNodeId = UserNodeId, TargetNodeName = UserNodeName, TokenType, TokenNodeId = TargetNodeId, TokenNodeName = TargetNodeName, RawData = parse_json(NodeProperties)["rawData"];
union PrimaryRefresh, SessionCookie, AzureCliToken
// Enrichment to MDE insights
| mv-apply EntityIds = parse_json(EntityIds) on (
where EntityIds.type =~ "DeviceInventoryId"
| extend DeviceId = tostring(EntityIds.id)
)
| extend HighRiskVulnerability = iff(parse_json(RawData)["highRiskVulnerabilityInsights"]["hasHighOrCritical"] == 'true', true, false)
| extend CredentialGuard = iff(parse_json(RawData)["hasGuardMisconfigurations"] has 'Credential Guard', false, true)
| summarize TokenArtifacts = make_list(TokenType) by
User = TargetNodeName,
Device = SourceNodeName,
DeviceId,
PublicIP = tostring(parse_json(RawData)["publicIP"]),
ExposureScore = tostring(parse_json(RawData)["exposureScore"]),
RiskScore = tostring(parse_json(RawData)["riskScore"]),
HighRiskOrCriticalVulnerability = tostring(HighRiskVulnerability),
MaxCvssScore = tostring(parse_json(RawData)["highRiskVulnerabilityInsights"]["maxCvssScore"]),
AllowedRDP = tostring(parse_json(RawData)["rdpStatus"]["allowConnections"]),
CredentialGuard = tostring(CredentialGuard),
TpmActivated = tostring(parse_json(RawData)["tpmData"]["activated"])
| join kind = leftouter ( AlertEvidence
| where isnotempty(DeviceId)
| summarize Alerts = make_set(Title), AlertCategories = make_set(Categories) by DeviceId
) on DeviceId
| project-away DeviceId1This query is designed to provide an overview of detected token artifacts related to security exposure management. It focuses on identifying and detailing three types of authentication artifacts: Primary Refresh Tokens (PRT), Session Cookies, and Azure CLI tokens. Here's a simplified breakdown of what the query does:
Primary Refresh Tokens (PRT):
Session Cookies:
Azure CLI Tokens:
Combining Results:
Enrichment with Device Insights:
Summarization:
Alert Integration:
The final output provides a comprehensive view of token artifacts and their associated security posture, helping security teams assess potential risks and vulnerabilities.

Thomas Naunheim
Released: March 5, 2025
Tables
Keywords
Operators