mimik.component_graph

Submodules

mimik.component_graph.abstract_task

class mimik.component_graph.abstract_task.AbstractTask(task_name: str, arguments: dict)[source]

Bases: ABC

forward()[source]

The default forward function of the task

Returns:

The static probability associated with the task

mimik.component_graph.component

class mimik.component_graph.component.Component(name: str, connected_component_names: list[str])[source]

Bases: object

add_system_name(system_name: str)[source]

Adds a system name to the component

Parameters:

system_name (str) – The system name to be added to the component

add_task(task: AbstractTask)[source]

Adds a task to the Component

Parameters:

task (AbstractTask) – The task to add to the component

mimik.component_graph.component_graph

class mimik.component_graph.component_graph.ComponentGraph(working_dir: str, silent=False)[source]

Bases: DiGraph

add_new_component(component_name: str, to_components: list[str], from_components: list[str], component_attributes: dict)[source]

Adds a new component to the killweb

Parameters:
  • component_name (str) – The name of the component to add

  • to_components (list[str]) – A list of the components the new component points to

  • from_components (list[str]) – A list of components the new component is pointed to by

  • component_attributes (dict) – A dictionary of component attributes including task, task_arguments, and system_name

add_new_edge(from_component: str, to_component: str)[source]

Adds a new edge to the killweb

Parameters:
  • from_component (str) – The origin component of the new edge

  • to_component (str) – The destination component of the new edge

add_task_to_component(component_name: str, task_name: str, task_arguments: dict)[source]

Adds a task to an existing component

Parameters:
  • component_name (str) – The name of the component to update

  • task_name (str) – The name of the task to add

  • task_arguments (dict) – The arguments of the task to add

get_component_on_click(event)[source]

Given a click event, determine what, if any, component was clicked

Parameters:

event (Event) – A mouse click event

Returns:

A component whose node in the graph was clicked on,

or None if no component was clicked

Return type:

Component

get_end_components()[source]

Gets all of the components ending a path in the killweb

Returns:

A list of component names for nodes who end paths

Return type:

list[str]

get_start_components()[source]

Gets all of the components starting a path in the killweb

Returns:

A list of component names for nodes who start paths

Return type:

list[str]

hover(event)[source]

The function to be called whenever the mouse hovers over the canvas. Checks if a node is being hovered over, and update the annotation box if so.

Parameters:

event – The hover event action including position data

load_killweb_from_config_file(config_filename: str)[source]

Loads a killweb from a given config file

Parameters:
  • killweb_name (str) – The name of the killweb to load

  • config_filename (str) – The config file to load from

networkx_visualization(show_and_save=True)[source]

Creates a star graph visualization by utilizing networkx to plot our existing nodes, edges, and attributes

Parameters:

show_and_save (bool) – True if the graph should be shown in save. Typically true when running without the GUI

Returns:

The created PyPlot figure

remove_component(component_name: str)[source]

Removes a component of the given name

Parameters:

component_name (str) – The name of the component to be removed

remove_existing_edge(from_component: str, to_component: str)[source]

Removes an edge from the killweb

Parameters:
  • from_component (str) – The origin component of the removed edge

  • to_component (str) – The destination component of the removed edge

save_killweb_to_config_file(filename: str, killweb_name: str)[source]

Saves the current killweb to a file

Parameters:
  • filename (str) – The file path to save to

  • killweb_name (str) – The name of the killweb to save

update_annotation(index)[source]

Updates the annotation box with the hovered node contents

Parameters:

index (int) – The index of the node being hovered over

mimik.component_graph.component_graph_capabilities

class mimik.component_graph.component_graph_capabilities.ComponentGraphCapabilities(graph: ComponentGraph)[source]

Bases: object

get_all_paths()[source]

Gets a list of all paths in the killweb that are capable of accomplishing each task

Returns:

A list of paths resembling kill chains

Return type:

list[str]

get_monte_carlo_outcomes()[source]

Returns the outcome of the Monte Carlo simulation

Returns:

A dictionary mapping paths to arrays containing results

Return type:

dict

get_monte_carlo_probabilities()[source]

Returns the probabilities derived from the Monte Carlo simulation

Returns:

A dictionary mapping paths to arrays containing path probabilities

Return type:

dict

monte_carlo_simulation(num_iterations: int)[source]

Gets a list of success probabilities for each path and sorts them

Parameters:

num_iterations (int) – The number of times to calculate probability of a path for an average

Returns:

The probability list of each simple path over num_iterations

print_all_paths()[source]

Prints all of the paths in the component graph

validate_graph(graph: ComponentGraph) bool[source]

Validates the ComponentGraph to ensure each component has a task

Parameters:

graph (ComponentGraph) – The graph to validate

Returns:

True if the ComponentGraph has a task for each component

Return type:

bool

mimik.component_graph.component_graph_metrics

class mimik.component_graph.component_graph_metrics.ComponentGraphMetrics(capabilities: ComponentGraphCapabilities)[source]

Bases: object

average_num_success(path: list[str]) float[source]

Calculates the average number of success events for each component in a path

Parameters:

path (list[str]) – The path to check the average number of successful components

Returns:

The average number of successful components within the path

calc_stats_of_paths()[source]

Calculates the probability of success for each path after Monte Carlo sim

Returns:

A dictionary of probabilities

calculate_variance(path: list[str]) float[source]

Calculates the variance of the monte carlo outcomes

Parameters:

path (list[str]) – The path to calculate variance from

Returns:

The variance of the monte carlo outcomes

Return type:

float

compute_node_centrality()[source]

Computes and sorts the in and out centrality of each component of the graph

Returns:

A list of two arrays each containing a list of key value pairs of components to their centralities

convert_path_to_string(path: list[str]) str[source]

Converts a path, definied as a list of node names, to a single string

Parameters:

path (list[str]) – The path to convert

Returns:

A string representation of the path

plot_MC_distribution(path: list[str])[source]

Plot the distrubtion of successes across the components within a path

Parameters:

path (list[str]) – The path whose components are to be plotted with respect to their distribution of successful events

print_probability_of_paths(print_top_n_paths=None, selected_component=None)[source]

Gets a list of success probabilities for each path and sorts them

Parameters:
  • print_top_n_paths (int) – Print the X number of paths with the highest probability

  • selected_component (str) – The path whose node should be included in the path

Returns:

The probability list of each simple path

proportion_complete(path: list[str]) float[source]

Calculates the proportion of simulations that succeed through the path

Parameters:

path (list[str]) – The path to check the proportion of iterations that succeed

Returns:

The proportion of times the path succeed to when it doesn’t

mimik.component_graph.task_factory

class mimik.component_graph.task_factory.TaskFactory(task_folder: str, silent: bool)[source]

Bases: object

create_task(task_name: str, arguments: dict)[source]

Attempts to return a task associated with the given name. If the task cannot be found, an AbstractTask is returned instead that assumes a static probability is found within the arguments parameter.

Parameters:
  • task_name (str) – The name of the task to create

  • arguments (dict) – The dictionary of arguments to include for the given task

Returns:

The created task

Module contents