Created
June 11, 2020 22:06
-
-
Save Cyb3rWard0g/7f2b4292d0209b8de8a8b492ef3f91fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from jinja2 import Template | |
import copy | |
import yaml | |
import glob | |
from os import path | |
print("[+] Processing files inside {} directory".format('../docs/evals/apt29/steps')) | |
# ******** Open every forge yaml file available **************** | |
print("[+] Opening report yaml files..") | |
yaml_files = sorted(glob.glob(path.join(path.dirname(__file__), '../docs/evals/apt29/steps', "*.yaml")), key=lambda x: (int(path.basename(x).split(".")[0]), str(path.basename(x).split(".")[1]), int(path.basename(x).split(".")[2].split("_")[0]))) | |
yaml_loaded = [yaml.safe_load(open(yf).read()) for yf in yaml_files] | |
# ******** Create Logic -> Output Documents ******** | |
otr_list = [] | |
detection_template = Template(open("templates/evals_detection_template.md").read()) | |
print("\n[+]Creating detection documents..") | |
for step in yaml_loaded: | |
for detection in step['detections']: | |
# ***** Create Detection Documents ***** | |
if detection['queries']: | |
for q in detection['queries']: | |
query_for_render = copy.deepcopy(q) | |
markdown = detection_template.render(renderquery=query_for_render) | |
if (path.exists('../docs/evals/apt29/detections/{}_{}.md'.format(step['step'],q['id']))): | |
print('[!] {}_{}.md already exists'.format(step['step'],q['id'])) | |
else: | |
print(' [>] {}_{}.md detection created'.format(step['step'],q['id'])) | |
open('../docs/evals/apt29/detections/{}_{}.md'.format(step['step'],q['id']), 'w').write(markdown) | |
# ******** Creating APT29 Evals Markdown Report ******** | |
print("\n[+] Creating APT29 Evals Markdown Report..") | |
print(" [>] Reading report template..") | |
yaml_template = Template(open("templates/evals_report_template.md").read()) | |
# Create Markdown file | |
print(" [>] Writing steps to markdown ..") | |
yaml_for_render = copy.deepcopy(yaml_loaded) | |
# Generate the markdown | |
markdown = yaml_template.render(renderyaml=yaml_for_render) | |
print("\n [>] Writing Markdown report to ../docs/evals/apt29/report.md") | |
open('../docs/evals/apt29/report.md', 'w').write(markdown) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment