3232cuckoo_conf = Config ()
3333web_cfg = Config ("web" )
3434tmp_path = cuckoo_conf .cuckoo .get ("tmppath" , "/tmp" )
35- linux_enabled = web_cfg .linux .get ("enabled" , False )
35+ # ToDo allow_static
36+ linux_enabled = web_cfg .linux .get ("enabled" , False ) or web_cfg .linux .get ("static_only" , False )
3637
3738demux_extensions_list = {
3839 b".accdr" ,
@@ -162,7 +163,8 @@ def is_valid_package(package: str) -> bool:
162163 return any (ptype in package for ptype in VALID_PACKAGES )
163164
164165
165- def _sf_children (child : sfFile ) -> bytes :
166+ # ToDo fix return type
167+ def _sf_children (child : sfFile ): # -> bytes:
166168 path_to_extract = ""
167169 _ , ext = os .path .splitext (child .filename )
168170 ext = ext .lower ()
@@ -184,15 +186,17 @@ def _sf_children(child: sfFile) -> bytes:
184186 _ = path_write_file (path_to_extract , child .contents )
185187 except Exception as e :
186188 log .error (e , exc_info = True )
187- return path_to_extract .encode ()
189+ return ( path_to_extract .encode (), child . platform , child . get_type (), child . get_size () )
188190
189191
190- def demux_sflock (filename : bytes , options : str , check_shellcode : bool = True ) -> List [bytes ]:
192+ # ToDo fix typing need to add str as error msg
193+ def demux_sflock (filename : bytes , options : str , check_shellcode : bool = True ): # -> List[bytes]:
191194 retlist = []
192195 # do not extract from .bin (downloaded from us)
193196 if os .path .splitext (filename )[1 ] == b".bin" :
194- return retlist
197+ return retlist , ""
195198
199+ # ToDo need to introduce error msgs here
196200 try :
197201 password = options2passwd (options ) or "infected"
198202 try :
@@ -201,9 +205,13 @@ def demux_sflock(filename: bytes, options: str, check_shellcode: bool = True) ->
201205 unpacked = unpack (filename , check_shellcode = check_shellcode )
202206
203207 if unpacked .package in whitelist_extensions :
204- return [filename ]
208+ file = File (filename )
209+ magic_type = file .get_type ()
210+ platform = file .get_platform ()
211+ file_size = file .get_size ()
212+ return [filename , platform , magic_type , file_size ], ""
205213 if unpacked .package in blacklist_extensions :
206- return [filename ]
214+ return [], "blacklisted package"
207215 for sf_child in unpacked .children :
208216 if sf_child .to_dict ().get ("children" ):
209217 retlist .extend (_sf_children (ch ) for ch in sf_child .children )
@@ -214,7 +222,7 @@ def demux_sflock(filename: bytes, options: str, check_shellcode: bool = True) ->
214222 retlist .append (_sf_children (sf_child ))
215223 except Exception as e :
216224 log .error (e , exc_info = True )
217- return list (filter (None , retlist ))
225+ return list (filter (None , retlist )), ""
218226
219227
220228def demux_sample (filename : bytes , package : str , options : str , use_sflock : bool = True , platform : str = "" ): # -> tuple[bytes, str]:
@@ -227,21 +235,29 @@ def demux_sample(filename: bytes, package: str, options: str, use_sflock: bool =
227235 if isinstance (filename , str ) and use_sflock :
228236 filename = filename .encode ()
229237
238+ error_list = []
230239 retlist = []
231240 # if a package was specified, trim if allowed and required
232241 if package :
233-
234242 if package in ("msix" ,):
235243 retlist .append ((filename , "windows" ))
236244 else :
237245 if File (filename ).get_size () <= web_cfg .general .max_sample_size or (
238246 web_cfg .general .allow_ignore_size and "ignore_size_check" in options
239247 ):
240- retlist .append ((filename , platform ))
248+ retlist .append ((filename , platform , "" ))
241249 else :
242250 if web_cfg .general .enable_trim and trim_file (filename ):
243251 retlist .append ((trimmed_path (filename ), platform ))
244- return retlist
252+ else :
253+ error_list .append (
254+ {
255+ os .path .basename (
256+ filename
257+ ): "File too bit, enable 'allow_ignore_size' in web.conf or use 'ignore_size_check' option"
258+ }
259+ )
260+ return retlist , error_list
245261
246262 # handle quarantine files
247263 tmp_path = unquarantine (filename )
@@ -259,9 +275,16 @@ def demux_sample(filename: bytes, package: str, options: str, use_sflock: bool =
259275 if use_sflock :
260276 if HAS_SFLOCK :
261277 retlist = demux_office (filename , password , platform )
262- return retlist
278+ return retlist , error_list
263279 else :
264280 log .error ("Detected password protected office file, but no sflock is installed: poetry install" )
281+ error_list .append (
282+ {
283+ os .path .basename (
284+ filename
285+ ): "Detected password protected office file, but no sflock is installed or correct password provided"
286+ }
287+ )
265288
266289 # don't try to extract from Java archives or executables
267290 if (
@@ -279,6 +302,13 @@ def demux_sample(filename: bytes, package: str, options: str, use_sflock: bool =
279302 else :
280303 if web_cfg .general .enable_trim and trim_file (filename ):
281304 retlist .append ((trimmed_path (filename ), platform ))
305+ else :
306+ error_list .append (
307+ {
308+ os .path .basename (filename ),
309+ "File too bit, enable 'allow_ignore_size' in web.conf or use 'ignore_size_check' option" ,
310+ }
311+ )
282312 return retlist
283313
284314 new_retlist = []
@@ -288,26 +318,34 @@ def demux_sample(filename: bytes, package: str, options: str, use_sflock: bool =
288318 check_shellcode = False
289319
290320 # all in one unarchiver
291- retlist = demux_sflock (filename , options , check_shellcode ) if HAS_SFLOCK and use_sflock else []
321+ retlist , error_msg = demux_sflock (filename , options , check_shellcode ) if HAS_SFLOCK and use_sflock else []
292322 # if it isn't a ZIP or an email, or we aren't able to obtain anything interesting from either, then just submit the
293323 # original file
294324 if not retlist :
325+ if error_msg :
326+ error_list .append ({os .path .basename (filename ), error_msg })
295327 new_retlist .append ((filename , platform ))
296328 else :
297- for filename in retlist :
329+ for filename , platform , magic_type , file_size in retlist :
298330 # verify not Windows binaries here:
299- file = File (filename )
300- magic_type = file .get_type ()
301- platform = file .get_platform ()
302331 if platform == "linux" and not linux_enabled and "Python" not in magic_type :
332+ error_list .append ({os .path .basename (filename ): "Linux processing is disabled" })
303333 continue
304334
305- if file . get_size () > web_cfg .general .max_sample_size and not (
335+ if file_size > web_cfg .general .max_sample_size and not (
306336 web_cfg .general .allow_ignore_size and "ignore_size_check" in options
307337 ):
308338 if web_cfg .general .enable_trim :
309339 # maybe identify here
310340 if trim_file (filename ):
311341 filename = trimmed_path (filename )
342+ else :
343+ error_list .append (
344+ {
345+ os .path .basename (filename ),
346+ "File too bit, enable 'allow_ignore_size' in web.conf or use 'ignore_size_check' option" ,
347+ }
348+ )
312349 new_retlist .append ((filename , platform ))
313- return new_retlist [:10 ]
350+
351+ return new_retlist [:10 ], error_list
0 commit comments