Path: blob/master/scenario-notebooks/AffectedKeyCredentials-CVE-2021-42306.ipynb
3250 views
Detecting vulnerable service principals and applications in AAD
This notebook contains logic to detect applications and service principals in Azure Active Directory that are vulnerable to the attack described in CVE-2021-42306.
It contains the following sections
Establish a connection to Microsoft Graph
Download and check for vulnerable Application and Service Principal objects
View and filter the vulnerable items
Create a Microsoft Sentinel Watchlist containing the items
Creating a Watchlist will allow you to create detections and alerts based on the IDs of the affected Applications and Service Principals in your Azure Active Directory. This will allow you to spot potential abuses of these objects
Please run the the code cells in sequence. Skipping cells will result in errors.
Initialize MSTICPy
Using Azure Key Vault to store the client secret for MS Graph
This is an optional section.
To use the MSTICPy Keyvault library you must have your keyvault details configured in msticpyconfig.yaml. Please see the following documents for more details.
Key Vault configuration format
Key Vault settings in the settings editor
To store you client secret in Key Vault you can use the following code snippet.
You can also configure a secret using the Azure management portal.
Specify Parameters for Connecting to MS Graph
Run this cell to display a form for entering details required to connect to Microsoft Graph.
If you are not storing your client secret in Key Vault, uncheck the Get secret from keyvault box and type the client secret into the Client secret box
Create the Microsoft Graph data provider
Note the current version of the graph provider only supports the global Azure cloud. The code below will adapt it if you have a different sovereign cloud configured in your msticpconfig.yaml.
The access token obtained for the Microsoft Graph expires after 1 hour. Please re-run this cell if you see this error:
Query MS Graph for Vulnerable AAD objects
This cell connects to the Microsoft Graph, queries available Application and ServicePrincipal objects and check for vulnerable configurations.
The following cell allows you to browse the results.
View and filter vulnerable objects to create a watch list
You can view vulnerable objects in the data browser.
Using the Choose columns and Filter data drop-downs you can change the displayed columns and filter the data.
results_viewer.filtered_data
Create watchlist in Azure Sentinel
Setup code
Please run the next cell before continuing; it contains code definitions required later.
Enter or confirm the details for the Microsoft Sentinel Workspace
Ensure that the details for the watchlist and the target workspace are correct.
Connect to Microsoft Sentinel Workspace API
Upload the watchlist
Executing the next cell will update an existing watchlist. If you deselected the option to Append to current watchlist existing watchlist content will be deleted.
Search for vulnerable ServicePrincipals/Apps in Microsoft Sentinel
You can optionally search for suspicious activity involving the affected accounts.
To use a Sentinel workspace other than your default, set the workspace_name variable to the name of the entry in your msticpyconfig.yaml. E.g.
Supplementary functions
Download/Browse current watchlists
Download and view the named watchlist
By default "Vulnerable_CVE_2021_42306"