Query Details

Tifcepillar4 Data

Query

// ================================================
// TIFCE Pillar 4: Feed Freshness
//
// Purpose:
// - Measure how recently each feed added or updated IOCs.
// - Blend recency and IOC addition velocity into a freshness score.
// ================================================
let FreshnessLookback = 30d;
// Indicator versions older than this are ignored; align it with the table's retention
let TILookback = 90d;
let CanonicalIOC = (iocType:string, iocValue:string) {
    strcat(tolower(trim(" ", iocType)), ":", tolower(trim(" ", iocValue)))
};
// -----------------------------
// Build per-feed IOC first/last seen state
// -----------------------------
let FeedIOCState =
    ThreatIntelIndicators
    | where TimeGenerated > ago(TILookback)
    // Each update writes a new row; keep only the latest version of each indicator,
    // remembering when its first version was seen
    | summarize arg_max(TimeGenerated, *), FirstVersionTime = min(TimeGenerated) by Id
    | where IsDeleted == false
    | where isnotempty(SourceSystem) and isnotempty(ObservableKey) and isnotempty(ObservableValue)
    | extend TIFeed = tostring(SourceSystem)
    | extend IOCTypeRaw = tostring(split(ObservableKey, ":", 0))
    | extend IOCType = replace_regex(tolower(trim(" ", IOCTypeRaw)), @"[\[\]""']", "")
    | extend IOC = CanonicalIOC(IOCType, tostring(ObservableValue))
    | extend CreatedTime = coalesce(
        todatetime(column_ifexists("Created", datetime(null))),
        FirstVersionTime
      )
    | extend UpdatedTime = coalesce(
        todatetime(column_ifexists("Modified", datetime(null))),
        todatetime(column_ifexists("LastUpdatedTime", datetime(null))),
        CreatedTime,
        TimeGenerated
      )
    | summarize
        FirstSeen = min(CreatedTime),
        LastSeen  = max(UpdatedTime)
      by TIFeed, IOC;
// -----------------------------
// Aggregate freshness metrics per feed
// -----------------------------
FeedIOCState
| extend IOCAgeDays = datetime_diff("day", now(), FirstSeen)
| summarize
    TotalDistinctIOCs   = count(),
    LastNewIOC          = max(FirstSeen),
    LastFeedActivity    = max(LastSeen),
    NewIOCsLast7d       = countif(FirstSeen > ago(7d)),
    NewIOCsLast30d      = countif(FirstSeen > ago(FreshnessLookback)),
    UpdatedIOCsLast7d   = countif(LastSeen > ago(7d)),
    UpdatedIOCsLast30d  = countif(LastSeen > ago(FreshnessLookback)),
    AvgIOCAgeDays       = round(avg(todouble(IOCAgeDays)), 1),
    P50IOCAgeDays       = toint(percentile(IOCAgeDays, 50))
  by TIFeed
| extend
    DaysSinceLastNewIOC   = datetime_diff("day", now(), LastNewIOC),
    DaysSinceLastActivity = datetime_diff("day", now(), LastFeedActivity)
// Recency favors recently active feeds; velocity favors feeds adding many new IOCs.
| extend
    FreshPctRecent = round(
        iif(TotalDistinctIOCs > 0, 100.0 * todouble(NewIOCsLast30d) / todouble(TotalDistinctIOCs), 0.0),
        2
    ),
    RecencyComponent = case(
        DaysSinceLastActivity <= 1, 100.0,
        DaysSinceLastActivity <= 7, 80.0,
        DaysSinceLastActivity <= 30, 50.0,
        DaysSinceLastActivity <= 90, 20.0,
        0.0
    ),
    VelocityComponent = iif(
        TotalDistinctIOCs > 0,
        100.0 * todouble(NewIOCsLast30d) / todouble(TotalDistinctIOCs),
        0.0
    )
