msticpy.context.tiproviders.riskiq module

RiskIQ Threat Intelligence Provider.

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.

class msticpy.context.tiproviders.riskiq.RiskIQ(**kwargs)

Bases: TIProvider, TIPivotProvider

RiskIQ Threat Intelligence Lookup.

Instantiate RiskIQ class.

property ioc_query_defs: Dict[str, Any]

Return current dictionary of IoC query/request definitions.

Returns:

IoC query/request definitions keyed by IoCType

Return type:

Dict[str, Any]

classmethod is_known_type(item_type: str) bool

Return True if this a known IoC Type.

Parameters:

item_type (str) – IoCType string to test

Returns:

True if known type.

Return type:

bool

is_supported_type(item_type: str | IoCType) bool

Return True if the passed type is supported.

Parameters:

item_type (Union[str, Type]) – type name or instance

Returns:

True if supported.

Return type:

bool

property item_query_defs: Dict[str, Any]

Return current dictionary of IoC query/request definitions.

Returns:

IoC query/request definitions keyed by IoCType

Return type:

Dict[str, Any]

lookup_ioc(ioc: str, ioc_type: str | None = None, query_type: str | None = None, **kwargs) DataFrame

Lookup a single IoC observable.

Parameters:
  • ioc (str) – IoC Observable value

  • ioc_type (str, optional) – IoC Type, by default None (type will be inferred)

  • query_type (str, optional) – Specify the data subtype to be queried, by default None. If not specified the default record type for the IoC type will be returned.

Returns:

The returned results.

Return type:

pd.DataFrame

lookup_iocs(data: DataFrame | Dict[str, str] | Iterable[str], ioc_col: str | None = None, ioc_type_col: str | None = None, query_type: str | None = None, **kwargs) DataFrame

Lookup collection of IoC observables.

Parameters:
  • data (Union[pd.DataFrame, Dict[str, str], Iterable[str]]) – Data input in one of three formats: 1. Pandas dataframe (you must supply the column name in ioc_col parameter) 2. Dict of observable, IoCType 3. Iterable of observables - IoCTypes will be inferred

  • ioc_col (str, optional) – DataFrame column to use for observables, by default None

  • ioc_type_col (str, optional) – DataFrame column to use for IoCTypes, by default None

  • query_type (str, optional) – Specify the data subtype to be queried, by default None. If not specified the default record type for the IoC type will be returned.

Returns:

DataFrame of results.

Return type:

pd.DataFrame

async lookup_iocs_async(data: DataFrame | Dict[str, str] | Iterable[str], ioc_col: str | None = None, ioc_type_col: str | None = None, query_type: str | None = None, **kwargs) DataFrame

Call base async wrapper.

lookup_item(item: str, item_type: str | None = None, query_type: str | None = None, **kwargs) DataFrame

Lookup a single item.

Parameters:
  • item (str) – Item value to lookup

  • item_type (str, optional) – The Type of the value to lookup, by default None (type will be inferred)

  • query_type (str, optional) – Specify the data subtype to be queried, by default None. If not specified the default record type for the item_value will be returned.

Returns:

The lookup result: result - Positive/Negative, details - Lookup Details (or status if failure), raw_result - Raw Response reference - URL of the item

Return type:

pd.DataFrame

Raises:

NotImplementedError – If attempting to use an HTTP method or authentication protocol that is not supported.

Notes

Note: this method uses memoization (lru_cache) to cache results for a particular observable to try avoid repeated network calls for the same item.

lookup_items(data: DataFrame | Dict[str, str] | Iterable[str], item_col: str | None = None, item_type_col: str | None = None, query_type: str | None = None, **kwargs) DataFrame

Lookup collection of items.

Parameters:
  • data (Union[pd.DataFrame, Dict[str, str], Iterable[str]]) – Data input in one of three formats: 1. Pandas dataframe (you must supply the column name in item_col parameter) 2. Dict of items 3. Iterable of items

  • item_col (str, optional) – DataFrame column to use for items, by default None

  • item_type_col (str, optional) – DataFrame column to use for types, by default None

  • query_type (str, optional) – Specify the data subtype to be queried, by default None. If not specified the default record type for the type will be returned.

Returns:

DataFrame of results.

Return type:

pd.DataFrame

async lookup_items_async(data: DataFrame | Dict[str, str] | Iterable[str], item_col: str | None = None, item_type_col: str | None = None, query_type: str | None = None, **kwargs) DataFrame

Lookup collection of items.

Parameters:
  • data (Union[pd.DataFrame, Dict[str, str], Iterable[str]]) – Data input in one of three formats: 1. Pandas dataframe (you must supply the column name in item_col parameter) 2. Dict of items, Type 3. Iterable of items - Types will be inferred

  • item_col (str, optional) – DataFrame column to use for items, by default None

  • item_type_col (str, optional) – DataFrame column to use for Types, by default None

  • query_type (str, optional) – Specify the data subtype to be queried, by default None. If not specified the default record type for the item will be returned.

Returns:

DataFrame of results.

Return type:

pd.DataFrame

property name: str

Return the name of the provider.

parse_results(response: Dict) Tuple[bool, ResultSeverity, Any]

Return the details of the response.

Parameters:

response (Dict) – The returned data response

Returns:

bool = positive or negative hit ResultSeverity = enumeration of severity Object with match details

Return type:

Tuple[bool, ResultSeverity, Any]

pivot_value(prop, host, **kwargs)

Perform a pivot on a single value.

register_pivots(pivot_reg: PivotRegistration, pivot: Pivot)

Register pivot functions for the TI Provider.

Parameters:
  • pivot_reg (PivotRegistration) – Pivot registration settings.

  • pivot (Pivot) – Pivot library instance

static resolve_ioc_type(observable: str) str

Return IoCType determined by IoCExtract.

Parameters:

observable (str) – IoC observable string

Returns:

IoC Type (or unknown if type could not be determined)

Return type:

str

static resolve_item_type(item: str) str

Return Type determined by ItemExtract.

Parameters:

item (str) – Item string

Returns:

Type (or unknown if type could not be determined)

Return type:

str

property supported_types: List[str]

Return list of supported types for this provider.

Returns:

List of supported type names

Return type:

List[str]

classmethod usage()

Print usage of provider.

exception msticpy.context.tiproviders.riskiq.RiskIQAPIUserError(api_exception: passivetotal.analyzer.AnalyzerAPIError)

Bases: RiskIQUserError

RiskIQ API provider exception.

Create RiskIQ API exception.

Parameters:

api_exception (ptanalyzer.AnalyzerAPIError) – Underlying API exception.

DEF_HELP_URI = ('msticpy documentation', 'https://msticpy.readthedocs.org')
args
display_exception()

Output the exception HTML or text friendly exception.

property help_uri: Tuple[str, str] | str

Get the default help URI.

classmethod no_display_exceptions()

Context manager to block exception display to IPython/stdout.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception msticpy.context.tiproviders.riskiq.RiskIQUserError(*args, help_uri: Tuple[str, str] | str | None = None, **kwargs)

Bases: MsticpyUserError

Generic RiskIQ provider exception.

Create RiskIQ provider exception.

Parameters:

help_uri (Union[Tuple[str, str], str, None], optional) – Override the default help URI.

DEF_HELP_URI = ('msticpy documentation', 'https://msticpy.readthedocs.org')
args
display_exception()

Output the exception HTML or text friendly exception.

property help_uri: Tuple[str, str] | str

Get the default help URI.

classmethod no_display_exceptions()

Context manager to block exception display to IPython/stdout.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.