Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add exception handling if osanalytics has no key 'netUsageBaseline' #14

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

if [ $# -ne 1 -o ! -d "$1" ]; then
echo "usage: $0 PATH_TO_BACKUP_DIR"
exit 1
fi

python3 -m venv venv
. venv/bin/activate
pip3 install -r requirements.txt
python3 -m triangle_check $1
15 changes: 9 additions & 6 deletions triangle_check/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,15 @@ def scan_dir(self, backup_dir, backup_password, ask_password_func):

with open(path_osanalytics, 'rb') as f:
osanalytics = plistlib.load(f)
baseline = osanalytics['netUsageBaseline']
for package in baseline:
if package in process_IOCs_exact:
self.append_detection(baseline[package][0].replace(tzinfo=timezone.utc).timestamp(), ('exact', 'NetUsage', package))
if (package in process_IOCs_implicit) or (package in process_IOCs_exact):
self.append_timeline(baseline[package][0].replace(tzinfo=timezone.utc).timestamp(), ('NetUsage', package))
try:
baseline = osanalytics['netUsageBaseline']
for package in baseline:
if package in process_IOCs_exact:
self.append_detection(baseline[package][0].replace(tzinfo=timezone.utc).timestamp(), ('exact', 'NetUsage', package))
if (package in process_IOCs_implicit) or (package in process_IOCs_exact):
self.append_timeline(baseline[package][0].replace(tzinfo=timezone.utc).timestamp(), ('NetUsage', package))
except KeyError as ke:
print('Warning: it appears that device analytics has been disabled, detection of some IOCs must be skipped.')

datausage = sqlite3.connect(path_datausage)
data_cur = datausage.cursor()
Expand Down