6
6
7
7
import pandas as pd
8
8
9
- from core .schemas .observables import file , sha256 , sha1 , md5 , hostname
9
+ from core .schemas .observables import file , sha256 , sha1 , md5 , hostname , path
10
10
from core .schemas import task
11
11
from core import taskmanager
12
12
@@ -30,13 +30,13 @@ def run(self):
30
30
orient = "values" ,
31
31
convert_dates = ["analysis_start_time" ],
32
32
)
33
- df .ffill ( inplace = True )
33
+ df .fillna ( 0 , inplace = True )
34
34
df = self ._filter_observables_by_time (df , "analysis_start_time" )
35
35
for _ , row in df .iterrows ():
36
36
self .analyze (row )
37
37
38
- # pylint: disable=arguments-differ
39
38
def analyze (self , item ):
39
+ logging .debug (f"HybridAnalysis: { item } " )
40
40
first_seen = item ["analysis_start_time" ]
41
41
42
42
f_hyb = file .File (value = f"FILE:{ item ['sha256' ]} " ).save ()
@@ -52,7 +52,7 @@ def analyze(self, item):
52
52
if "vxfamily" in item :
53
53
context ["vxfamily" ] = item ["vxfamily" ]
54
54
55
- if "tags" in item :
55
+ if "tags" in item and isinstance ( item [ "tags" ], list ) :
56
56
tags .extend (item ["tags" ])
57
57
58
58
if "threatlevel_human" in item :
@@ -80,6 +80,8 @@ def analyze(self, item):
80
80
81
81
context ["url" ] = "https://www.hybrid-analysis.com" + item ["reporturl" ]
82
82
83
+ logging .debug (f"HybridAnalysis: { context } " )
84
+
83
85
f_hyb .add_context (self .name , context )
84
86
f_hyb .tag (tags )
85
87
@@ -96,13 +98,13 @@ def analyze(self, item):
96
98
sha1_obs .tag (tags )
97
99
f_hyb .link_to (sha1_obs , "sha1" , self .name )
98
100
99
- if "domains" in item :
101
+ if "domains" in item and isinstance ( item [ "domains" ], list ) :
100
102
for domain in item ["domains" ]:
101
103
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 )
103
105
new_host .tag (tags )
104
106
105
- if "extracted_files" in item :
107
+ if "extracted_files" in item and isinstance ( item [ "extracted_files" ], list ) :
106
108
for extracted_file in item ["extracted_files" ]:
107
109
context_file_dropped = {"source" : self .name }
108
110
@@ -116,29 +118,37 @@ def analyze(self, item):
116
118
sha256_new_file = sha256 .SHA256 (value = extracted_file ["sha256" ]).save ()
117
119
118
120
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 )
119
126
120
127
context_file_dropped ["virustotal_score" ] = 0
121
128
context_file_dropped ["size" ] = extracted_file ["file_size" ]
122
129
123
- if "av_matched" in extracted_file :
130
+ if "av_matched" in extracted_file and isinstance ( 'av_matched' , int ) :
124
131
context_file_dropped ["virustotal_score" ] = extracted_file [
125
132
"av_matched"
126
133
]
127
134
128
- if "threatlevel_readable" in extracted_file :
135
+ if "threatlevel_readable" in extracted_file and isinstance ( 'threatlevel_readable' , str ) :
129
136
context_file_dropped ["threatlevel" ] = extracted_file [
130
137
"threatlevel_readable"
131
138
]
132
139
133
- if "av_label" in extracted_file :
140
+ if "av_label" in extracted_file and isinstance ( 'av_label' , str ) :
134
141
context_file_dropped ["av_label" ] = extracted_file ["av_label" ]
135
142
136
- if "type_tags" in extracted_file :
143
+ if "type_tags" in extracted_file and isinstance ( 'type_tags' , list ) :
137
144
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" ])
138
149
139
150
new_file .add_context (self .name , context_file_dropped )
140
151
sha256_new_file .add_context (self .name , context_file_dropped )
141
-
142
152
f_hyb .link_to (new_file , "dropped" , self .name )
143
153
144
154
0 commit comments