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

KQL query for brute force against users in certain AAD groups

Brass Contributor

Greetings. 

I am trying to figure out a way to search for brute force attacks against users that are part of certain AAD groups.

So far I have found that i can utilize brute force queries already available in Azure Sentinel hunting queries, but checking this information up against group membership seems to be an issue. 

 

I can find some information about group membership trough the audit logs, but the best solution would be, if possible, to just query straight against AAD group membership. Is this information possible to stream into Azure Sentinel log analytics?

5 Replies

@stianhoydal there are a few ways you could achieve this and you may want to have a try a few with what works best, the AuditLog is only going to track changes to your groups, so you need to reference your brute force attack query vs the current list of members of those groups.

 

The easiest may be having a Watchlist - Use Azure Sentinel watchlists | Microsoft Docs which contains the list of users who are a part of that group. You could keep that Watchlist current by using a Logic App that polls Azure AD / MS Graph and updates the watchlist every hour or whatever suits your environment - How to Use the Watchlists Logic App Connector for Azure Sentinel – Azure Cloud & AI Domain Blog (azu...

 

So if you created a watchlist called 'HighRiskUsers' with the list of UserPrinicpalNames of the users in those groups you could then add logic to look at that list before alerting you -

 

let watchlist = (_GetWatchlist('HighRiskUsers') | project UserPrincipalName);
<your brute force attack query>

| project UserPrincipalName
| where UserPrincipalName in (watchlist)

 

Alternatively you could look at using the Azure Log Analytics Data Collector - Connectors | Microsoft Docs or the ingestion API to send that data to a custom table. So you could poll AzureAD using Powershell/MS Graph to get membership of those groups, then ingest what you wanted to HighRiskUsers_CL as an example, then in your query you could use a join to match against your brute force query and your custom table of data.

 

let Alert1 =
SigninLogs
<your brute force attack query>
| project TimeGenerated, UserPrincipalName
;
let HighRiskUsers =
HighRiskUsers_CL
| project UserPrincipalName
;
Alert1
| join kind=inner HighRiskUsers on UserPrincipalName

 

 

best response confirmed by stianhoydal (Brass Contributor)
Solution

You could do this in a few ways, you may need to test to see what works best for you environment. The issue you are facing is that the AuditLogs table will only track changes to groups, you want to query log data (your brute force attack query) vs static data (group membership)

1. Add the users to a watchlist - https://docs.microsoft.com/en-us/azure/sentinel/watchlists

You could upload an initial csv to the watchlist that contains the userprincipalnames of the users who are in the groups you care about. In this example a watchlist called HighRiskUsers with userprincipalname as a column header. You then include being in that watchlist as part of your query -

let watchlist = (_GetWatchlist('HighRiskUsers') | project UserPrincipalName);
SigninLogs
*your brute force query here*
| where UserPrincipalName in (watchlist)

You could then use a logic app to keep that watchlist current - https://docs.microsoft.com/en-us/connectors/azuresentinel/#watchlists---update-an-existing-watchlist...

For example, poll Azure AD/MS Graph for the membership of those groups every few hours, then have the logic app keep it current

2. You could ingest those members (and potentially the group names if useful) to a custom table in Sentinel then use a join operator in your query. You can send custom data using the ingestion API or Azure Log Analytics Data Collector logic app - https://docs.microsoft.com/en-us/connectors/azureloganalyticsdatacollector/

So again, you could poll Azure AD/MS Graph, and send the data to Sentinel as a custom log, using the same example you could call it HighRiskUsers_CL. Then when you write your hunting query you want to join on matches between your brute force query and the HighRiskUsers_CL table -

let Alert1 =
SigninLogs
<your brute force attack query>
| project UserPrincipalName
;
let HighRiskUsers =
HighRiskUsers_CL
| project UserPrincipalName, HighRiskGroupName
;
Alert1
| join kind=inner HighRiskUsers on UserPrincipalName
| project UserPrincipalName, HighRiskGroupName

Thank you for the great response. I will try this once i get back to the project.

@m_zorich Sweet, with a guide and everything. This will make a fine addition to my collection :lol:

1 best response

Accepted Solutions
best response confirmed by stianhoydal (Brass Contributor)
Solution

You could do this in a few ways, you may need to test to see what works best for you environment. The issue you are facing is that the AuditLogs table will only track changes to groups, you want to query log data (your brute force attack query) vs static data (group membership)

1. Add the users to a watchlist - https://docs.microsoft.com/en-us/azure/sentinel/watchlists

You could upload an initial csv to the watchlist that contains the userprincipalnames of the users who are in the groups you care about. In this example a watchlist called HighRiskUsers with userprincipalname as a column header. You then include being in that watchlist as part of your query -

let watchlist = (_GetWatchlist('HighRiskUsers') | project UserPrincipalName);
SigninLogs
*your brute force query here*
| where UserPrincipalName in (watchlist)

You could then use a logic app to keep that watchlist current - https://docs.microsoft.com/en-us/connectors/azuresentinel/#watchlists---update-an-existing-watchlist...

For example, poll Azure AD/MS Graph for the membership of those groups every few hours, then have the logic app keep it current

2. You could ingest those members (and potentially the group names if useful) to a custom table in Sentinel then use a join operator in your query. You can send custom data using the ingestion API or Azure Log Analytics Data Collector logic app - https://docs.microsoft.com/en-us/connectors/azureloganalyticsdatacollector/

So again, you could poll Azure AD/MS Graph, and send the data to Sentinel as a custom log, using the same example you could call it HighRiskUsers_CL. Then when you write your hunting query you want to join on matches between your brute force query and the HighRiskUsers_CL table -

let Alert1 =
SigninLogs
<your brute force attack query>
| project UserPrincipalName
;
let HighRiskUsers =
HighRiskUsers_CL
| project UserPrincipalName, HighRiskGroupName
;
Alert1
| join kind=inner HighRiskUsers on UserPrincipalName
| project UserPrincipalName, HighRiskGroupName

View solution in original post