Microsoft Secure Tech Accelerator
Apr 03 2024, 07:00 AM - 11:00 AM (PDT)
Microsoft Tech Community

Azure Sentinel triggers incident when it shouldn't

Brass Contributor

Greetings, I just ran into something interesting. I have created a analytics rule that looks like this:

 

let exceptionUsers = IdentityInfo
| where TimeGenerated > ago(22d) //IdentityInfo refreshes its information every 21 days
| where todynamic(GroupMembership) contains "SG-U Guest users excluded from CA blocked countries"
| distinct MailAddress;
//Creates a set of users that is to be ignored when looking for logins outside of europe. 
SigninLogs
| where TimeGenerated > ago(4h)
| where Location !in ( "AL","AD","AM","AT","BY","BE","BA","BG","CH","CY","CZ","DE","DK","EE","ES","FO","FI","FR","GB","GE","GI","GR","HU","HR","IE","IS","IT","LI","LT","LU","LV","MC","MK","MT","NO","NL","PL","PT","RO","RU","SE","SI","SK","SM","TR","UA","VA","SJ","") // List of country codes in europe. 
| where UserPrincipalName !in ( exceptionUsers )
| extend AccountCustomEntity = Identity
| extend IPCustomEntity = IPAddress

Might not be the greatest of queries, but still, I run this query and get no results. As i expect. However, the analytics rule with this configuration still manages to trigger. 

 

This is the view from the analytics rule wizard when i test with current data.

stianhoydal_0-1631180987240.png

The last spike indicates the one i saw today. How can the analytics rule wizard get different results from the same query i run in the Logs tab?

5 Replies

@stianhoydal The analytic rule will ignore any time details set in the query.  As it states in the Set rule logic tab:  Any time details set here will be within the scope defined below in the Query scheduling fields.

 

That may have something to do with it.  Try running the query manually but use the value that is set In the Lookup data from the last field and see if that returns any results.

I see, that probably explains why the users that should be excluded shows up anyway. Since the IdentityInfo table is only updated every 21 days i seem to be unable to get this information as queries against the table sometimes return empty if the users in question haven't been updates within the timeframe. Seeing as the lookback time you can set in the query wizard is max 14 days i need to figure out a workaround i suppose.

So i figured out a simple workaround, but still the query wizard shows that it would trigger the alarm several times although it shouldn't have. 

 

let excludedUsers = GuestAccountsExcludedFromCAPolicy_CL 
| distinct UserEmail_s;
SigninLogs 
| where Location !in ( "AL","AD","AM","AT","BY","BE","BA","BG","CH","CY","CZ","DE","DK","EE","ES","FO","FI","FR","GB","GE","GI","GR","HU","HR","IE","IS","IT","LI","LT","LU","LV","MC","MK","MT","NO","NL","PL","PT","RO","RU","SE","SI","SK","SM","TR","UA","VA","SJ","") // List of country codes in europe. 
| where UserPrincipalName !in (excludedUsers)
| extend AccountCustomEntity = Identity
| extend IPCustomEntity = IPAddress

The GuestAccountsExcludedFromCAPolicy_CL is simply a table filled with users fetched from AAD via logic apps.

 

Still the query wizard shows that it would trigged multiple alarms within the last 48 hours although there should only be one. 

stianhoydal_0-1631279840851.png

It seems to me as if the query is just ignoring the line

| where UserPrincipalName !in (excludedUsers)

because it would be correct otherwise, but the whole point is to not get alerted when one of the excluded members tries to log on. 

Anyone have any ideas on why this is happening, or potential solutions? 

 

It looks right. I would double check the values you are getting in your custom tables to make sure they are matching what you are seeing in the SigninLogs.

You may also want to use a Watchlist for the locations to make it easier to keep up to date.
For anyone else that might have been wondering, seemingly the best way i found to make this work is to fetch the AAD group members into a custom table and update this according to how often you would want to run the analytics rule since the analytics rule wizard overrides any time references made in a query. If i want the query to run every 1 hour with the latest 1 hour of data i would need to update the custom table every 1 hour or less.