Skip to content

Commit 288e3d6

Browse files
sebdraventomchop
andauthored
Feed bugs (#942)
Co-authored-by: Thomas Chopitea <[email protected]>
1 parent b641735 commit 288e3d6

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

plugins/feeds/public/hybrid_analysis.py

+22-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pandas as pd
88

9-
from core.schemas.observables import file, sha256, sha1, md5, hostname
9+
from core.schemas.observables import file, sha256, sha1, md5, hostname,path
1010
from core.schemas import task
1111
from core import taskmanager
1212

@@ -30,13 +30,13 @@ def run(self):
3030
orient="values",
3131
convert_dates=["analysis_start_time"],
3232
)
33-
df.ffill(inplace=True)
33+
df.fillna(0, inplace=True)
3434
df = self._filter_observables_by_time(df, "analysis_start_time")
3535
for _, row in df.iterrows():
3636
self.analyze(row)
3737

38-
# pylint: disable=arguments-differ
3938
def analyze(self, item):
39+
logging.debug(f"HybridAnalysis: {item}")
4040
first_seen = item["analysis_start_time"]
4141

4242
f_hyb = file.File(value=f"FILE:{item['sha256']}").save()
@@ -52,7 +52,7 @@ def analyze(self, item):
5252
if "vxfamily" in item:
5353
context["vxfamily"] = item["vxfamily"]
5454

55-
if "tags" in item:
55+
if "tags" in item and isinstance(item["tags"], list):
5656
tags.extend(item["tags"])
5757

5858
if "threatlevel_human" in item:
@@ -80,6 +80,8 @@ def analyze(self, item):
8080

8181
context["url"] = "https://www.hybrid-analysis.com" + item["reporturl"]
8282

83+
logging.debug(f"HybridAnalysis: {context}")
84+
8385
f_hyb.add_context(self.name, context)
8486
f_hyb.tag(tags)
8587

@@ -96,13 +98,13 @@ def analyze(self, item):
9698
sha1_obs.tag(tags)
9799
f_hyb.link_to(sha1_obs, "sha1", self.name)
98100

99-
if "domains" in item:
101+
if "domains" in item and isinstance(item["domains"], list):
100102
for domain in item["domains"]:
101103
new_host = hostname.Hostname(value=domain).save()
102-
f_hyb.link_to(new_host, "contacted", self.name)
104+
f_hyb.link_to(new_host, "contact", self.name)
103105
new_host.tag(tags)
104106

105-
if "extracted_files" in item:
107+
if "extracted_files" in item and isinstance(item["extracted_files"], list):
106108
for extracted_file in item["extracted_files"]:
107109
context_file_dropped = {"source": self.name}
108110

@@ -116,29 +118,37 @@ def analyze(self, item):
116118
sha256_new_file = sha256.SHA256(value=extracted_file["sha256"]).save()
117119

118120
new_file.link_to(sha256_new_file, "sha256", self.name)
121+
122+
path_extracted_file = None
123+
if "file_path" is extracted_file and extracted_file["file_path"] and isinstance(extracted_file["file_path"], str):
124+
path_extracted_file = path.Path(value=extracted_file["file_path"]).save()
125+
new_file.link_to(path_extracted_file, "path", self.name)
119126

120127
context_file_dropped["virustotal_score"] = 0
121128
context_file_dropped["size"] = extracted_file["file_size"]
122129

123-
if "av_matched" in extracted_file:
130+
if "av_matched" in extracted_file and isinstance('av_matched', int):
124131
context_file_dropped["virustotal_score"] = extracted_file[
125132
"av_matched"
126133
]
127134

128-
if "threatlevel_readable" in extracted_file:
135+
if "threatlevel_readable" in extracted_file and isinstance('threatlevel_readable', str):
129136
context_file_dropped["threatlevel"] = extracted_file[
130137
"threatlevel_readable"
131138
]
132139

133-
if "av_label" in extracted_file:
140+
if "av_label" in extracted_file and isinstance('av_label', str):
134141
context_file_dropped["av_label"] = extracted_file["av_label"]
135142

136-
if "type_tags" in extracted_file:
143+
if "type_tags" in extracted_file and isinstance('type_tags', list):
137144
new_file.tag(extracted_file["type_tags"])
145+
if path_extracted_file:
146+
path_extracted_file.tag(extracted_file["type_tags"])
147+
148+
sha256_new_file.tag(extracted_file["type_tags"])
138149

139150
new_file.add_context(self.name, context_file_dropped)
140151
sha256_new_file.add_context(self.name, context_file_dropped)
141-
142152
f_hyb.link_to(new_file, "dropped", self.name)
143153

144154

plugins/feeds/public/vxvault_url.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ def run(self):
2727
# don't need to do much here; want to add the information
2828
# and tag it with 'malware'
2929
def analyze(self, item):
30-
30+
if not item:
31+
return
3132
tags = ["malware", "dropzone"]
3233
context = {"source": self.name}
33-
34+
logging.debug(f"VXVaultUrl: {item}")
3435
url_obs = url.Url(value=item).save()
3536
url_obs.add_context(self.name, context)
3637
url_obs.tag(tags)

tests/feeds.py

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
lolbas,
99
openphish,
1010
timesketch,
11+
hybrid_analysis
1112
)
1213

1314

@@ -45,3 +46,8 @@ def test_attack(self):
4546
defaults = attack.MitreAttack._defaults.copy()
4647
feed = attack.MitreAttack(**defaults)
4748
feed.run()
49+
50+
def test_hybrid_analysis(self):
51+
defaults = hybrid_analysis.HybridAnalysis._defaults.copy()
52+
feed = hybrid_analysis.HybridAnalysis(**defaults)
53+
feed.run()

0 commit comments

Comments
 (0)