Handling sliding windows in Azure Sentinel rules

Published Jul 06 2020 11:09 AM 4,993 Views
Microsoft

In the article "Azure Sentinel correlation rules: Active Lists out; make_list() in," I presented a rule that detects several sign-in failures to Azure AD, alongside a sign-in success to AWS from the same IP address. An inherent challenge with the rule was that the time window is defined by rule execution: if the rule is executed every hour, and an attack is split across two rule executions, no alert will be triggered.

 

In this blog post, we will see how to modify this rule to analyze a sliding time window and work across rule execution boundaries. While enhancing the rule time window support, we will also add support for delayed events.

 

This post of part of a series of blog posts on writing rules in Azure Sentinel:

 

Defining the sliding window

 

Let start with defining the time variables for the detection:

let rule_frequency = 1h; // how often is the rule executed
let max_session = 24h; // the maximum length of a detected session
let aad_delay = 1h; // the maximum delay we anticipate for events for each source
let aws_delay = 1h;

 

The rule attempts to detect a sequence of events (1), let's call them a session, that took less than "max_session" and of which the last occurred within the current rule run (2). When events are expected to be delayed, we will still look for such a session (3) but require that the last event was ingested (4) within the current rule run.

 

2020-07-06 15_32_11-Clipboard.png

 

The rest is just the mechanics of how to do the above.

 

Filtering the relevant AAD events

 

The rule logic itself starts, as did the simpler version, with filtering Azure AD Sign-in failures. However, if the original version did not explicitly filter on time, this one adds a time condition (green). The time condition goes back as much as needed to capture sessions that ended at the beginning of the current run window, even if delayed.

 

let signin_threshold = 5;
let suspicious_signins = 
SigninLogs
| where TimeGenerated > ago (max_session + rule_frequency + aad_delay)
| where ResultType !in ("0", "50125", "50140")
| where IPAddress != "127.0.0.1"

 

Identifying AAD failure sessions

 

Next comes the KQL magic that makes sliding windows detection easy:

  • The operator row_window_session (green) searches for sessions: sequences of events no longer than max_session. It adds to each event a field, aad_first_time, which includes the time of the first event in the session and would be the same for all events in the session.
  • To prepare the data for row_window_session, we sorted (red) as the operator expected sorted input. In this case, we sort by IP address, in addition to time, to ensure sessions are specific to a source IP address.
  • Lastly, we analyze using the operator summarize (blue), the data we need from each session: its length and indicative timestamps.
| sort by IPAddress, TimeGenerated asc
| extend aad_first_time = row_window_session (TimeGenerated, max_session, max_session, IPAddress != prev(IPAddress))
| summarize session_count = count(), aad_last_time = max(TimeGenerated), aad_last_ingest=max(ingestion_time()) by aad_first_time , IPAddress

 

Filtering only relevant sessions

Once we have sessions, we need to check if they indeed indicate a detection:

  • Was the session count above the detection threshold? (red)
  • Did the session end within the latest rule execution, adjusted to an ingestion delay? (blue)

The last line, project-rename, is just makeup. It renames IPAddress to make it easy to identify it as the AAD failure session IP address. This comes in handy after the join when multiple tables add their fields to the result set.

 

| where session_count >= signin_threshold
| where aad_last_time > ago (rule_frequency + aad_delay)
| project-rename aad_ip_address = IPAddress;

Note that unlike the simpler version, the result of this query part is a table and not a list, and we will use the join operator to correlate it to the AWS events. Why? We need to keep the timestamps and test them after the "join." It would also help us provide more data to the analyst.

 

Want to stop here? the general aggregation case

 

While the rule we explore correlates Azure sign-in failures with a successful sign-in on AWS, the more common form is simple aggregation. i.e., detection more than X events in a time window. The section we already covered address such a general use case, with the following small modifications:

  • Remote the line "let suspicious_signins =" and the semicolon at the end to make this the primary query in the rule.
  • Add the line "| where aad_last_ingest > ago(rule_frequency)" to ensure the session included a new, just ingested, event and therefore was not yet reported on.

 

