Skip to content

Commit

Permalink
Merge pull request #130 from CrowdStrike/feat/128/containment-guard-r…
Browse files Browse the repository at this point in the history
…ails

Visual Guard Rail for Network Containment
  • Loading branch information
ChristopherHammond13 authored Apr 16, 2024
2 parents b4d5206 + 66ab9a2 commit 2342cd6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
40 changes: 39 additions & 1 deletion falcon_toolkit/containment/perform_containment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import tabulate

from caracara import Client
from caracara.common.csdialog import csradiolist_dialog


def result_output(
Expand Down Expand Up @@ -71,6 +72,38 @@ def result_output(
))


def guard_rail_confirmation(device_count: int, action: str) -> bool:
"""Confirm via a visual Prompt Toolkit box whether the user really wants to (un)contain."""
if action == "contain":
confirmation_options = [
(False, "Abort"),
(True, f"Network contain {device_count} devices"),
]
prompt_text = f"Are you sure you want to network contain {device_count} devices?"
else:
confirmation_options = [
(False, "Abort"),
(True, f"Release {device_count} devices from network containment"),
]
prompt_text = (
f"Are you sure you want to release {device_count} devices "
"from network containment?"
)

confirmation: bool = csradiolist_dialog(
title="Confirm Network Containment Action",
text=prompt_text,
values=confirmation_options,
).run()

if confirmation:
click.echo(click.style("User confirmed action", bold=True, fg='green'))
return True

click.echo(click.style("Aborted!", bold=True, fg='red'))
return False


def perform_containment_action(
device_ids: List[str],
client: Client,
Expand All @@ -82,12 +115,17 @@ def perform_containment_action(
if action not in ("contain", "lift_containment"):
raise ValueError(f"{action} is not a supported device action in this function")

device_count = len(device_ids)
if not guard_rail_confirmation(device_count, action):
return

limit = 100
resources = []
errors = []

for i in range(0, len(device_ids), limit):
for i in range(0, device_count, limit):
click.echo("Changing the network containment status on a batch of systems...", nl=False)

response = client.hosts.hosts_api.perform_action(
action_name=action,
ids=device_ids[i: i + limit],
Expand Down
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "falcon-toolkit"
version = "3.4.0"
version = "3.4.1"
description = "Toolkit to interface with CrowdStrike Falcon via the API"
license = "MIT"
authors = [
Expand Down

0 comments on commit 2342cd6

Please sign in to comment.