Skip to content

Commit d0b6f99

Browse files
author
Patrick Bareiss
committed
CI/CD upload attack datasets to Splunk
1 parent 9bb2364 commit d0b6f99

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

bin/replay.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,22 @@ def send_data_to_splunk(file_path, splunk_host, hec_token, event_host_uuid,
117117

118118
def main():
119119
parser = argparse.ArgumentParser(
120-
description="Replay datasets from YAML files to Splunk via HTTP Event Collector (HEC). "
121-
"All metadata (source, sourcetype, index) is read from the YAML files.",
120+
description="Replay datasets from YAML files to Splunk via HEC. "
121+
"All metadata (source, sourcetype, index) is read from YAML files.",
122122
epilog="""
123123
Environment Variables Required:
124124
SPLUNK_HOST - Splunk server hostname/IP
125125
SPLUNK_HEC_TOKEN - Splunk HEC token
126126
127127
Example usage:
128128
# Replay from specific YAML files
129-
python replay.py datasets/attack_techniques/T1003.003/atomic_red_team/atomic_red_team.yml
129+
python replay.py datasets/attack_techniques/T1003.003/atomic_red_team/\
130+
atomic_red_team.yml
130131
python replay.py file1.yml file2.yml file3.yml
131132
132133
# Replay from directories (finds all YAML files)
133134
python replay.py datasets/attack_techniques/T1003.003/
134-
python replay.py datasets/attack_techniques/T1003.003/ datasets/attack_techniques/T1005/
135+
python replay.py datasets/attack_techniques/T1003.003/
135136
136137
Environment setup:
137138
export SPLUNK_HOST="192.168.1.100"
@@ -232,22 +233,33 @@ def main():
232233
f"'{dataset_name}', skipping")
233234
continue
234235

235-
# Handle relative paths - relative to attack_data root
236+
# Handle relative paths - relative to git project root
236237
if dataset_path.startswith('/datasets/'):
237238
# Convert to absolute path based on project structure
239+
# Find git project root by looking for .git directory
238240
current_path = Path(yml_file).parent
239-
base_dir = current_path
241+
project_root = current_path
240242

241-
# Walk up to find attack_data root
242-
while (base_dir.name != 'attack_data' and
243-
base_dir.parent != base_dir):
244-
base_dir = base_dir.parent
243+
# Walk up to find git project root (directory containing .git)
244+
while (not (project_root / '.git').exists() and
245+
project_root.parent != project_root):
246+
project_root = project_root.parent
245247

246-
if base_dir.name == 'attack_data':
247-
full_path = base_dir / dataset_path.lstrip('/')
248+
if (project_root / '.git').exists():
249+
# Found git project root, construct path relative to it
250+
full_path = project_root / dataset_path.lstrip('/')
248251
else:
249-
# Fallback: assume current working directory structure
250-
full_path = Path.cwd() / dataset_path.lstrip('/')
252+
# Fallback: try to find project root using current working dir
253+
cwd = Path.cwd()
254+
while (not (cwd / '.git').exists() and
255+
cwd.parent != cwd):
256+
cwd = cwd.parent
257+
258+
if (cwd / '.git').exists():
259+
full_path = cwd / dataset_path.lstrip('/')
260+
else:
261+
# Last resort: assume current working directory structure
262+
full_path = Path.cwd() / dataset_path.lstrip('/')
251263
else:
252264
# Assume relative to yml file location
253265
yml_dir = Path(yml_file).parent

0 commit comments

Comments
 (0)