From bfd853fc767bba187fc01d182c8983e98446f245 Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 17 Sep 2025 09:31:25 -0400 Subject: [PATCH] Took safeties and turned them into a preflight test so we no longer have to toggle --- AirlockTools.py | 15 +++++++++++++++ utils/policyfunctions.py | 40 ++++++++++++++++++++++++++++++++++++++-- utils/pretty.py | 5 ++++- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/AirlockTools.py b/AirlockTools.py index 6042242..9f9aa7a 100644 --- a/AirlockTools.py +++ b/AirlockTools.py @@ -271,7 +271,22 @@ def menu_prepare_to_enforce(): allowlist_child_name = allowlists[choice] allowlist_child_id = allowid[choice] + elif choice == "6": + if os.path.exists(f"preflight\\final_path_exclusions_{first_policy}_{second_policy}.html") and os.path.exists(f"preflight\\final_hash_approvals_{first_policy}_{second_policy}.html") and allowlist_parent_name != " " and allowlist_child_name != " " and destination_name != " ": + utils.policyfunctions.sendToPolicyTest( + url, + first_policy, + second_policy, + destination_name, + destination_id, + allowlist_parent_name, + allowlist_parent_id, + allowlist_child_name, + allowlist_child_id + ) + + elif choice == "7": if os.path.exists(f"preflight\\final_path_exclusions_{first_policy}_{second_policy}.html") and os.path.exists(f"preflight\\final_hash_approvals_{first_policy}_{second_policy}.html") and allowlist_parent_name != " " and allowlist_child_name != " " and destination_name != " ": utils.policyfunctions.sendToPolicy( url, diff --git a/utils/policyfunctions.py b/utils/policyfunctions.py index 0037a37..c3f16bf 100644 --- a/utils/policyfunctions.py +++ b/utils/policyfunctions.py @@ -35,7 +35,6 @@ def addHash(url, policy, hash): pass # print(p) - def addPath(url, policy, hash): print(f"Adding the following Path Exclusions to {policy}:") for p in hash: @@ -137,6 +136,8 @@ def sendToPolicy(url, first_policy, second_policy, destination_name, destination addPathReal(url, destination_id,processed_paths) + print(ct.colorText(f"Adding publishers to {destination_name}", "yellow")) + publisher_list = publishers['publisher'].tolist() addPubReal(url, destination_id, publisher_list) @@ -285,4 +286,39 @@ def skipback(days): hex_timestamp = format(timestamp, '08x') objectid_hex = hex_timestamp + '0000000000000000' return ObjectId(objectid_hex) - \ No newline at end of file + +def sendToPolicyTest(url, first_policy, second_policy, destination_name, destination_id, allowlist_parent_name, allowlist_parent_id, allowlist_child_name, allowlist_child_id): + pathexclusions = pd.read_parquet(f"parquet\\final_path_exclusions_{first_policy}_{second_policy}.parquet") + allowbyhash = pd.read_parquet(f"parquet\\final_hash_approvals_{first_policy}_{second_policy}.parquet") + publishers = pd.read_parquet(f"parquet\\publishers_{first_policy}_{second_policy}.parquet") + + + print(ct.colorText(f"These path exclusions would be added to {destination_name}", "yellow")) + + # Get unique combinations of longestcfp and file_extension + unique_combinations = pathexclusions[["longestcfp", "file_extension"]].drop_duplicates() + + # Regex to match a Windows drive letter at the start (e.g., C:\) + drive_letter_pattern = re.compile(r'^[a-zA-Z]:\\') + + # Build processed paths like \\path\\**.exe or C:\path\**.jar + processed_paths = [ + (path if drive_letter_pattern.match(path) else f"\\\\{path}") + f"\\**{ext}" + for path, ext in unique_combinations.itertuples(index=False, name=None) + ] + + addPath(url, destination_id,processed_paths) + + print(ct.colorText(f"These publishers would added to {destination_name}", "yellow")) + + publisher_list = publishers['publisher'].tolist() + addPub(url, destination_id, publisher_list) + + print(ct.colorText(f"These hashes would be added to {allowlist_parent_name}", "yellow")) + + allowlist_parenthashlist = allowbyhash[allowbyhash['reputation_status'] == 'KNOWN']['sha256'].unique().tolist() + addHash(url, allowlist_parent_id,allowlist_parenthashlist) + + print(ct.colorText(f"These hashes would be added to {allowlist_child_name}", "yellow")) + allowlist_childhashlist = allowbyhash[allowbyhash['reputation_status'] == 'UNKNOWN']['sha256'].unique().tolist() + addHash(url, allowlist_child_id, allowlist_childhashlist) \ No newline at end of file diff --git a/utils/pretty.py b/utils/pretty.py index e651d3e..8f6907a 100644 --- a/utils/pretty.py +++ b/utils/pretty.py @@ -296,7 +296,10 @@ def printEnforceChecklist(first_policy, second_policy, allowlist_child_name, all else: print(colorText(f" [✓] destination policy is {destination_name}","green")) - print(colorText(f"6. Liftoff ------------------------------------------------------", "cyan")) + print(colorText(f"6. Test ------------------------------------------------------", "cyan")) + print(colorText(f" Print rather than apply selected data.", "cyan")) + + print(colorText(f"7. Liftoff ------------------------------------------------------", "cyan")) print(colorText(f" Apply path exclusions according to allowed and approved paths", "cyan")) print(colorText(f" Apply signed or attested hashes to Parent Allow List", "cyan")) print(colorText(f" Apply approved, but unsigned hashes to the Child Allow List", "cyan"))