Query Details
// Hunt : M365 - Teams Messages with External Links Sent by Guests (30d)
// Purpose : Enumerate all Teams messages containing external URLs sent by guest
// users over 30 days. Supports phishing campaign investigation,
// C2 link distribution analysis, and guest account compromise review.
// Tables : OfficeActivity
// Period : P30D
//==========================================================================================
let LookbackDays = 30d;
let SuspiciousUrlPatterns = dynamic([
"bit.ly", "tinyurl", "t.co", "ow.ly", "goo.gl",
"ngrok.io", "loca.lt", "serveo.net",
"pastebin", "hastebin", "repl.it", "glitch.me"
]);
OfficeActivity
| where TimeGenerated > ago(LookbackDays)
| where RecordType == "MicrosoftTeams"
| where Operation in ("MessageCreatedHasLink", "MessageCreated")
| where UserId has "#EXT#" // guest accounts only
| extend MessageText = coalesce(tostring(ExtraProperties[0].Value), tostring(ItemName))
| extend ChannelLower = tolower(ChannelName)
| extend
IsSuspiciousUrl = MessageText has_any (SuspiciousUrlPatterns),
GuestDomain = tostring(extract(@"#EXT#@(.+)", 1, UserId))
| summarize
MessageCount = count(),
SuspiciousLinks = countif(IsSuspiciousUrl),
Teams = make_set(TeamName, 10),
Channels = make_set(ChannelName, 10),
URLSample = make_set(MessageText, 10),
ClientIPs = make_set(ClientIP, 5),
FirstMessage = min(TimeGenerated),
LastMessage = max(TimeGenerated)
by UserId, GuestDomain
| sort by SuspiciousLinks desc, MessageCount desc
| project
UserId,
GuestDomain,
MessageCount,
SuspiciousLinks,
Teams,
Channels,
URLSample,
ClientIPs,
FirstMessage,
LastMessage
This query is designed to identify and analyze Microsoft Teams messages that contain external URLs sent by guest users over the past 30 days. Here's a simplified breakdown of what the query does:
Time Frame: It looks at data from the last 30 days.
Suspicious URLs: It defines a list of suspicious URL patterns, such as shortened links (e.g., bit.ly, tinyurl) and other potentially risky domains.
Data Source: The query examines the OfficeActivity table, focusing on records related to Microsoft Teams messages.
Guest Users: It filters for messages sent by guest users, identified by the presence of "#EXT#" in their user ID.
Message Analysis:
Summary Statistics:
Sorting and Output:
This query is useful for investigating potential phishing campaigns, command-and-control (C2) link distribution, and reviewing possible guest account compromises in Microsoft Teams.

David Alonso
Released: March 18, 2026
Tables
Keywords
Operators