|
| 1 | +--- |
| 2 | +title: Create custom hunting queries in Microsoft Sentinel |
| 3 | +titleSuffix: Microsoft Sentinel |
| 4 | +description: Learn how to create a custom query to hunt for threats. |
| 5 | +author: austinmccollum |
| 6 | +ms.author: austinmc |
| 7 | +ms.topic: how-to |
| 8 | +ms.date: 04/23/2024 |
| 9 | +appliesto: |
| 10 | + - Microsoft Sentinel in the Azure portal |
| 11 | + - Microsoft Sentinel in the Microsoft Defender portal |
| 12 | +ms.collection: usx-security |
| 13 | +--- |
| 14 | + |
| 15 | +# Create custom hunting queries in Microsoft Sentinel |
| 16 | + |
| 17 | +Create or modify a query and save it as your own query or share it with users who are in the same tenant. |
| 18 | + |
| 19 | +## Create a new query |
| 20 | + |
| 21 | +In Microsoft Sentinel, create a custom hunting query from the **Hunting** > **Queries** tab. |
| 22 | + |
| 23 | +1. For Microsoft Sentinel in the [Azure portal](https://portal.azure.com), under **Threat management** select **Hunting**.<br> For Microsoft Sentinel in the [Defender portal](https://security.microsoft.com/), select **Microsoft Sentinel** > **Threat management** > **Hunting**. |
| 24 | +1. Select the **Queries** tab. |
| 25 | +1. From the command bar, select **New query**. |
| 26 | + |
| 27 | +1. Fill in all the blank fields. |
| 28 | + |
| 29 | + 1. Create entity mappings by selecting entity types, identifiers, and columns. |
| 30 | + |
| 31 | + :::image type="content" source="media/hunting/map-entity-types-hunting.png" alt-text="Screenshot for mapping entity types in hunting queries."::: |
| 32 | + |
| 33 | + 1. Map MITRE ATT&CK techniques to your hunting queries by selecting the tactic, technique, and sub-technique (if applicable). |
| 34 | + |
| 35 | + :::image type="content" source="./media/hunting/mitre-attack-mapping-hunting.png" alt-text="New query" lightbox="./media/hunting/new-query.png"::: |
| 36 | + |
| 37 | +1. When your finished defining your query, select **Create**. |
| 38 | + |
| 39 | +**To clone and modify an existing query**: |
| 40 | + |
| 41 | +1. From the table, select the hunting query you want to modify. |
| 42 | +1. Select the ellipsis (...) in the line of the query you want to modify, and select **Clone query**. |
| 43 | + |
| 44 | + :::image type="content" source="./media/hunting/clone-query.png" alt-text="Clone query" lightbox="./media/hunting/clone-query.png"::: |
| 45 | + |
| 46 | +1. Modify the query and select **Create**. |
| 47 | + |
| 48 | +**To modify an existing custom query**: |
| 49 | + |
| 50 | +1. From the table, select the hunting query that you wish to modify. Only queries that from a custom content source can be edited. Other content sources have to be edited at that source. |
| 51 | + |
| 52 | +1. Select the ellipsis (...) in the line of the query you want to modify, and select **Edit query**. |
| 53 | + |
| 54 | +1. Modify the **Custom query** field with the updated query. You can also modify the entity mapping and techniques as explained in the "**To create a new query**" section of this documentation. |
| 55 | + |
| 56 | +## Sample query |
| 57 | + |
| 58 | +A typical query starts with a table or parser name followed by a series of operators separated by a pipe character ("\|"). |
| 59 | + |
| 60 | +In the example above, start with the table name SecurityEvent and add piped elements as needed. |
| 61 | + |
| 62 | +1. Define a time filter to review only records from the previous seven days. |
| 63 | + |
| 64 | +1. Add a filter in the query to only show event ID 4688. |
| 65 | + |
| 66 | +1. Add a filter in the query on the command line to contain only instances of cscript.exe. |
| 67 | + |
| 68 | +1. Project only the columns you're interested in exploring and limit the results to 1000 and select **Run query**. |
| 69 | + |
| 70 | +1. Select the green triangle and run the query. You can test the query and run it to look for anomalous behavior. |
| 71 | + |
| 72 | +We recommend that your query uses an [Advanced Security Information Model (ASIM) parser](normalization-about-parsers.md) and not a built-in table. This ensures that the query will support any current or future relevant data source rather than a single data source. |
0 commit comments