Matching the sessions to a successful AWS login event

 

After finding successful AWS logins (red), we match them on IP addresses to the sessions we identified earlier using join (blue). For matches, implying we have a session of Azure failures and a successful AWS login for the same address, we test the following:

  • Was any of the events ingested in the latest rule execution window (green)? This ensures the detected attack included new information and was not reported yet. This is the primary means used to support delayed events while avoiding duplicate alerting. 
  • Was the successful AWS event with the time window of the session? (blue). This a simple to implement choice, but not the only one. Other options can also be implemented, such as the AWS success happening after the Azure failure session. Those will require changing this time condition line and may also require extending other timeframes in the query.

 

The "project-rename" and "extend" operators (orange) are again cosmetic only and make the AWS fields easy to use and identify in the joined table.

 

AWSCloudTrail
| where TimeGenerated > ago(max_session + rule_frequency + delay)
| where EventName == "ConsoleLogin"
| extend LoginResult = tostring(parse_json(ResponseElements).ConsoleLogin) 
| where LoginResult == "Success"
| project-rename aws_time = TimeGenerated, aws_ip_address = SourceIpAddress
| extend aws_ingest_time = ingestion_time()
| join suspicious_signins on $left. aws_ip_address == $right.aad_ip_address 
| where max_of(aws_ingest_time, aad_last_ingest) > ago(rule_frequency)
| where aws_time between (aad_first_time ..aad_last_time)

 

That’s it. The rest would be just result and entity preparation.

 

Rule Settings

 

An analytics rule is not just a query. There are several parameters that you need to set to make it work. The two critical ones are:

  • -"Run query every" is the rule execution frequency and should be set to, as expected to "rule_frequency."
  • "Lookup data from the last," or the rule's lookback time, has to be at least as long as the most extended time condition in the rule. This would be max_session + rule_frequency + the length of the delays, aad_delay, and aws_delay.

 

Also, you should configure alert aggregation based on the source IP address. A sliding window-based rule will alert when new events are extending an existing session. While it is possible to suppress such alerting, it adds information, so generating an alert that will be grouped to the same incidents is the best practice. Aggregation should be by IP address and aad_first_time, to which you should allocate one of the unused entities.

 

Summary

Aggregation rules and more advanced relations-based rules require careful consideration of time window management to avoid missing alerts or duplicate alerting. This article provides a recipe that should help you implement such rules correctly using a sliding window analysis.

 

I hope you found it useful!

3 Comments
Occasional Contributor

Very good content, @Ofer_Shezaf  .

Thanks.

I have a doubt.

 

The timegenereted() is the time that the event was generated at the source and is informed in the source payload, right?

 

If for some reason my source does not send the time the log was created, what will be the timegenereted time?

 

If I'm not mistaken, for the MMA collector, if I don't have the timegenereted specified in the log, I'll specify _TimeReceived, which is the time that the log arrived at the installed agent. That's it?

 

What would it be like for firewall logs, for example?

Microsoft

@luizao_lf : you are correct that some sources do not produce a reliable TimeGenerated field. For each of those you will have to pick the correct timestamp. For Firewalls for example, it would differ based on the specific firewall.

Occasional Contributor

If the event is from windows, for example, if you do not have timegenereted () at the source, the value of timegenereted () will be the moment the log arrived at the MMA agent.

 

But what about a firewall that does not have an MMA agent? If the team does not contain the source, what value will be sent in the timegenereted () field? Will it be the value when it arrives at the CEF concentrator? or would it be otherwise?

