Path: blob/master/scenario-notebooks/Guided Hunting - Office365-Exploring.ipynb
3250 views
Guided Hunting - Office 365 Explorer
**Python Version:** Python 3.6 (including Python 3.6 - AzureML)
**Required Packages**: kqlmagic, msticpy, pandas, numpy, matplotlib, seaborn, ipywidgets, ipython, scikit_learn, folium, maxminddb_geolite2
Data Sources Required:
Log Analytics - OfficeActivity, IPLocation, Azure Network Analytics
Brings together a series of queries and visualizations to help you investigate the security status of Office 365 subscription and individual user activities.
The first section focuses on Tenant-Wide data queries and analysis
The second section allows you to focus on individial accounts and examine them for any suspicious activity.
This notebook is intended to be illustrative of the types of data available in Office 365 Activity data and how to query and use them. It is not meant to be used as a prescriptive guide to how to navigate through the data.
Feel free to experiment and submit anything interesting you find to the community.
Table of Contents
- Notebook initialization
- Office 365 Activity
- Tenant-wide Information
- Summary of O365 Activity Types
- Variability of IP Address for users
- Accounts with multiple IPs and Geolocations
- Choose threshold to show User Logons where User has logged on from > N IP Address in period
- Matrix of Selected Operation Types by Location and IP
- Geolocation Map of Client IPs
- Graphical Activity Timeline
- Users With largest Activity Type Count
- Office User Investigation
- Rare Combinations of Country/UserAgent/Operation Type
- Available DataFrames
- Saving Data to Excel
Notebook initialization
The next cell:
Checks for the correct Python version
Checks versions and optionally installs required packages
Imports the required packages into the notebook
Sets a number of configuration options.
This should complete without errors. If you encounter errors or warnings look at the following two notebooks:
If you are running in the Microsoft Sentinel Notebooks environment (Azure Notebooks or Azure ML) you can run live versions of these notebooks:
You may also need to do some additional configuration to successfully use functions such as Threat Intelligence service lookup and Geo IP lookup. There are more details about this in the ConfiguringNotebookEnvironment notebook and in these documents:
Get WorkspaceId and Authenticate to Log Analytics
Use the following syntax if you are authenticating using an Azure Active Directory AppId and Secret:
instead of
Note: you may occasionally see a JavaScript error displayed at the end of the authentication - you can safely ignore this.
On successful authentication you should see a popup schema button. To find your Workspace Id go to Log Analytics. Look at the workspace properties to find the ID.
Configuration
msticpyconfig.yaml configuration File
You can configure primary and secondary TI providers and any required parameters in the msticpyconfig.yaml file. This is read from the current directory or you can set an environment variable (MSTICPYCONFIG) pointing to its location.
To configure this file see the ConfigureNotebookEnvironment notebook
Office 365 Activity
Log Analytics Queries and query time window
Tenant-wide Information
Summary of O365 Activity Types
Warning this query can be time consuming for large O365 subscriptions
Variability of IP Address for users
Accounts with multiple IPs and Geolocations
Choose threshold to show User Logons where User has logged on from > N IP Address in period
Matrix of Selected Operation Types by Location and IP
Geolocation Map of Client IPs
Graphical Activity Timeline
Users With largest Activity Type Count
Details of user operations
Office User Investigation
Activity Summary
Operation Breakdown for User
IP Count for Different User Operations
Activity Timeline
User IP GeoMap
Check for User IPs in Azure Network Flow Data
The full data is available in the Dataframe az_net_query_byip
Rare Combinations of Country/UserAgent/Operation Type
The dataframe below lists combinations in the time period that had less than 3 instances. This might help you to spot relatively unusual activity.
Appendices
Available DataFrames
Saving Data to Excel
To save the contents of a pandas DataFrame to an Excel spreadsheet use the following syntax