Query Details
let CorporateCloudflareAccountID = "your_cloudflare_account_id";
union DeviceProcessEvents
| where ProcessCommandLine contains "tunnel run" and ProcessCommandLine contains "--token" // OS agnostic, handles renamed executables
| extend HalfTrim = trim_start('.*--token ', ProcessCommandLine)
| extend CloudflaredToken = parse_json(base64_decode_tostring(trim_end(' .*', HalfTrim)))
| extend CloudflareAccountID = CloudflaredToken.a
| project-away HalfTrim
| where CloudflareAccountID != CorporateCloudflareAccountIDThis query is designed to identify potential unauthorized use of Cloudflare tunnels on devices within an organization. Here's a simplified breakdown of what it does:
Define a Variable: It sets a variable CorporateCloudflareAccountID to represent the organization's official Cloudflare account ID.
Search for Processes: It searches through DeviceProcessEvents to find any process command lines that include the phrases "tunnel run" and "--token". This indicates that a Cloudflare tunnel is being run, and a token is being used.
Extract Token Information:
Identify Account ID: From the parsed token information, it extracts the CloudflareAccountID.
Filter Results: It filters out any processes where the CloudflareAccountID matches the organization's official account ID (CorporateCloudflareAccountID), leaving only those that do not match.
In summary, this query helps to detect any Cloudflare tunnel activities on devices that are not using the organization's official Cloudflare account, which could indicate unauthorized or suspicious activity.

C.J. May
Released: June 20, 2025
Tables
Keywords
Operators