%3CLINGO-SUB%20id%3D%22lingo-sub-1505394%22%20slang%3D%22en-US%22%3EHandling%20sliding%20windows%20in%20Azure%20Sentinel%20rules%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1505394%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EIn%20the%20article%20%22%3C%2FSPAN%3E%3CA%20class%3D%22_e75a791d-denali-editor-page-rtfLink%22%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-sentinel%2Fazure-sentinel-correlation-rules-active-lists-out-make-list-in%2Fba-p%2F1029225%22%20target%3D%22_blank%22%3E%3CEM%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EAzure%20Sentinel%20correlation%20rules%3A%20Active%20Lists%20out%3B%20make_list()%20in%3C%2FSPAN%3E%3C%2FEM%3E%3C%2FA%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%2C%22%20I%20presented%20a%20rule%20that%20detects%20several%20sign-in%20failures%20to%20Azure%20AD%2C%20alongside%20a%20sign-in%20success%20to%20AWS%20from%20the%20same%20IP%20address.%20An%20inherent%20challenge%20with%20the%20rule%20was%20that%20the%20time%20window%20is%20defined%20by%20rule%20execution%3A%20if%20the%20rule%20is%20executed%20every%20hour%2C%20and%20an%20attack%20is%20split%20across%20two%20rule%20executions%2C%20no%20alert%20will%20be%20triggered.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EIn%20this%20blog%20post%2C%20we%20will%20see%20how%20to%20modify%20this%20rule%20to%20analyze%20a%20sliding%20time%20window%20and%20work%20across%20rule%20execution%20boundaries.%20While%20enhancing%20the%20rule%20time%20window%20support%2C%20we%20will%20also%20add%20support%20for%20delayed%20events.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CFONT%20color%3D%22%23FF00FF%22%3E%3CEM%3EThis%20post%20of%20part%20of%20a%20series%20of%20blog%20posts%20on%20writing%20rules%20in%20Azure%20Sentinel%3A%3C%2FEM%3E%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3E%3CFONT%20color%3D%22%23FF00FF%22%3E%3CEM%3E%3CA%20class%3D%22_e75a791d-denali-editor-page-rtfLink%22%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-sentinel%2Fazure-sentinel-correlation-rules-active-lists-out-make-list-in%2Fba-p%2F1029225%22%20target%3D%22_blank%22%3EAzure%20Sentinel%20correlation%20rules%20using%20lists%3C%2FA%3E%3C%2FEM%3E%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3E%3CFONT%20color%3D%22%23FF00FF%22%3E%3CEM%3E%3CA%20class%3D%22_e75a791d-denali-editor-page-rtfLink%22%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-sentinel%2Fazure-sentinel-correlation-rules-the-join-kql-operator%2Fba-p%2F1041500%22%20target%3D%22_blank%22%3EAzure%20Sentinel%20correlation%20rules%20using%20the%20join%20operator%3C%2FA%3E%3C%2FEM%3E%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3E%3CFONT%20color%3D%22%23FF00FF%22%3E%3CEM%3E%3CA%20class%3D%22_e75a791d-denali-editor-page-rtfLink%22%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-sentinel%2Fimplementing-lookups-in-azure-sentinel-part-1-reference-files%2Fba-p%2F1091306%22%20target%3D%22_blank%22%3EImplementing%20Lookups%20in%20Azure%20Sentinel%3C%2FA%3E%26nbsp%3B%3C%2FEM%3E%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3E%3CFONT%20color%3D%22%23FF00FF%22%3E%3CEM%3E%3CA%20class%3D%22_e75a791d-denali-editor-page-rtfLink%22%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-sentinel%2Fapproximate-partial-and-combined-lookups-in-azure-sentinel%2Fba-p%2F1393795%22%20target%3D%22_blank%22%3EApproximate%2C%20partial%2C%20and%20combined%20lookups%3C%2FA%3E%3C%2FEM%3E%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3E%3CFONT%20color%3D%22%23FF00FF%22%3E%3CEM%3EHandling%20sliding%20windows%20in%20Azure%20Sentinel%20rules%20(this%20post)%3C%2FEM%3E%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1301766198%22%20id%3D%22toc-hId--1301766198%22%20id%3D%22toc-hId--1301766198%22%20id%3D%22toc-hId--1301766198%22%20id%3D%22toc-hId--1301766198%22%20id%3D%22toc-hId--1301766198%22%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EDefining%20the%20sliding%20window%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3ELet%20start%20with%20defining%20the%20time%20variables%20for%20the%20detection%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CPRE%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3Elet%20rule_frequency%20%3D%201h%3B%20%2F%2F%20how%20often%20is%20the%20rule%20executed%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3Elet%20max_session%20%3D%2024h%3B%20%2F%2F%20the%20maximum%20length%20of%20a%20detected%20session%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3Elet%20aad_delay%20%3D%201h%3B%20%2F%2F%20the%20maximum%20delay%20we%20anticipate%20for%20events%20for%20each%20source%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3Elet%20aws_delay%20%3D%201h%3B%3C%2FSPAN%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EThe%20rule%20attempts%20to%20detect%20a%20sequence%20of%20events%20(1)%2C%20let's%20call%20them%20a%20session%2C%20that%20took%20less%20than%20%22%3C%2FSPAN%3E%3CEM%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3Emax_session%3C%2FSPAN%3E%3C%2FEM%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%22%20and%20of%20which%20the%20last%20occurred%20within%20the%20current%20rule%20run%20(2).%20When%20events%20are%20expected%20to%20be%20delayed%2C%20we%20will%20still%20look%20for%20such%20a%20session%20(3)%20but%20require%20that%20the%20last%20event%20was%20ingested%20(4)%20within%20the%20current%20rule%20run.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%222020-07-06%2015_32_11-Clipboard.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F203580i6AE0B36A02433879%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%222020-07-06%2015_32_11-Clipboard.png%22%20alt%3D%222020-07-06%2015_32_11-Clipboard.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EThe%20rest%20is%20just%20the%20mechanics%20of%20how%20to%20do%20the%20above.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1185746635%22%20id%3D%22toc-hId-1185746635%22%20id%3D%22toc-hId-1185746635%22%20id%3D%22toc-hId-1185746635%22%20id%3D%22toc-hId-1185746635%22%20id%3D%22toc-hId-1185746635%22%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EFiltering%20the%20relevant%20AAD%20events%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EThe%20rule%20logic%20itself%20starts%2C%20as%20did%20the%20simpler%20version%2C%20with%20filtering%20Azure%20AD%20Sign-in%20failures.%20However%2C%20if%20the%20original%20version%20did%20not%20explicitly%20filter%20on%20time%2C%20this%20one%20adds%20a%20%3CFONT%20color%3D%22%23008000%22%3Etime%20condition%20(green)%3C%2FFONT%3E.%20The%20time%20condition%20goes%20back%20as%20much%20as%20needed%20to%20capture%20sessions%20that%20ended%20at%20the%20beginning%20of%20the%20current%20run%20window%2C%20even%20if%20delayed.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3Elet%20signin_threshold%20%3D%205%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3Elet%20suspicious_signins%20%3D%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3ESigninLogs%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSTRONG%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%3CFONT%20color%3D%22%23008000%22%3E%7C%20where%20TimeGenerated%20%26gt%3B%20ago%20(max_session%20%2B%20rule_frequency%20%2B%20aad_delay)%3C%2FFONT%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%7C%20where%20ResultType%20!in%20(%220%22%2C%20%2250125%22%2C%20%2250140%22)%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%7C%20where%20IPAddress%20!%3D%20%22127.0.0.1%22%3C%2FSPAN%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--621707828%22%20id%3D%22toc-hId--621707828%22%20id%3D%22toc-hId--621707828%22%20id%3D%22toc-hId--621707828%22%20id%3D%22toc-hId--621707828%22%20id%3D%22toc-hId--621707828%22%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EIdentifying%20AAD%20failure%20sessions%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3ENext%20comes%20the%20KQL%20magic%20that%20makes%20sliding%20windows%20detection%20easy%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EThe%20operator%20%3CFONT%20color%3D%22%23008000%22%3Erow_window_session%20(green)%3C%2FFONT%3E%20searches%20for%20sessions%3A%20sequences%20of%20events%20no%20longer%20than%20max_session.%20It%20adds%20to%20each%20event%20a%20field%2C%20aad_first_time%2C%20which%20includes%20the%20time%20of%20the%20first%20event%20in%20the%20session%20and%20would%20be%20the%20same%20for%20all%20events%20in%20the%20session.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3ETo%20prepare%20the%20data%20for%20row_window_session%2C%20we%20%3CFONT%20color%3D%22%23FF0000%22%3Esorted%20(red)%3C%2FFONT%3E%20as%20the%20operator%20expected%20sorted%20input.%20In%20this%20case%2C%20we%20sort%20by%20IP%20address%2C%20in%20addition%20to%20time%2C%20to%20ensure%20sessions%20are%20specific%20to%20a%20source%20IP%20address.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3ELastly%2C%20we%20analyze%20using%20the%20operator%20%3CFONT%20color%3D%22%230000FF%22%3Esummarize%20(blue)%3C%2FFONT%3E%2C%20the%20data%20we%20need%20from%20each%20session%3A%20its%20length%20and%20indicative%20timestamps.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CPRE%3E%3CFONT%20color%3D%22%23FF0000%22%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%7C%20sort%20by%20IPAddress%2C%20TimeGenerated%20asc%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FFONT%3E%3CFONT%20color%3D%22%23008000%22%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%7C%20extend%20aad_first_time%20%3D%20row_window_session%20(TimeGenerated%2C%20max_session%2C%20max_session%2C%20IPAddress%20!%3D%20prev(IPAddress))%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FFONT%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%3CFONT%20color%3D%22%230000FF%22%3E%7C%20summarize%20session_count%20%3D%20count()%2C%20aad_last_time%20%3D%20max(TimeGenerated)%2C%20aad_last_ingest%3Dmax(ingestion_time())%20by%20aad_first_time%20%2C%20IPAddress%3C%2FFONT%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1865805005%22%20id%3D%22toc-hId-1865805005%22%20id%3D%22toc-hId-1865805005%22%20id%3D%22toc-hId-1865805005%22%20id%3D%22toc-hId-1865805005%22%20id%3D%22toc-hId-1865805005%22%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EFiltering%20only%20relevant%20sessions%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EOnce%20we%20have%20sessions%2C%20we%20need%20to%20check%20if%20they%20indeed%20indicate%20a%20detection%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EWas%20the%20session%20count%20above%20the%20detection%20threshold%3F%20%3CFONT%20color%3D%22%23FF0000%22%3E(red)%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EDid%20the%20session%20end%20within%20the%20latest%20rule%20execution%2C%20adjusted%20to%20an%20ingestion%20delay%3F%20%3CFONT%20color%3D%22%230000FF%22%3E(blue)%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EThe%20last%20line%2C%20project-rename%2C%20is%20just%20makeup.%20It%20renames%20IPAddress%20to%20make%20it%20easy%20to%20identify%20it%20as%20the%20AAD%20failure%20session%20IP%20address.%20This%20comes%20in%20handy%20after%20the%20join%20when%20multiple%20tables%20add%20their%20fields%20to%20the%20result%20set.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CFONT%20color%3D%22%23FF0000%22%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%7C%20where%20session_count%20%26gt%3B%3D%20signin_threshold%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FFONT%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%3CFONT%20color%3D%22%230000FF%22%3E%7C%20where%20aad_last_time%20%26gt%3B%20ago%20(rule_frequency%20%2B%20aad_delay)%3C%2FFONT%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%7C%20project-rename%20aad_ip_address%20%3D%20IPAddress%3B%3C%2FSPAN%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3ENote%20that%20unlike%20the%20simpler%20version%2C%20the%20result%20of%20this%20query%20part%20is%20a%20table%20and%20not%20a%20list%2C%20and%20we%20will%20use%20the%20join%20operator%20to%20correlate%20it%20to%20the%20AWS%20events.%20Why%3F%20We%20need%20to%20keep%20the%20timestamps%20and%20test%20them%20after%20the%20%22join.%22%20It%20would%20also%20help%20us%20provide%20more%20data%20to%20the%20analyst.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-58350542%22%20id%3D%22toc-hId-58350542%22%20id%3D%22toc-hId-58350542%22%20id%3D%22toc-hId-58350542%22%20id%3D%22toc-hId-58350542%22%20id%3D%22toc-hId-58350542%22%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EWant%20to%20stop%20here%3F%20the%20general%20aggregation%20case%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EWhile%20the%20rule%20we%20explore%20correlates%20Azure%20sign-in%20failures%20with%20a%20successful%20sign-in%20on%20AWS%2C%20the%20more%20common%20form%20is%20simple%20aggregation.%20i.e.%2C%20detection%20more%20than%20X%20events%20in%20a%20time%20window.%20The%20section%20we%20already%20covered%20address%20such%20a%20general%20use%20case%2C%20with%20the%20following%20small%20modifications%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3ERemote%20the%20line%20%22%3C%2FSPAN%3E%3CSTRONG%3E%3CEM%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3Elet%20suspicious_signins%20%3D%3C%2FSPAN%3E%3C%2FEM%3E%3C%2FSTRONG%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%22%20and%20the%20semicolon%20at%20the%20end%20to%20make%20this%20the%20primary%20query%20in%20the%20rule.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EAdd%20the%20line%20%22%3CEM%3E%3CSTRONG%3E%7C%20where%20aad_last_ingest%20%26gt%3B%20ago(rule_frequency)%3C%2FSTRONG%3E%3C%2FEM%3E%22%20to%20ensure%20the%20session%20included%20a%20new%2C%20just%20ingested%2C%20event%20and%20therefore%20was%20not%20yet%20reported%20on.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1749103921%22%20id%3D%22toc-hId--1749103921%22%20id%3D%22toc-hId--1749103921%22%20id%3D%22toc-hId--1749103921%22%20id%3D%22toc-hId--1749103921%22%20id%3D%22toc-hId--1749103921%22%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EMatching%20the%20sessions%20to%20a%20successful%20AWS%20login%20event%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EAfter%20finding%20successful%20AWS%20logins%20(red)%2C%20we%20match%20them%20on%20IP%20addresses%20to%20the%20sessions%20we%20identified%20earlier%20using%20join%20(blue).%20For%20matches%2C%20implying%20we%20have%20a%20session%20of%20Azure%20failures%20and%20a%20successful%20AWS%20login%20for%20the%20same%20address%2C%20we%20test%20the%20following%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EWas%20any%20of%20the%20events%20ingested%20in%20the%20latest%20rule%20execution%20window%20(%3CFONT%20color%3D%22%23008000%22%3Egreen%3C%2FFONT%3E)%3F%20This%20ensures%20the%20detected%20attack%20included%20new%20information%20and%20was%20not%20reported%20yet.%20This%20is%20the%20primary%20means%20used%20to%20support%20delayed%20events%20while%20avoiding%20duplicate%20alerting.%3C%2FSPAN%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EWas%20the%20successful%20AWS%20event%20with%20the%20time%20window%20of%20the%20session%3F%20(%3C%2FSPAN%3E%3CFONT%20color%3D%22%230000FF%22%3Eblue%3C%2FFONT%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E).%20This%20a%20simple%20to%20implement%20choice%2C%20but%20not%20the%20only%20one.%20Other%20options%20can%20also%20be%20implemented%2C%20such%20as%20the%20AWS%20success%20happening%20after%20the%20Azure%20failure%20session.%20Those%20will%20require%20changing%20this%20time%20condition%20line%20and%20may%20also%20require%20extending%20other%20timeframes%20in%20the%20query.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EThe%20%22project-rename%22%20and%20%22extend%22%20operators%20(orange)%20are%20again%20cosmetic%20only%20and%20make%20the%20AWS%20fields%20easy%20to%20use%20and%20identify%20in%20the%20joined%20table.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CFONT%20color%3D%22%23008000%22%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EAWSCloudTrail%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%7C%20where%20TimeGenerated%20%26gt%3B%20ago(max_session%20%2B%20rule_frequency%20%2B%20delay)%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%7C%20where%20EventName%20%3D%3D%20%22ConsoleLogin%22%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%7C%20extend%20LoginResult%20%3D%20tostring(parse_json(ResponseElements).ConsoleLogin)%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%7C%20where%20LoginResult%20%3D%3D%20%22Success%22%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%7C%20project-rename%20aws_time%20%3D%20TimeGenerated%2C%20aws_ip_address%20%3D%20SourceIpAddress%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FFONT%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%3CFONT%20color%3D%22%23008000%22%3E%7C%20extend%20aws_ingest_time%20%3D%20ingestion_time()%3C%2FFONT%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3CFONT%20color%3D%22%230000FF%22%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%7C%20join%20suspicious_signins%20on%20%24left.%20aws_ip_address%20%3D%3D%20%24right.aad_ip_address%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FFONT%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%7C%20where%20max_of(aws_ingest_time%2C%20aad_last_ingest)%20%26gt%3B%20ago(rule_frequency)%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%7C%20where%20aws_time%20between%20(aad_first_time%20..aad_last_time)%3C%2FSPAN%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EThat%E2%80%99s%20it.%20The%20rest%20would%20be%20just%20result%20and%20entity%20preparation.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-738408912%22%20id%3D%22toc-hId-738408912%22%20id%3D%22toc-hId-738408912%22%20id%3D%22toc-hId-738408912%22%20id%3D%22toc-hId-738408912%22%20id%3D%22toc-hId-738408912%22%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3ERule%20Settings%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EAn%20analytics%20rule%20is%20not%20just%20a%20query.%20There%20are%20several%20parameters%20that%20you%20need%20to%20set%20to%20make%20it%20work.%20The%20two%20critical%20ones%20are%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E-%22Run%20query%20every%22%20is%20the%20rule%20execution%20frequency%20and%20should%20be%20set%20to%2C%20as%20expected%20to%20%22rule_frequency.%22%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3E%22Lookup%20data%20from%20the%20last%2C%22%20or%20the%20rule's%20lookback%20time%2C%20has%20to%20be%20at%20least%20as%20long%20as%20the%20most%20extended%20time%20condition%20in%20the%20rule.%20This%20would%20be%20max_session%20%2B%20rule_frequency%20%2B%20the%20length%20of%20the%20delays%2C%20aad_delay%2C%20and%20aws_delay.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EAlso%2C%20you%20should%20configure%20alert%20aggregation%20based%20on%20the%20source%20IP%20address.%20A%20sliding%20window-based%20rule%20will%20alert%20when%20new%20events%20are%20extending%20an%20existing%20session.%20While%20it%20is%20possible%20to%20suppress%20such%20alerting%2C%20it%20adds%20information%2C%20so%20generating%20an%20alert%20that%20will%20be%20grouped%20to%20the%20same%20incidents%20is%20the%20best%20practice.%20Aggregation%20should%20be%20by%20IP%20address%20and%20aad_first_time%2C%20to%20which%20you%20should%20allocate%20one%20of%20the%20unused%20entities.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1069045551%22%20id%3D%22toc-hId--1069045551%22%20id%3D%22toc-hId--1069045551%22%20id%3D%22toc-hId--1069045551%22%20id%3D%22toc-hId--1069045551%22%20id%3D%22toc-hId--1069045551%22%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3ESummary%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EAggregation%20rules%20and%20more%20advanced%20relations-based%20rules%20require%20careful%20consideration%20of%20time%20window%20management%20to%20avoid%20missing%20alerts%20or%20duplicate%20alerting.%20This%20article%20provides%20a%20recipe%20that%20should%20help%20you%20implement%20such%20rules%20correctly%20using%20a%20sliding%20window%20analysis.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-preserver-spaces%3D%22true%22%3EI%20hope%20you%20found%20it%20useful!%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1505394%22%20slang%3D%22en-US%22%3E%3CP%3ESliding%20window%20based%20aggregation%20and%20correlation%20rules%20are%20the%20holy%20grail%20in%20SIEM%20rule%20writing.%20Learn%20how%20to%20create%20them%20in%20Azure%20Sentinel.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2253088%22%20slang%3D%22en-US%22%3ERe%3A%20Handling%20sliding%20windows%20in%20Azure%20Sentinel%20rules%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2253088%22%20slang%3D%22en-US%22%3E%3CP%3EVery%20good%20content%2C%3CSPAN%3E%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F293879%22%20target%3D%22_blank%22%3E%40Ofer_Shezaf%3C%2FA%3E%26nbsp%3B%3C%2FSPAN%3E%26nbsp%3B.%3C%2FP%3E%3CP%3EThanks.%3C%2FP%3E%3CP%3EI%20have%20a%26nbsp%3Bdoubt.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CU%3Etimegenereted()%3C%2FU%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%20the%20time%20that%20the%20event%20was%20generated%20at%20the%20source%20and%20is%20informed%20in%20the%20source%20payload%2C%20right%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20for%20some%20reason%20my%20source%20does%20not%20send%20the%20time%20the%20log%20was%20created%2C%20what%20will%20be%20the%20timegenereted%20time%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I'm%20not%20mistaken%2C%20for%20the%20MMA%20collector%2C%20if%20I%20don't%20have%20the%20timegenereted%20specified%20in%20the%20log%2C%20I'll%20specify%20_TimeReceived%2C%20which%20is%20the%20time%20that%20the%20log%20arrived%20at%20the%20installed%20agent.%20That's%20it%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20would%20it%20be%20like%20for%20firewall%20logs%2C%20for%20example%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2253361%22%20slang%3D%22en-US%22%3ERe%3A%20Handling%20sliding%20windows%20in%20Azure%20Sentinel%20rules%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2253361%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F733311%22%20target%3D%22_blank%22%3E%40luizao_lf%3C%2FA%3E%26nbsp%3B%3A%20you%20are%20correct%20that%20some%20sources%20do%20not%20produce%20a%20reliable%20TimeGenerated%20field.%20For%20each%20of%20those%20you%20will%20have%20to%20pick%20the%20correct%20timestamp.%20For%20Firewalls%20for%20example%2C%20it%20would%20differ%20based%20on%20the%20specific%20firewall.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2257925%22%20slang%3D%22en-US%22%3ERe%3A%20Handling%20sliding%20windows%20in%20Azure%20Sentinel%20rules%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2257925%22%20slang%3D%22en-US%22%3E%3CP%3EIf%20the%20event%20is%20from%20windows%2C%20for%20example%2C%20if%20you%20do%20not%20have%20timegenereted%20()%20at%20the%20source%2C%20the%20value%20of%20timegenereted%20()%20will%20be%20the%20moment%20the%20log%20arrived%20at%20the%20MMA%20agent.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20what%20about%20a%20firewall%20that%20does%20not%20have%20an%20MMA%20agent%3F%20If%20the%20team%20does%20not%20contain%20the%20source%2C%20what%20value%20will%20be%20sent%20in%20the%20timegenereted%20()%20field%3F%20Will%20it%20be%20the%20value%20when%20it%20arrives%20at%20the%20CEF%20concentrator%3F%20or%20would%20it%20be%20otherwise%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Version history
Last update:
‎Dec 29 2020 04:15 AM
Updated by: