|
| 1 | +# Az - Monitoring |
| 2 | + |
| 3 | +{{#include ../../../banners/hacktricks-training.md}} |
| 4 | + |
| 5 | +## Entra ID - Logs |
| 6 | + |
| 7 | +There are 3 types of logs available in Entra ID: |
| 8 | + |
| 9 | +- **Sign-in Logs**: Sign-in logs document every authentication attempt, whether successful or failed. They offer details such as IP addresses, locations, device information and applied conditional access policies, which are essential for monitoring user activity and detecting suspicious login behavior or potential security threats. |
| 10 | +- **Audit Logs**: Audit logs provide a record of all changes made within your Entra ID environment. They capture updates to users, groups, roles, or policies for example. These logs are vital for compliance and security investigations, as they let you review who made what change and when. |
| 11 | +- **Provisioning Logs**: Provisioning logs provide information about users provisioned in your tenant through a third-party service (such as on-premises directories or SaaS applications). These logs help you understand how identity information is synchronized. |
| 12 | + |
| 13 | +> [!WARNING] |
| 14 | +> Note that these logs are only stored for **7 days** in the free version, **30 days** in P1/P2 version and 60 additional days in security signals for risky signin activity. However, not even a global admin would be able to **modify or delete them earlier**. |
| 15 | +
|
| 16 | +## Entra ID - Log Systems |
| 17 | + |
| 18 | +- **Diagnostic Settings**: A diagnostic setting specifies a list of categories of platform logs and/or metrics that you want to collect from a resource, and one or more destinations that you would stream them to. Normal usage charges for the destination will occur. Learn more about the different log categories and contents of those logs. |
| 19 | + - **Destinations**: |
| 20 | + - **Analytics Workspace**: Investigation through Azure Log Analytics and create alerts. |
| 21 | + - **Storage account**: Static análysis and backup. |
| 22 | + - **Event hub**: Stream data to external systems like third-party SIEMs. |
| 23 | + - **Monitor partner solutions**: Special integrations between Azure Monitor and other non-Microsoft monitoring platforms. |
| 24 | +- **Workbooks**: Workbooks combine text, log queries, metrics, and parameters into rich interactive reports. |
| 25 | +- **Usage & Insights**: Useful to see the most common activities in Entra ID |
| 26 | + |
| 27 | +## Azure Monitor |
| 28 | + |
| 29 | +These are the main features of Azure Monitor: |
| 30 | + |
| 31 | +- **Activity Logs**: Azure Activity Logs capture subscription‑level events and management operations, giving you an overview of changes and actions taken on your resources. |
| 32 | + - **Activily logs** cannot be modified or deleted. |
| 33 | +- **Change Analysis**: Change Analysis automatically detects and visualizes configuration and state changes across your Azure resources to help diagnose issues and track modifications over time. |
| 34 | +- **Alerts**: Alerts from Azure Monitor are automated notifications triggered when specified conditions or thresholds are met in your Azure environment. |
| 35 | +- **Workbooks**: Workbooks are interactive, customizable dashboards within Azure Monitor that enable you to combine and visualize data from various sources for comprehensive analysis. |
| 36 | +- **Investigator**: Investigator helps you drill down into log data and alerts to conduct deep-rooted analysis and identify the cause of incidents. |
| 37 | +- **Insights**: Insights provide analytics, performance metrics, and actionable recommendations (like those in Application Insights or VM Insights) to help you monitor and optimize the health and efficiency of your applications and infrastructure. |
| 38 | + |
| 39 | +### Log Analytics Workspaces |
| 40 | + |
| 41 | +Log Analytics workspaces are central repositories in Azure Monitor where you can **collect, analyze, and visualize log and performance data** from your Azure resources and on-premises environments. Here are the key points: |
| 42 | + |
| 43 | +- **Centralized Data Storage**: They serve as the central location to store diagnostic logs, performance metrics, and custom logs generated by your applications and services. |
| 44 | +- **Powerful Query Capabilities**: You can run queries using Kusto Query Language (KQL) to analyze the data, generate insights, and troubleshoot issues. |
| 45 | +- **Integration with Monitoring Tools**: Log Analytics workspaces integrate with various Azure services (such as Azure Monitor, Azure Sentinel, and Application Insights) allowing you to create dashboards, set up alerts, and gain a comprehensive view of your environment. |
| 46 | + |
| 47 | +In summary, a Log Analytics workspace is essential for advanced monitoring, troubleshooting, and security analysis in Azure. |
| 48 | + |
| 49 | +You can configure a resource to send data to an analytics workspace from the **diagnostic settings** of the resource. |
| 50 | + |
| 51 | +## Enumeration |
| 52 | + |
| 53 | +### Entra ID |
| 54 | + |
| 55 | +```bash |
| 56 | +# Get last 10 sign-ins |
| 57 | +az rest --method get --uri 'https://graph.microsoft.com/v1.0/auditLogs/signIns?$top=10' |
| 58 | + |
| 59 | +# Get last 10 audit logs |
| 60 | +az rest --method get --uri 'https://graph.microsoft.com/v1.0/auditLogs/directoryAudits?$top=10' |
| 61 | + |
| 62 | +# Get last 10 provisioning logs |
| 63 | +az rest --method get --uri ‘https://graph.microsoft.com/v1.0/auditLogs/provisioning?$top=10’ |
| 64 | + |
| 65 | +# Get EntraID Diagnostic Settings |
| 66 | +az rest --method get --uri "https://management.azure.com/providers/microsoft.aadiam/diagnosticSettings?api-version=2017-04-01-preview" |
| 67 | + |
| 68 | +# Get Entra ID Workbooks |
| 69 | +az rest \ |
| 70 | + --method POST \ |
| 71 | + --url "https://management.azure.com/providers/microsoft.resourcegraph/resources?api-version=2021-03-01" \ |
| 72 | + --headers '{"commandName": "AppInsightsExtension.GetWorkbooksListArg"}' \ |
| 73 | + --body '{ |
| 74 | + "subscriptions": ["9291ff6e-6afb-430e-82a4-6f04b2d05c7f"], |
| 75 | + "query": "where type =~ \"microsoft.insights/workbooks\" \n| extend sourceId = tostring(properties.sourceId) \n| where sourceId =~ \"Azure Active Directory\" \n| extend DisplayName = tostring(properties.displayName) \n| extend WorkbookType = tostring(properties.category), LastUpdate = todatetime(properties.timeModified) \n| where WorkbookType == \"workbook\"\n| project DisplayName, name, resourceGroup, kind, location, id, type, subscriptionId, tags, WorkbookType, LastUpdate, identity, properties", |
| 76 | + "options": {"resultFormat": "table"}, |
| 77 | + "name": "e4774363-5160-4c09-9d71-2da6c8e3b00a" |
| 78 | + }' | jq '.data.rows' |
| 79 | +``` |
| 80 | + |
| 81 | +### Azure Monitor |
| 82 | + |
| 83 | +```bash |
| 84 | +# Get last 10 activity logs |
| 85 | +az monitor activity-log list --max-events 10 |
| 86 | + |
| 87 | +# Get Resource Diagnostic Settings |
| 88 | +az rest --url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.DocumentDb/databaseAccounts/<db-name>/providers/microsoft.insights/diagnosticSettings?api-version=2021-05-01-preview" |
| 89 | + |
| 90 | +# Get Entra ID Workbooks |
| 91 | +az rest \ |
| 92 | + --method POST \ |
| 93 | + --url "https://management.azure.com/providers/microsoft.resourcegraph/resources?api-version=2021-03-01" \ |
| 94 | + --headers '{"commandName": "AppInsightsExtension.GetWorkbooksListArg"}' \ |
| 95 | + --body '{ |
| 96 | + "content": {}, |
| 97 | + "commandName": "AppInsightsExtension.GetWorkbooksListArg" |
| 98 | + }' |
| 99 | + |
| 100 | +# List Log Analytic groups |
| 101 | +az monitor log-analytics workspace list --output table |
| 102 | + |
| 103 | +# List alerts |
| 104 | +az monitor metrics alert list --output table |
| 105 | +az monitor activity-log alert list --output table |
| 106 | +``` |
| 107 | + |
| 108 | +{{#include ../../../banners/hacktricks-training.md}} |
| 109 | + |
0 commit comments