Path: blob/master/machine-learning-notebooks/Guided Hunting - Anomalous Process Network Connections.ipynb
3250 views
Guided Hunting - Anomalous Process Network Connections
**Required Packages**: msticpy, pandas, numpy, matplotlib, plotly, ipywidgets, ipython, sklearn
Data Sources Required:
Log Analytics - DeviceNetworkEvents
Brings together a series of queries and visualizations to help you investigate anomalous processes in your network. There are then guided hunting steps to investigate these occurences in further dept. This notebook authenticates with environment variables and requires the following:
msticpyconfig.yaml has been properly configured
Registered application has been created with API permissions given to Log Analytics API
Key vault set up with a secret to the Registered Application
Setup Environment Variables
Please set the following environment variables in the code block below:
AZURE_TENANT_ID
AZURE_CLIENT_ID
key_vault_name
key_vault_url
secret_client
Verify Environment Variables are Set
You should see the values of the following:
AZURE_TENANT_ID
AZURE_CLIENT_ID
AZURE_CLIENT_SECRET
Setup msticpyconfig.yaml
Ensure your msticpyconfig.yaml has been set up and saved in the current directory you are running this notebook.
Setup QueryProvider
Connect to Sentinel
You should see "connected" output after running this code block. Once you are connected, you can continue on with the notebook.
Run Anomaly Detection Script - Anomalous Processes
Change your KQL to reduce your data. Enter the field name you want to run the IsolationForest algorithm on to identify anomalies. This script is set to search for anomalous processes on the network. It is recommended to change the contamination rate to fit your environment. The bigger the environment, the smaller the contamination rate will likely need to be. After you select the "Analyze" button, you can search the data frame with the "Column" and "Value" text widgets. There is an option to graph the top ten most significant anomalies based on "Anomaly Score" with the "Graph Results" button.
What to do with this Information
Take note of the any of the anomalies that were generated. You can focus on the Top Anomalies from the graph or all of the anomalies from the data frame. A reminder that anything with a field value of "Anomaly = -1" was deemed to be anomalous process generating a successful network connection. You can follow some of the techniques below to investigate these anomalous processes further. In each of the following queries, it ends with "df.head(10)". This displays 10 results. If you want to change that number, just change the number 10 to the desired amount of results you would like to see.
Verify Parent Process
It is common to see a malicious process spawn from normal process. You can check the anomalous processes that were identified to see if there is anything unusual with the parent process of the original anomalous process. Replace process1.exe, process2.exe, and process3.exe with the names of the anomalous processes.
Check if Process Spawned out of Temp File Path
Attackers commonly use a TEMP folder to spawn malicious processes. Ensure the anomalous process did not spawn out of this direction. Replace process1.exe, process2.exe, and process3.exe with the names of the anomalous processes.
Check if cmd.exe or Powershell was Used
Actors will sometimes use remote code execution with cmd.exe or powershell in coordination with other processes. The following KQL will verify this. Replace process1.exe, process2.exe, and process3.exe with the names of the anomalous processes.