daf868fa81 | ||
---|---|---|
.. | ||
Images | ||
README.md | ||
azuredeploy.json |
README.md
AS-Add-Machine-Logon-Users-to-Incident
Author: Accelerynt
For any technical questions, please contact info@accelerynt.com
This playbook is intended to be run from a Microsoft Sentinel incident. It will match the hosts from a Microsoft Sentinel incident with Microsoft Defender machines and add the logon users for each machine as a comment on the Microsoft Sentinel incident.
Requirements
The following items are required under the template settings during deployment:
- A Microsoft Azure Active Directory app registration with admin consent granted for "Users.Read.All" in the "WindowsDefenderATP" API
- An Azure key vault secret containing your app registration client secret
Setup
Create an App Registration
Navigate to the Microsoft Azure Active Directory app registration page: https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade
Click "New registration".
Enter "AS-Add-Machine-Logon-Users-to-Incident" for the name, all else can be left as is. Click "Register"
Once the app registration is created, you will be redirected to the "Overview" page. Under the "Essentials" section, take note of the "Application (client) ID", as this will be needed for deployment.
Next, you will need to add permissions for the app registration to call the Microsoft Defender logonusers endpoint. From the left menu blade, click "API permissions" under the "Manage" section. Then, click "Add a permission".
From the "Select an API" pane, click the "APIs my organization uses" tab, then paste "WindowsDefenderATP" in the search bar. Click the option matching the search.
Click "Application permissions", then type "User.Read.All" into the search bar and select the result. Click "Add permissions".
Admin consent will be needed before your app registration can use the assigned permission. Click "Grant admin consent for (name)".
Lastly, a client secret will need to be generated for the app registration. From the left menu blade, click "Certificates & secrets" under the "Manage" section. Then, click "New client secret".
Enter a description and select the desired expiration date, then click "Add".
Copy the value of the secret that is generated, as this will be needed for Create an Azure Key Vault Secret.
Create an Azure Key Vault Secret
Navigate to the Azure key vaults page: https://portal.azure.com/#view/HubsExtension/BrowseResource/resourceType/Microsoft.KeyVault%2Fvaults
Navigate to an existing key vault or create a new one. From the key vault overview page, click the "Secrets" menu option, found under the "Settings" section. Click "Generate/Import".
Choose a name for the secret, such as "AS-Add-Machine-Logon-Users-to-Incident-AR-Client-Secret", and enter the client secret copied in the previous section. All other settings can be left as is. Click "Create".
Once your secret has been added to the vault, navigate to the "Access policies" menu option. Leave this page open, as you will need to return to it once the playbook has been deployed. See Granting Access to Azure Key Vault.
Deployment
To configure and deploy this playbook:
Open your browser and ensure you are logged into your Microsoft Sentinel workspace. In a separate tab, open the link to our playbook on the Accelerynt Security GitHub repository:
https://github.com/Accelerynt-Security/AS-Add-Machine-Logon-Users-to-Incident
Click the "Deploy to Azure" button at the bottom and it will bring you to the custom deployment template.
In the Project Details section:
- Select the "Subscription" and "Resource Group" from the dropdown boxes you would like the playbook deployed to.
In the Instance Details section:
-
Playbook Name: This can be left as "AS-Add-Machine-Logon-Users-to-Incident" or you may change it.
-
Client ID: Enter the Application (client) ID of your app registration referenced in Create an App Registration.
-
Key Vault Name: Enter the name of the key vault referenced in Create an Azure Key Vault Secret.
-
Secret Name: Enter the name of the key vault Secret created in Create an Azure Key Vault Secret.
Towards the bottom, click on "Review + create".
Once the resources have validated, click on "Create".
The resources should take around a minute to deploy. Once the deployment is complete, you can expand the "Deployment details" section to view them. Click the one corresponding to the Logic App.
Microsoft Sentinel Contributor Role
After deployment, you will need to give the system assigned managed identity the "Microsoft Sentinel Contributor" role. This will enable it to add comments to incidents. Navigate to the Log Analytics Workspaces page and select the same workspace the playbook is located in:
Select the "Access control (IAM)" option from the menu blade, then click "Add role assignment".
Select the "Microsoft Sentinel Contributor" role, then click "Next".
Select the "Managed identity" option, then click "Select Members". Under the subscription the logic app is located, set the value of "Managed identity" to "Logic app". Next, enter "AS-Add-Machine-Logon-Users-to-Incident", or the alternative playbook name used during deployment, in the field labeled "Select". Select the playbook, then click "Select".
Continue on to the "Review + assign" tab and click "Review + assign".
Alternatively, if you wish to do this through PowerShell, run the following commands, replacing the managed identity object id and resource group name. You can find the managed identity object id on the Identity blade under Settings for the Logic App.
You will not need to run the Install-Module if this has been done before. More documentation on this module can be found here:
https://learn.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-9.3.0
Install-Module -Name Az
Connect-AzAccount
New-AzRoleAssignment -ObjectId <logic app managed identity object id> -RoleDefinitionName "Microsoft Sentinel Contributor" -ResourceGroupName "<logic app resource group name>"
Granting Access to Azure Key Vault
Before the Logic App can run successfully, the key vault connection created during deployment must be granted access to the key vault storing your app registration client secret.
From the key vault "Access policies" page, click "Create".
Select the "Get" checkbox under "Secret permissions", then click "Next".
Paste "AS-Add-Machine-Logon-Users-to-Incident" into the principal search box and click the option that appears. Click "Next" towards the bottom of the page.
Navigate to the "Review + create" section and click "Create".
Running the Playbook
To run this playbook from a Microsoft Sentinel incident, navigate to Microsoft Sentinel:
Select a workspace and then click the "Incidents" menu option located under "Threat management". Select an incident with compromised host entities.
Click on the "Action" list button on the bottom right of the screen and select "Run playbook".
From the "Run playbook on incident" view, type "AS-Add-Machine-Logon-Users-to-Incident" into the search bar, then click run.