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

Hashes for artifacts #495

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions scripts/artifacts/hashvals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os, hashlib, os

from pathlib import Path
from time import gmtime
from time import localtime
from time import strftime
from scripts.artifact_report import ArtifactHtmlReport
from datetime import datetime


# Write digest results to file


def write_hashes(files_found, report_folder, seeker, wrap_text, time_offset):
sha2pulls = {}
data_list = []
for file_found in files_found:
artifact_path = file_found.replace(seeker.directory, "")
if os.path.isfile(file_found):
with open(file_found, "rb") as f:
fdata = f.read()
sha2pulls = hashlib.sha256(fdata).hexdigest()

else:
pass

data_list.append((file_found, sha2pulls))

report = ArtifactHtmlReport("SHA256 File Hashes")
report.start_artifact_report(report_folder, "Message Digest for Processed Files")
report.add_script()
data_headers = ["Artifact", "SHA256"]
report.write_artifact_data_table(
data_headers, data_list, artifact_path, html_escape=False
)
report.end_artifact_report()


__artifacts__ = {"File Hashes": ("File Hashes", ("*/*"), write_hashes)}