Fixed some logic, added functions to list allowlist, and category. Category list function will need work, the subcategories are not being parsed at this time
This commit is contained in:
+53
-1
@@ -94,4 +94,56 @@ def listPolicies(url):
|
||||
policyids.append(list['groupid'])
|
||||
choice = input(ct.colorText("Select Policy Group: ", "white"))
|
||||
choice = int(choice) - 1
|
||||
return choice, policiesnames
|
||||
return choice, policiesnames
|
||||
|
||||
def listAllowlists(url):
|
||||
endpoint = url + '/v1/application'
|
||||
print(ct.colorText("[+] Grabbing All Allowlists", "cyan"))
|
||||
payload = {}
|
||||
headers = {
|
||||
"X-APIKey": os.getenv('APIKEY')
|
||||
}
|
||||
response = requests.request("POST", endpoint, headers=headers, data=payload, verify=False)
|
||||
parse_text = json.loads(response.text)
|
||||
policiesnames = []
|
||||
policyids = []
|
||||
for index, list in enumerate(parse_text['response']['applications'], start=1):
|
||||
print(ct.colorText(f"{index}. {list['name']}", "yellow"))
|
||||
policiesnames.append(list['name'])
|
||||
policyids.append(list['applicationid'])
|
||||
choice = int(input(ct.colorText("Select allowlist: ", "white")))
|
||||
if choice < 38:
|
||||
print(ct.colorText("Please only choose an allowlist designed for this use - '38+'","red"))
|
||||
elif choice >= 38:
|
||||
choice = int(choice) - 1
|
||||
return choice, policiesnames
|
||||
#Need else and catch for upper bound
|
||||
|
||||
|
||||
def listCategories(url):
|
||||
endpoint = url + '/v1/application/categories'
|
||||
print(ct.colorText("[+] Grabbing All Categories", "cyan"))
|
||||
payload = {}
|
||||
headers = {
|
||||
"X-APIKey": os.getenv('APIKEY')
|
||||
}
|
||||
response = requests.request("POST", endpoint, headers=headers, data=payload, verify=False)
|
||||
parse_text = json.loads(response.text)
|
||||
policiesnames = []
|
||||
policyids = []
|
||||
for index, list in enumerate(parse_text['response']['categories'], start=1):
|
||||
print(ct.colorText(f"{index}. {list['name']}", "yellow"))
|
||||
policiesnames.append(list['name'])
|
||||
policyids.append(list['categoryid'])
|
||||
|
||||
|
||||
choice = input(ct.colorText("Select Policy Group: ", "white"))
|
||||
choice = int(choice) - 1
|
||||
return choice, policiesnames
|
||||
|
||||
|
||||
|
||||
|
||||
else:
|
||||
print(ct.colorText("Please choose only 38 or Aboove", "red"))
|
||||
|
||||
+18
-4
@@ -81,24 +81,38 @@ def export_groups_for_review(df, col="filename_x", group_col="longestcfp"):
|
||||
return grouped, df
|
||||
|
||||
|
||||
|
||||
def mask_from_csv(df, csv_path, filepath_col):
|
||||
"""
|
||||
Reads reviewed CSV of groups, keeps only files in approved groups.
|
||||
"""
|
||||
review_df = pd.read_csv(csv_path)
|
||||
# Convert string representation of lists back to actual lists
|
||||
review_df[filepath_col] = review_df[filepath_col].apply(ast.literal_eval)
|
||||
|
||||
|
||||
def parse_paths(val):
|
||||
if isinstance(val, str):
|
||||
try:
|
||||
# Try to parse as a list
|
||||
parsed = ast.literal_eval(val)
|
||||
# If it's not a list, wrap it
|
||||
return parsed if isinstance(parsed, list) else [parsed]
|
||||
except (ValueError, SyntaxError):
|
||||
# If parsing fails, treat it as a single path
|
||||
return [val]
|
||||
return [val]
|
||||
|
||||
review_df[filepath_col] = review_df[filepath_col].apply(parse_paths)
|
||||
|
||||
# Flatten all approved file paths into a set for masking
|
||||
approved_files = set()
|
||||
for paths in review_df[filepath_col]:
|
||||
approved_files.update(paths)
|
||||
|
||||
|
||||
# Keep only rows in df that are in approved_files
|
||||
masked_df = df[df[filepath_col].isin(approved_files)].copy()
|
||||
remainder = df[~df[filepath_col].isin(approved_files)].copy()
|
||||
return masked_df, remainder
|
||||
|
||||
|
||||
def filter_and_drop(approved, eligiblepaths, min_hashes):
|
||||
"""
|
||||
Filters eligiblepaths to rows where all hashes are in approved,
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
|
||||
|
||||
def addHash(policy, hash):
|
||||
pass
|
||||
print(f"Adding the following hashes to {policy}:")
|
||||
print(hash)
|
||||
|
||||
def addPath(policy, hash):
|
||||
pass
|
||||
print(f"Adding the following Path Exclusions to {policy}:")
|
||||
print(hash)
|
||||
Reference in New Issue
Block a user