Continued Colorization, pushed it to utils and colorized other helper scripts

This commit is contained in:
Driven-Element
2025-08-24 13:46:20 -04:00
parent 615fb77891
commit bdf3d4b9ec
5 changed files with 105 additions and 91 deletions
+5 -4
View File
@@ -17,6 +17,7 @@ import requests
import json
import os
import time
import utils.colortext as ct
def pullPolicyExechistories(url, choice, policiesnames, outputjson: bool):
@@ -32,7 +33,7 @@ def pullPolicyExechistories(url, choice, policiesnames, outputjson: bool):
for index, item in enumerate(json_response_data['response']['exechistories']):
if index == len(json_response_data['response']['exechistories']) -1:
checkpoint = item['checkpoint']
print(f"Date Greater than 30 Days, Stepping to new Checkpoint. {item['checkpoint']}")
print(ct.colorText(f"Date Greater than 30 Days, Stepping to new Checkpoint. {item['checkpoint']}", "blue"))
else:
if (datetime.date.today() - datetime.timedelta(days=10) > datetime.datetime.strptime(item['datetime'].replace(' +0000 UTC', ''), '%Y-%m-%dT%H:%M:%SZ').date()):
pass
@@ -57,7 +58,7 @@ def checkpoint_stomper(checkpoint, url, policy, headers):
def listPolicies(url):
endpoint = url + '/v1/group'
print("[+] Grabbing All Policies")
print(ct.colorText("[+] Grabbing All Policies", "magenta"))
payload = {}
headers = {
"X-APIKey": os.getenv('APIKEY')
@@ -67,9 +68,9 @@ def listPolicies(url):
policiesnames = []
policyids = []
for index, list in enumerate(parse_text['response']['groups'], start=1):
print(f"{index}. {list['name']}")
print(ct.colorText(f"{index}. {list['name']}", "yellow"))
policiesnames.append(list['name'])
policyids.append(list['groupid'])
choice = input("Select Policy Group: ")
choice = input(ct.colorText("Select Policy Group: ", "yellow"))
choice = int(choice) - 1
return choice, policiesnames
+14
View File
@@ -0,0 +1,14 @@
def colorText(text: str, color: str) -> str:
colors = {
"red": "\033[91m",
"green": "\033[92m",
"yellow": "\033[93m",
"blue": "\033[94m",
"magenta": "\033[95m",
"cyan": "\033[96m",
"white": "\033[97m",
"reset": "\033[0m"
}
return f"{colors.get(color, colors['reset'])}{text}{colors['reset']}"
+19 -18
View File
@@ -16,16 +16,17 @@ import datetime
import requests
import json
import os
import utils.colortext as ct
def devicehistory(url, outputjson: bool):
endpoint = url + '/v1/getexechistory'
print("\n")
print("1. Today")
print("2. Last 24 Hours")
print("3. Past 7 Days")
print("4. Past 30 Days")
print("5. Custom Date Range")
choice = input("\nSelect Date Range: ")
print(ct.colorText("1. Today", "yellow"))
print(ct.colorText("2. Last 24 Hours", "yellow"))
print(ct.colorText("3. Past 7 Days", "yellow"))
print(ct.colorText("4. Past 30 Days", "yellow"))
print(ct.colorText("5. Custom Date Range","yellow"))
choice = input(ct.colorText("\nSelect Date Range: ", "white"))
today = datetime.date.today()
today = today.strftime("%Y-%m-%d")
if choice == '1':
@@ -40,18 +41,18 @@ def devicehistory(url, outputjson: bool):
date_selected = datetime.date.today() - datetime.timedelta(days=30)
date_selected = date_selected.strftime('%Y-%m-%d')
elif choice == "5":
print("Please Input Dates as YYYY-MM-DD")
date_selected = input("From: ")
today = input("Date To: ")
print("WARNING: Device Name is Case Sensitive")
device = input("Enter Device Name: ")
print(ct.colorText("Please Input Dates as YYYY-MM-DD", "cyan"))
date_selected = input(ct.colorText("From: ", "white"))
today = input(ct.colorText("Date To: ", "white"))
print(ct.colorText("WARNING: Device Name is Case Sensitive", "red"))
device = input(ct.colorText("Enter Device Name: ", "white"))
payload_dict = {
"datefrom": date_selected,
"dateto": today,
"hostname": device
}
payload = json.dumps(payload_dict)
print(payload)
print(ct.colorText(payload, "green"))
headers = {
"X-APIKey": os.getenv('APIKEY')
}
@@ -64,10 +65,10 @@ def devicehistory(url, outputjson: bool):
parse_text = json.loads(response.text)
for block in parse_text['response']['exechistory']:
print(f"Command: {block['commandline']}")
print(f"Date: {block['datetime']}")
print(f"Filename: {block['filename']}")
print(f"Policy Name: {block['policyname']}")
print(f"Hostname: {block['hostname']}")
print(f"Hash: {block['sha256']}")
print(ct.colorText(f"Command: {block['commandline']}","green"))
print(ct.colorText(f"Date: {block['datetime']}","green"))
print(ct.colorText(f"Filename: {block['filename']}","green"))
print(ct.colorText(f"Policy Name: {block['policyname']}","green"))
print(ct.colorText(f"Hostname: {block['hostname']}","green"))
print(ct.colorText(f"Hash: {block['sha256']}","green"))
print("\n")
+2 -1
View File
@@ -16,6 +16,7 @@ import pandas as pd
import requests
import os
import json
import utils.colortext as ct
def aggregateHashes(executions_json) -> pd.DataFrame:
@@ -27,7 +28,7 @@ def aggregateHashes(executions_json) -> pd.DataFrame:
if df.empty:
return df
print(df)
print(color_text(df,"green"))
# Aggregate by sha256, deduplicate lists, and preserve order
agg_df = df.groupby("sha256").agg(lambda x: list(dict.fromkeys(x))).reset_index()