// Weighted score emphasizes recency (60%) over velocity (40%).
| extend
    FreshnessScore = round(0.6 * RecencyComponent + 0.4 * VelocityComponent, 2),
    FreshnessStatus = case(
        DaysSinceLastActivity <= 1, "Very Fresh (daily activity)",
        DaysSinceLastActivity <= 7, "Fresh (weekly activity)",
        DaysSinceLastActivity <= 30, "Moderately Fresh",
        "Stale / Inactive (>30 days since activity)"
    )
| order by FreshnessScore desc, DaysSinceLastActivity asc
| project
    Feed = TIFeed,
    TotalDistinctIOCs,
    FreshnessScore,
    NewIOCsLast7d,
    NewIOCsLast30d,
    UpdatedIOCsLast7d,
    UpdatedIOCsLast30d,
    DaysSinceLastNewIOC,
    DaysSinceLastActivity,
    AvgIOCAgeDays,
    P50IOCAgeDays,
    FreshPctRecent,
    LastNewIOC,
    LastFeedActivity,
    FreshnessStatus

About this query

// ================================================
// TIFCE Pillar 4: New IOCs per day
//
// Purpose:
// - Chart how many indicators each feed adds per day.
// - Days without new indicators are plotted as zero, so a feed that has
//   stopped delivering shows up before its freshness status turns stale.
// ================================================
// Indicator versions older than this are ignored; align it with the table's retention
let TILookback = 90d;
// Chart window when run standalone; the workbook uses its Time Range picker
let ChartStart = ago(30d);
let ChartEnd = now();
ThreatIntelIndicators
| where TimeGenerated > ago(TILookback)
// Each update writes a new row; keep only the latest version of each indicator,
// remembering when its first version was seen
| summarize arg_max(TimeGenerated, *), FirstVersionTime = min(TimeGenerated) by Id
| where isnotempty(SourceSystem)
| extend AddedTime = coalesce(todatetime(column_ifexists("Created", datetime(null))), FirstVersionTime)
| where AddedTime between (ChartStart .. ChartEnd)
| make-series NewIOCs = count() default = 0 on AddedTime from bin(ChartStart, 1d) to ChartEnd step 1d by Feed = tostring(SourceSystem)

Explanation

This KQL script is designed to analyze and measure the "freshness" of threat intelligence feeds by evaluating how recently they have added or updated Indicators of Compromise (IOCs). Here's a simplified breakdown of what the query does:

Part 1: Feed Freshness

  1. Setup and Definitions:

    • Defines a lookback period of 30 days for freshness and 90 days for indicator retention.
    • Establishes a function to create a standardized format for IOCs.
  2. Building IOC State:

    • Filters threat intelligence indicators to only include those generated within the last 90 days.
    • Keeps only the latest version of each IOC and records when it was first seen.
    • Extracts relevant fields and calculates the first and last seen times for each IOC per feed.
  3. Calculating Freshness Metrics:

    • Computes various metrics for each feed, such as the total number of distinct IOCs, the number of new and updated IOCs in the last 7 and 30 days, and the average age of IOCs.
    • Calculates the number of days since the last new IOC and the last activity for each feed.
  4. Scoring and Status:

    • Calculates a freshness score for each feed, emphasizing recent activity (60%) over the velocity of new IOC additions (40%).
    • Assigns a freshness status based on the recency of activity, categorizing feeds as "Very Fresh," "Fresh," "Moderately Fresh," or "Stale/Inactive."
  5. Output:

    • Orders feeds by their freshness score and projects relevant metrics for analysis.

Part 2: New IOCs per Day

  1. Setup:

    • Defines a 90-day lookback period for indicator retention and a 30-day window for charting.
  2. Daily IOC Addition:

    • Filters indicators to include only those generated within the last 90 days.
    • Summarizes the number of new IOCs added each day for each feed.
    • Uses a time series to plot daily additions, filling in days with zero new IOCs to highlight periods of inactivity.

Overall, this query helps security analysts understand the activity and effectiveness of their threat intelligence feeds by providing insights into how frequently new threat data is being added and updated.