Path: blob/master/A Getting Started Guide For PowerShell AML Notebooks.ipynb
3249 views
A Getting Started Guide for Microsoft Sentinel notebooks with PowerShell
Notebook Version: 2.0
Data Sources Required:
Log Analytics - SecurityEvent (Optional)
**.Net Interactive installation is required! **:
To use this notebook, you will first need to install .Net Interactive. Please follow the instructions in the section of "Installing the required PowerShell modules". Current Ubuntu version is 18.04, and .NET SDK 5.0 is required. Details can be found in this article -> Microsoft Sentinel Notebooks + Powershell.
** About this notebook **:
This notebook takes you through the basics needed to get started with PowerShell notebooks that leverage Microsoft Sentinel data and APIs.
This notebook assumes that you are running this in an Azure Machine Learning notebooks environment created via the Microsoft Sentinel UI as this notebook has not yet been tested in other environments. Check the official documentation on creating a Microsoft Sentinel AML workspace/environment to learn more.
For a notebook that provides more definitive guidance to the notebook experience, launch the A Getting Started Guide for Microsoft Sentinel ML Notebooks notebook from the Microsoft Sentinel notebook UI. This notebook provides a step-by-step overview of the notebook experience as well as some tips and tricks on how to get the most out of your Jupyter notebook experience.
For more information as to why Juypter for security investigations, check out this excellent article Why Use Jupyter for Security Investigations
Lastly, don't forget to install .Net Interactive to use this notebook!
Installing .NET SDK and Interactive
Please execute the following cells to install .NET SDK and Interactive. You need install them once on a compute instance, and only once. If you have already install them, you may safely ignore these following 6 cells in this block.
Once successfully complete the above steps, please:
** 1. Reload the page,
** ** 2. Select .NET (PowerShell) kernel
** ** 3. Then restart kernel **
Using Azure Notebooks
For this notebook we are going to be using PowerShell, so you will need to select the ".NET (PowerShell)" kernel in the dropdown on the top right corner of the notebook UI.
Once you have selected the right kernel, you are ready to move onto the next code cell.
Installing the required PowerShell modules
Code cells behave in the same way your code would in other environments, so you need to remember about common coding practices such as variable initialization and module/library imports. For this notebook you only need to make sure to install the required PowerShell modules since those are not installed by default.
Working with PowerShell within a Jupyter notebook - The Basics
In this section we added a few tips and tricks to using PowerShell in a notebook!
While there are differences between running PowerShell in a notebook environment vs a local machine, most features are support.
If you plan on porting your existing scripts, there are some modifications might need to be made to account for these differences.
Due to an additional UI+kernel intecepting your PowerShell commands, be sure to not overload the output as this can cause a chokepoint.
Also, since the output goes to a white (or black if darkmode is set) UI, some output colors might need to be modified to be visible.
Work with the display
Output to HTML or markdown.
Output from C# and visa versa. Yes, switching between DotNet languages is possible too
Download content
Prompt for information
Use progress bars or run commands in parallel
Microsoft Sentinel Configuration
Once we have set up our Jupyter environment with the libraries that we'll use in the notebook, we need to make sure we have some configuration in place. Some of the notebook components need addtional configuration to connect to external services (e.g. API keys to retrieve Threat Intelligence data). This includes configuration for connection to our Microsoft Sentinel workspace. For this notebook, we simply import the configuration from the config.json file that is created in your notebook explorer folder when you launch the notebook from the Microsoft Sentinel UI.
Connect to your Microsoft Sentinel workspace
Once you have configured your notebook, now you can connect to your workspace.
Note:
We changed the default foreground colors in case you are using the "Light" notebook UI theme, since the yellow output will be hard to see. Feel free to modify.
Access your hunting queries
Utilize the savedsearch API to download and run your hunting queries
Access your Microsoft Sentinel incidents
Utilize the Microsoft Sentinel API to download metadata regarding your incidents
Note: It could take a few seconds to download all of your incidents!
Chart your incidents using XPlot
Charts can be rendered using Xplot.Plotly. Here is a simple example on how to combine your incident data with XPlot.
Query your Microsoft Sentinel Data
Data within your Microsoft Sentinel workspace can be manipulated. My favorite part about working with notebooks is that I can extract values from one query or API call and use them as inputs to another query and/or API.
Note:
The query below requires the Heartbeat table. This was chosen as an example since it will reside in all Microsoft Sentinel workspaces.
For a more 'real world' example, pick another table or add your own query.
Match Microsoft Sentinel data with IOCs
You can also join data from external sources...
Enriching data
Now that we have seen how to query for data, we can see how you can enrich data with additional data sources.
For this we are going to use an external threat intelligence provider to give us some more details about a URL.
The example cell below assuming you have a VirusTotal (VT) key in your yaml configuration file
If you don't already have a VirusTotal API key, signup here.
If not, you can either hardcode the VT key in the cell or run the A Getting Started Guide for Microsoft Sentinel ML Notebooks notebook for instructions on how to create the configuration file with your VirusTotal key included.
Get your watchlist aliases and data
Retrieve your watchlist aliases and data by running the code below
Note: You must be part of the private preview program to use this feature. Sign-up at www.aka.ms/SecurityPrP to get started!