Path: blob/master/tutorials-and-examples/example-notebooks/Example - Guided Hunting - Office365-Exploring.ipynb
3253 views
Title: Office 365 Explorer
Notebook Version: 1.0
Python Version: Python 3.10 (including Python 3.10 - SDK v2 - AzureML)
Required Packages: kqlmagic, msticpy, pandas, numpy, matplotlib, seaborn, networkx, ipywidgets, ipython, scikit_learn, folium, maxminddb_geolite2, holoviews
Platforms Supported:
Azure Notebooks Free Compute
Azure Notebooks DSVM
OS Independent
Data Sources Required:
Log Analytics - OfficeActivity, IPLocation, Azure Network Analytics
Description:
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.
Warning: Example Notebook - No longer supported!
 This notebooks is meant to be illustrative of specific scenarios and is not actively maintained. It is unlikely to be runnable directly in your environment. Instead, please use the notebooks in the root of this repo.Â
Table of Contents
Setup
Make sure that you have installed packages specified in the setup (uncomment the lines to execute)
Install Packages
The first time this cell runs for a new Azure Notebooks project or local Python environment it will take several minutes to download and install the packages. In subsequent runs it should run quickly and confirm that package dependencies are already installed. Unless you want to upgrade the packages you can feel free to skip execution of the next cell.
If you see any import failures (ImportError) in the notebook, please re-run this cell and answer 'y', then re-run the cell where the failure occurred.
Note you may see some warnings about package incompatibility with certain packages. This does not affect the functionality of this notebook but you may need to upgrade the packages producing the warnings to a more recent version.
Get WorkspaceId
To find your Workspace Id go to Log Analytics. Look at the workspace properties to find the ID.
Read Workspace configuration from local config.json for workspace ASIHuntOMSWorkspaceV4
TENANT_ID: 72f988bf-86f1-41af-91ab-2d7cd011db47
SUBSCRIPTION_ID: 40dcc8bf-0478-4f3b-b275-ed0a94f2c013
RESOURCE_GROUP: ASIHuntOMSWorkspaceRG
WORKSPACE_ID: 52b1ab41-869e-4138-9e40-2a4457f09bf0
WORKSPACE_NAME: ASIHuntOMSWorkspaceV4
Authenticate to Log Analytics
If you are using user/device authentication, run the following cell.
Click the 'Copy code to clipboard and authenticate' button.
This will pop up an Azure Active Directory authentication dialog (in a new tab or browser window). The device code will have been copied to the clipboard.
Select the text box and paste (Ctrl-V/Cmd-V) the copied value.
You should then be redirected to a user authentication page where you should authenticate with a user account that has permission to query your Log Analytics workspace.
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.
Current data in workspace
Office 365 Activity
Log Analytics Queries
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
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
Distinct User Agent Strings in Use
IPs and User Agents - frequency of use
Distinct UserAgents by num of operations
Graphical Activity Timeline
Change in rate of Activity Class (RecordType) and Operation
Users With largest Activity Type Count
Identify Users/IPs with largest operation count
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.
Rarest combinations
Most common operations
Appendices
Available DataFrames
Saving Data to Excel
To save the contents of a pandas DataFrame to an Excel spreadsheet use the following syntax