Skip to content

Commit 724b2b1

Browse files
authored
Merge pull request kevoreilly#2457 from kevoreilly/yara_detect_fix
yara_detect
2 parents bb5cc07 + 11de9d8 commit 724b2b1

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

Diff for: lib/cuckoo/common/abstracts.py

+22-16
Original file line numberDiff line numberDiff line change
@@ -842,24 +842,28 @@ def yara_detected(self, name):
842842
if re.findall(name, yara_block["name"], re.I):
843843
yield "sample", self.results["target"]["file"]["path"], yara_block, self.results["target"]["file"]
844844

845-
for block in target["file"].get("extracted_files", []):
846-
for keyword in ("cape_yara", "yara"):
847-
for yara_block in block[keyword]:
848-
if re.findall(name, yara_block["name"], re.I):
849-
# we can't use here values from set_path
850-
yield "sample", block["path"], yara_block, block
845+
if target["file"].get("selfextract"):
846+
for _, toolsblock in target["file"]["selfextract"].items():
847+
for block in toolsblock.get("extracted_files", []):
848+
for keyword in ("cape_yara", "yara"):
849+
for yara_block in block[keyword]:
850+
if re.findall(name, yara_block["name"], re.I):
851+
# we can't use here values from set_path
852+
yield "sample", block["path"], yara_block, block
851853

852854
for block in self.results.get("CAPE", {}).get("payloads", []) or []:
853855
for sub_keyword in ("cape_yara", "yara"):
854856
for yara_block in block.get(sub_keyword, []):
855857
if re.findall(name, yara_block["name"], re.I):
856858
yield sub_keyword, block["path"], yara_block, block
857859

858-
for subblock in block.get("extracted_files", []):
859-
for keyword in ("cape_yara", "yara"):
860-
for yara_block in subblock[keyword]:
861-
if re.findall(name, yara_block["name"], re.I):
862-
yield "sample", subblock["path"], yara_block, block
860+
if block.get("selfextract", {}):
861+
for _, toolsblock in block["selfextract"].items():
862+
for subblock in toolsblock.get("extracted_files", []):
863+
for keyword in ("cape_yara", "yara"):
864+
for yara_block in subblock[keyword]:
865+
if re.findall(name, yara_block["name"], re.I):
866+
yield "sample", subblock["path"], yara_block, block
863867

864868
for keyword in ("procdump", "procmemory", "extracted", "dropped"):
865869
if self.results.get(keyword) is not None:
@@ -879,11 +883,13 @@ def yara_detected(self, name):
879883
if re.findall(name, yara_block["name"], re.I):
880884
yield "extracted_pe", pe["path"], yara_block, block
881885

882-
for subblock in block.get("extracted_files", []):
883-
for keyword in ("cape_yara", "yara"):
884-
for yara_block in subblock[keyword]:
885-
if re.findall(name, yara_block["name"], re.I):
886-
yield "sample", subblock["path"], yara_block, block
886+
if block.get("selfextract", {}):
887+
for _, toolsblock in block["selfextract"].items():
888+
for subblock in toolsblock.get("extracted_files", []):
889+
for keyword in ("cape_yara", "yara"):
890+
for yara_block in subblock[keyword]:
891+
if re.findall(name, yara_block["name"], re.I):
892+
yield "sample", subblock["path"], yara_block, block
887893

888894
macro_path = os.path.join(CUCKOO_ROOT, "storage", "analyses", str(self.results["info"]["id"]), "macros")
889895
for macroname in self.results.get("static", {}).get("office", {}).get("Macro", {}).get("info", []) or []:

Diff for: modules/processing/CAPE.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ def process_file(self, file_path, append_file, metadata: dict, *, category: str,
163163
"""
164164

165165
if not path_exists(file_path):
166+
log.debug("file doesn't exist: %s", file_path)
166167
return
167168

168169
cape_names = set()
@@ -206,7 +207,7 @@ def process_file(self, file_path, append_file, metadata: dict, *, category: str,
206207

207208
type_string, append_file = self._metadata_processing(metadata, file_info, append_file)
208209

209-
if processing_conf.CAPE.targetinfo and category in ("static", "file"):
210+
if category in ("static", "file"):
210211
if MISP_HASH_LOOKUP:
211212
misp_hash_lookup(file_info["sha256"], str(self.task["id"]), file_info)
212213

@@ -256,7 +257,7 @@ def process_file(self, file_path, append_file, metadata: dict, *, category: str,
256257
# Process CAPE Yara hits
257258
# Prefilter extracted data + beauty is better than oneliner:
258259
all_files = []
259-
for key, value in file_info.get("selfextract", {}).items():
260+
for _, value in file_info.get("selfextract", {}).items():
260261
for file in value.get("extracted_files", []):
261262
if not file.get("cape_yara", []):
262263
continue

Diff for: modules/processing/pcapng.py

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def append_file_contents_to_file(self, file_with_contents, append_to_file):
8080
dst.write(src.read())
8181

8282
def generate_pcapng(self, sslkeylogfile_path):
83+
# ToDo bail if file is empty
8384
cmd = [EDITCAP, "--inject-secrets", "tls," + sslkeylogfile_path, self.pcap_path, self.pcapng_path]
8485
log.debug("generating pcapng with command '%s", cmd)
8586
subprocess.check_call(cmd, timeout=EDITCAP_TIMEOUT)

0 commit comments

Comments
 (0)