Path: blob/master/tutorials-and-examples/training-notebooks/Training - MSTICPy Training 3 - 2022-01-13.ipynb
3253 views
MSTICPy - Intermediate/Advance Use
Notebooks and Microsoft Sentinel Training #3
msticpy is a library for InfoSec investigation and hunting in Jupyter Notebooks. It includes functionality to:
query log data from multiple sources
enrich the data with Threat Intelligence, geolocations and Azure resource data
extract Indicators of Activity (IoA) from logs and unpack encoded data
perform sophisticated analysis such as anomalous session detection and time series decomposition
visualize data using interactive timelines, process trees and multi-dimensional Morph Charts
It also includes some time-saving notebook tools such as widgets to set query time boundaries, select and display items from lists, and configure the notebook environment.
Source Code: https://github.com/microsoft/msticpy
Python Package: https://pypi.org/project/msticpy/
Contents
1. Introduction
1.1 What's New
1.2 Optional components/dependencies
2. Data Queries
2.1 Recap
2.2 Parameters
2.3 Query time ranges
2.4 Querying other data sources - Microsoft Defender 365
2.5 Creating/saving your own queries
3. Incident Triage
4. Enriching data with Threat Intelligence (and others)
4.1 Introduction to Pivot functions
4.2 Pivot on individual values
4.3 Pivot from DataFrames
4.4 Joining input to your output
4.5 Pivoting with RiskIQ
5. Visualization
5.1 Timelines and timeline values
5.2 Matrix plots for large data sets
5.3 Process Trees
5.4 Time series for temporal pattern anomalies
6. Extras
6.1 Open Threat Research Security Data sets
7. Conclusion and Resources
1. Introduction
1.1 Background
Watch the first two parts of this series
1.2 What's new
Single sign-on with Managed Identities
Your sign-in credentials from Azure Machine Learning are used automatically for MS Sentinel
You can override this (in the query provider) with
mp_az_auth=False(see later)
The MSTICPy Configuration tool now works in non-geological timescales in Azure Machine Learning!
1.3 Extras - installing optional dependencies
Notes:
1. This doesn't affect the MSTICPy code that's installed - only the dependencies
2. Often, you won't need this unless you want the specific *extra* functionality
3. Use %pip within the notebook, not !pip.
MSTICPy is a library with a broad range of functionality and a lot of dependencies. As such, installing all of the dependencies can take a lot of time.
MSTICPy has implemented a series of Extras that allow for subsets of these dependencies. These Extras are grouped around core technologies that you might want to use with MSTICPy.
| Extra | Functionality |
|---|---|
| --none-- | Most functionality (approx 75%) Kqlmagic Jupyter basic |
| keyvault | Key Vault and keyring storage of settings secrets |
| azure | Azure API data retrieval, Azure storage APIs, Sentinel APIs |
| kql | Kqlmagic Jupyter extended functionality |
| azsentinel | Combination of core install + "azure", "keyvault", "kql" |
| ml | Timeseries analysis, Event clustering, Outlier analysis |
| splunk | Splunk data queries |
| vt3 | VirusTotal V3 graph API |
| riskiq | RiskIQ Illuminate threat intel provider & pivot functions |
| all | Includes all of above packages |
| dev | Development tools plus "base" |
| test | "dev" plus "all" |
To install a specific Extra, use the following syntax: %pip install msticpy[extra]
You can also install multiple extras at once: %pip install msticpy[extra1,extra2,...]
If you see this kind of exception - install the extra mentioned
2. Data Queries
2.1. Recap
In the last training session we covered:
Authenticating to Microsoft Sentinel
Browsing and listing queries
Running queries
New and Improved!
Once set up we can tell the QueryProvider to connect which will kick off the authentication process.
Old way
Integrated auth with MSI
2.3 Query parameters
Where did start and end parameters come from?
2.3 Query Times
Can set start and end parameters manually
Python datetimes
datetime strings
integers/floats (days, relative to now)
2.4 Querying other data sources - Microsoft Defender 365
2.5 Creating/saving your own queries
A template query looks like this
It is query language-agnostic
Parameters are substituted using Python format strings
you might need to quote the parameter
or invoke a conversion function in the target language
Steps
Create your query file(s)
Save them to a folder
Add this to your
msticpyconfig.yamlor specify at runtime as param to QueryProvider
Config
Runtime parameter
See Creating Custom Queries for more details
3. Incident Explorer
See forthcoming Guided Investigation - Incident Triage notebook
4. Enriching data with Threat Intelligence (and others)
4.1 Introduction to Pivot functions
4.2 Pivot on individual values
4.3 Pivot from DataFrames
4.4 Joining input to your output
4.5 Pivoting with RiskIQ
Threat intelligence enrichment recap
Azure Data Enrichment
MSTICPy also includes a number of Azure API integrations that can be used to enrich your data with additional data about Azure Resources. These are available in two formats, via the AzureData feature of MSTICPy and also via the new Azure Resource Graph data connector.
See https://msticpy.readthedocs.io/data_acquisition/AzureData.html
We can also use the AzureSentinel (soon to be renamed) class to get details about specific Microsoft Sentinel elements.
See https://msticpy.readthedocs.io/data_acquisition/AzureSentinel.html
4.1 Introduction to Pivot Functions
Pivot functions are methods of entities that provide:
data queries related to an entity
enrichment functions relevant to that entity
Pivot functions are dynamically attached to entities. We created this framework to make it easier to find which functions you can use for which entity type.
Motivation
We had built a lot of functionality in MSTICPy for querying and enrichment
A lot of the functions had inconsistent type/parameter signatures
There was no easy discovery mechanism for these functions - you had to know
Using entities as pivot points is a "natural" investigation pattern
Access functionality from entities
4.2 Pivot on individual values
Queries are pivot functions too
4.3 Pivot on DataFrames and Lists
entity.pivot_func(list_or_iterable)
entity.pivot_func(dataframe, column="col_name")
4.4 Joining input to output
Creating Pivot pipelines - DataFrames as input and output
4.5 RiskIQ Pivots
5. Visualization
5.1 Timelines and timeline values
5.2 Matrix plots for large data sets
5.3 Process Trees
5.4 Time series for temporal pattern anomalies
Most visualization functionality is available through DataFrame.mp_plot.vis_func()
5.1 Timelines and timeline values
5.3 Matrix plots
Often these are useful at large scale for showing patterns of behavior and highlighting significant changes.
5.4 Process Trees
Schema-dependent
Works with:
MS Sentinel/WEVT Windows process events
Linux Auditd logs
MDE DeviceProcess events
Sysmon - thanks Nicholas Bareil!
Custom schemas can be used.
5.5 Time series analysis
Note: your data set must:
Be at least 1 week long
Grouped/aggregated by a time interval (e.g. 1 hour)
Have a scalar value column (number of logons, bytes transmitted, etc.)
6. Extras
6.1 OTRF Security Datasets
7. Conclusion and Resources
Conclusion
Notebooks give the kind of flexibility not found in any SIEM (including Sentinel)
Create your own reusable analysis flows
Capture progress as it happens
Automate complex detections and observation patterns
There is a learning curve - be prepared to invest some time
But the payoff in capability is worth it
Lots of functionality in MSTICPy and more being added all the time
Actions
Watch the training videos 📺
Watch InfoSec Jupyterthon workshops 📺
Play around with template and sample notebooks
Visit MSTICPy GitHub repo and leave us a star ⭐
Read the MSTICPy docs 📓
MSTICPy Hackathon - On Now!
Come and contribute/fix some code - https://github.com/microsoft/msticpy/wiki/MSTICPy-January-2022-Hackathon
Contacts
@ianhellen (Twitter and Discord) @ianhelle (Github)
@MSSPete (twitter), @petebryan (GitHub)
Discord OTRF Jupyter Channel https://discordapp.com/channels/717911137915764877/915326424846594179
MSTICPy Issues - https://github.com/microsoft/msticpy/issues