Path: blob/master/tutorials-and-examples/feature-tutorials/TIProviders.ipynb
3253 views
msticpy Threat Intel Lookup
This notebook describes the use of the Threat Intelligence lookup class in msticpy. The class allows lookup of individual or multiple IoCs from one or more TI providers.
TILookup is also extensible - you can subclass TIProvider to implement your own custom lookups. You can also subclass the HTTPProvider or KqlProvider classes, which provide support for querying a REST endpoint or Log Analytics table respectively.
You must have msticpy installed to run this notebook:
To use the Microsoft Sentinel Threat Intel provider you will also need the "azsentinel" components:
TILookup class
Input can be a single IoC observable or a pandas DataFrame containing multiple observables. Processing may require a an API key and processing performance may be limited to a specific number of requests per minute for the account type that you have.
Constructor
Attributes
add_provider()
available_providers()
browse_results()
configured_providers()
list_available_providers()
loaded_providers()
lookup_ioc()
lookup_iocs()
provider_status()
provider_usage()
reload_provider_settings()
reload_providers()
result_to_df()
Available Providers
The msticpy TI Provider library can lookup IoCs in multiple providers.
The list below shows the current set of providers.
You can view the list of supported query types for each provider with the show_query_types=True parameter
Loading TIProviders
Calling TILookup with no parameters will load all of the available providers that have a configuration entry in msticpyconfig.yaml (see next section)
Configuration File
You can configure primary and secondary providers. Primary providers are used by default.
You may need to supply an authorization (API) key and in some cases a user ID for each provider.
For LogAnalytics/Microsoft Sentinel providers, you will need the workspace ID and tenant ID and will need to authenticate in order to access the data (although if you have an existing authenticated connection with the same workspace/tenant, this connection will be re-used).
The configuration file is read from the current directory.
Alternatively, you can specify a location for this file in an environment variable MSTICPYCONFIG.
If you need to create a config file, uncomment the lines in the following cell.
Warning - this will overwrite a file of the same name in the current directory
Delete any provider entries that you do not want to use and add the missing parameters for your providers.
Reload providers to pick up new settings
Looking up IoCs
lookup_ioc
To lookup a single IoC.
Lookup an IoC from a single provider
And show the output
Or convert result to a DataFrame and let pandas do the display work...
Lookup using all primary providers
Provider Usage
This shows the supported IoC Types.
In some cases an IoC type will also support special types of sub-query such as geo-ip and passive-dns
Use to do a passive DNS lookup
Use to do a GeoIP lookup
Inferring IoC Type vs. Specifying explicity
If you do a lookup without specifying a type, TILookup will try to infer the type by matching regexes. There are patterns for all supported types but there are some caveats:
The match is not 100% foolproof - e.g. some URLs and hash types may be misidentified.
The inference adds an overhead to each lookup.
If you know the type that you want to look up, it is always better to explicitly include it.
For single IoC lookup, use the
ioc_typeparameter.For multiple IoC lookups (see below), supply either:
a DataFrame with a column that specifies the type for each entry
a dictionary of the form
{ioc_observable: ioc_type}
Looking up Multiple IoCs
lookup_iocs
Multiple IP Lookup from single provider
Multiple IoCs using all providers
Output sorted by IoC
Note that these URLs were picked randomly from the TI databases of the three providers used. In most cases the IoC is found by only that provider, which
Multiple Mixed IoC Types
Browsing TI Results
To make it easier to walk through the returned results there is a browser. This shows you results aggregated by the IoC value (e.g. an individual IP Address or URL) for all providers.
For each provider that returns a result for an IoC, the summarized details will be shown in a table below the browse list. Click on Raw results from provider... to see all returned data.
Note: the reference URL may not work if you have not authenticated to the service
The value of the selected IoC entry is available as ti_selector.value
You can match this back to the original results DataFrame as follows:
Specifying Time Ranges
Some providers (currently only AzSTI) support time ranges so that you can specify specific periods to search for.
If a provider does not support time ranges, the parameters will be ignored