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

Fixing the missing reference to kvsectionbody[dev] #437

Merged
merged 2 commits into from
Aug 28, 2024
Merged
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
12 changes: 3 additions & 9 deletions cape/cape_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
BODY_FORMAT,
ImageSectionBody,
Result,
KVSectionBody,
ResultKeyValueSection,
ResultMultiSection,
ResultSection,
Expand Down Expand Up @@ -399,11 +400,9 @@ def _load_rules(self):
if yara_root is None:
return (None, {"Updater_Error": "No valid updater directory set"})
rules, indexed = {}, []
filepaths = []
for yara_root, _, filenames in os.walk(yara_root, followlinks=True):
for filename in filenames:
filepath = os.path.join(yara_root, filename)
filepaths.append(filepath)
if validate_rule(filepath):
rules[f"rule_{len(rules)}"] = filepath
indexed.append(filename)
Expand All @@ -415,7 +414,7 @@ def _load_rules(self):
while True:
try:
yara_rules = yara.compile(filepaths=rules, externals=YARA_EXTERNALS)
return (yara_rules, filepaths, errors)
return (yara_rules, errors)
except yara.SyntaxError as e:

bad_rule = str(e).split('.yar', 1)[0]
Expand Down Expand Up @@ -480,7 +479,7 @@ def _general_flow(
if "prescript_detection=yes" in kwargs.get("options", ""):
parent_section.title_text += " (with prescript detection)"
#self.rules_list would be the list of loaded signatures not the ones in the folder
self.yara_sigs, filepaths, errors = self._load_rules()
self.yara_sigs, errors = self._load_rules()
#What about scripts and files ? How will we pass it along ? Need to zip compound it ? We might need to clone the repo on the server analyzer so it's passed along ?
prescipt_detection_section = ResultMultiSection("Prescript Detection")
if errors is not None:
Expand Down Expand Up @@ -530,11 +529,6 @@ def _general_flow(
else:
info_section_body = TextSectionBody(body="No matching rules, ran CAPE as default")
prescipt_detection_section.add_section_part(info_section_body)
list_of_rules = ""
for filepath in filepaths:
list_of_rules += f"{filepath} "
rules_section_body = TextSectionBody(body=list_of_rules)
prescipt_detection_section.add_section_part(rules_section_body)
parent_section.add_subsection(prescipt_detection_section)
cape_task = CapeTask(self.file_name, host_to_use, **kwargs)

Expand Down