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+ linux_enabled = web_cfg .linux .get ("enabled" , False ) or web_cfg . linux . get ( "static_only" , False )
3636
3737demux_extensions_list = {
3838 b".accdr" ,
@@ -162,7 +162,8 @@ def is_valid_package(package: str) -> bool:
162162 return any (ptype in package for ptype in VALID_PACKAGES )
163163
164164
165- def _sf_children (child : sfFile ) -> bytes :
165+ # ToDo fix return type
166+ def _sf_children (child : sfFile ): # -> bytes:
166167 path_to_extract = ""
167168 _ , ext = os .path .splitext (child .filename )
168169 ext = ext .lower ()
@@ -184,15 +185,17 @@ def _sf_children(child: sfFile) -> bytes:
184185 _ = path_write_file (path_to_extract , child .contents )
185186 except Exception as e :
186187 log .error (e , exc_info = True )
187- return path_to_extract .encode ()
188+ return ( path_to_extract .encode (), child . platform , child . get_type (), child . get_size () )
188189
189190
190- def demux_sflock (filename : bytes , options : str , check_shellcode : bool = True ) -> List [bytes ]:
191+ # ToDo fix typing need to add str as error msg
192+ def demux_sflock (filename : bytes , options : str , check_shellcode : bool = True ): # -> List[bytes]:
191193 retlist = []
192194 # do not extract from .bin (downloaded from us)
193195 if os .path .splitext (filename )[1 ] == b".bin" :
194- return retlist
196+ return retlist , ""
195197
198+ # ToDo need to introduce error msgs here
196199 try :
197200 password = options2passwd (options ) or "infected"
198201 try :
@@ -201,9 +204,13 @@ def demux_sflock(filename: bytes, options: str, check_shellcode: bool = True) ->
201204 unpacked = unpack (filename , check_shellcode = check_shellcode )
202205
203206 if unpacked .package in whitelist_extensions :
204- return [filename ]
207+ file = File (filename )
208+ magic_type = file .get_type ()
209+ platform = file .get_platform ()
210+ file_size = file .get_size ()
211+ return [filename , platform , magic_type , file_size ], ""
205212 if unpacked .package in blacklist_extensions :
206- return [filename ]
213+ return [], "blacklisted package"
207214 for sf_child in unpacked .children :
208215 if sf_child .to_dict ().get ("children" ):
209216 retlist .extend (_sf_children (ch ) for ch in sf_child .children )
@@ -214,7 +221,7 @@ def demux_sflock(filename: bytes, options: str, check_shellcode: bool = True) ->
214221 retlist .append (_sf_children (sf_child ))
215222 except Exception as e :
216223 log .error (e , exc_info = True )
217- return list (filter (None , retlist ))
224+ return list (filter (None , retlist )), ""
218225
219226
220227def demux_sample (filename : bytes , package : str , options : str , use_sflock : bool = True , platform : str = "" ): # -> tuple[bytes, str]:
@@ -227,21 +234,29 @@ def demux_sample(filename: bytes, package: str, options: str, use_sflock: bool =
227234 if isinstance (filename , str ) and use_sflock :
228235 filename = filename .encode ()
229236
237+ error_list = []
230238 retlist = []
231239 # if a package was specified, trim if allowed and required
232240 if package :
233-
234241 if package in ("msix" ,):
235242 retlist .append ((filename , "windows" ))
236243 else :
237244 if File (filename ).get_size () <= web_cfg .general .max_sample_size or (
238245 web_cfg .general .allow_ignore_size and "ignore_size_check" in options
239246 ):
240- retlist .append ((filename , platform ))
247+ retlist .append ((filename , platform , "" ))
241248 else :
242249 if web_cfg .general .enable_trim and trim_file (filename ):
243250 retlist .append ((trimmed_path (filename ), platform ))
244- return retlist
251+ else :
252+ error_list .append (
253+ {
254+ os .path .basename (
255+ filename
256+ ): "File too bit, enable 'allow_ignore_size' in web.conf or use 'ignore_size_check' option"
257+ }
258+ )
259+ return retlist , error_list
245260
246261 # handle quarantine files
247262 tmp_path = unquarantine (filename )
@@ -259,9 +274,16 @@ def demux_sample(filename: bytes, package: str, options: str, use_sflock: bool =
259274 if use_sflock :
260275 if HAS_SFLOCK :
261276 retlist = demux_office (filename , password , platform )
262- return retlist
277+ return retlist , error_list
263278 else :
264279 log .error ("Detected password protected office file, but no sflock is installed: poetry install" )
280+ error_list .append (
281+ {
282+ os .path .basename (
283+ filename
284+ ): "Detected password protected office file, but no sflock is installed or correct password provided"
285+ }
286+ )
265287
266288 # don't try to extract from Java archives or executables
267289 if (
@@ -279,7 +301,14 @@ def demux_sample(filename: bytes, package: str, options: str, use_sflock: bool =
279301 else :
280302 if web_cfg .general .enable_trim and trim_file (filename ):
281303 retlist .append ((trimmed_path (filename ), platform ))
282- return retlist
304+ else :
305+ error_list .append (
306+ {
307+ os .path .basename (filename ),
308+ "File too bit, enable 'allow_ignore_size' in web.conf or use 'ignore_size_check' option" ,
309+ }
310+ )
311+ return retlist , error_list
283312
284313 new_retlist = []
285314
@@ -288,26 +317,34 @@ def demux_sample(filename: bytes, package: str, options: str, use_sflock: bool =
288317 check_shellcode = False
289318
290319 # all in one unarchiver
291- retlist = demux_sflock (filename , options , check_shellcode ) if HAS_SFLOCK and use_sflock else []
320+ retlist , error_msg = demux_sflock (filename , options , check_shellcode ) if HAS_SFLOCK and use_sflock else []
292321 # if it isn't a ZIP or an email, or we aren't able to obtain anything interesting from either, then just submit the
293322 # original file
294323 if not retlist :
324+ if error_msg :
325+ error_list .append ({os .path .basename (filename ), error_msg })
295326 new_retlist .append ((filename , platform ))
296327 else :
297- for filename in retlist :
328+ for filename , platform , magic_type , file_size in retlist :
298329 # verify not Windows binaries here:
299- file = File (filename )
300- magic_type = file .get_type ()
301- platform = file .get_platform ()
302330 if platform == "linux" and not linux_enabled and "Python" not in magic_type :
331+ error_list .append ({os .path .basename (filename ): "Linux processing is disabled" })
303332 continue
304333
305- if file . get_size () > web_cfg .general .max_sample_size and not (
334+ if file_size > web_cfg .general .max_sample_size and not (
306335 web_cfg .general .allow_ignore_size and "ignore_size_check" in options
307336 ):
308337 if web_cfg .general .enable_trim :
309338 # maybe identify here
310339 if trim_file (filename ):
311340 filename = trimmed_path (filename )
341+ else :
342+ error_list .append (
343+ {
344+ os .path .basename (filename ),
345+ "File too bit, enable 'allow_ignore_size' in web.conf or use 'ignore_size_check' option" ,
346+ }
347+ )
312348 new_retlist .append ((filename , platform ))
313- return new_retlist [:10 ]
349+
350+ return new_retlist [:10 ], error_list
0 commit comments