Skip to content

Commit 9177b6d

Browse files
authored
Fix downloaders order (#2511)
1 parent 7f73a66 commit 9177b6d

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

lib/cuckoo/common/load_extra_modules.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import glob
22
import importlib
33
import inspect
4+
import logging
45
import os
56
import pkgutil
67
from pathlib import Path
78

89
from lib.cuckoo.common.config import Config
910

11+
log = logging.getLogger(__name__)
12+
1013
integrations_conf = Config("integrations")
1114

1215

@@ -42,7 +45,7 @@ def ratdecodedr_load_decoders(path: str):
4245
try:
4346
module = importlib.import_module(module_name)
4447
except ImportError as e:
45-
print(f"Unable to import Module {module_name}: {e}")
48+
log.error("Unable to import Module %s - %s", module_name, e)
4649
continue
4750

4851
for mod_name, mod_object in inspect.getmembers(module):
@@ -103,11 +106,11 @@ def cape_load_custom_decoders(CUCKOO_ROOT: str):
103106
# For example, a cape_type of "Emotet Payload" would trigger a config parser named "Emotet.py".
104107
cape_modules[name.replace("_", " ")] = importlib.import_module(f"{versions[version]}.{name}")
105108
except (ImportError, IndexError, AttributeError) as e:
106-
print(f"CAPE parser: No module named {name} - {e}")
109+
log.error("CAPE parser: No module named %s - %s", name, e)
107110
except SyntaxError as e:
108-
print(f"CAPE parser: Fix your code in {name} - {e}")
111+
log.error("CAPE parser: Fix your code in %s - %s", name, e)
109112
except Exception as e:
110-
print(f"CAPE parser: Fix your code in {name} - {e}")
113+
log.error("CAPE parser: Fix your code in %s - %s", name, e)
111114

112115
return cape_modules
113116

@@ -135,7 +138,7 @@ def malduck_load_decoders(CUCKOO_ROOT: str):
135138
try:
136139
malduck_modules[name] = importlib.import_module(f"modules.processing.parsers.malduck.{name}")
137140
except (ImportError, IndexError) as e:
138-
print(f"malduck parser: No module named {name} - {e}")
141+
log.error("malduck parser: No module named %s - %s", name, e)
139142

140143
return malduck_modules
141144

@@ -174,7 +177,7 @@ def file_extra_info_load_modules(CUCKOO_ROOT: str):
174177
continue
175178
file_extra_modules.append(module)
176179
except (ImportError, IndexError, AttributeError) as e:
177-
print(f"file_extra_info module: No module named {name} - {e}")
180+
log.error("file_extra_info module: No module named %s - %s", name, e)
178181

179182
return file_extra_modules
180183

@@ -218,13 +221,15 @@ def load_downloaders(CUCKOO_ROOT: str):
218221
for name in names:
219222
try:
220223
module = importlib.import_module(f"{versions[version]}.{name}")
221-
# config under [abusech]
222-
if name == "malwarebazaar" and not getattr(module, "enabled", False) and not integrations_conf.__dict__.get("abusech", {}).get("malwarebazaar", False):
223-
continue
224-
elif not getattr(module, "enabled", False) and not integrations_conf.__dict__.get(name, {}).get("enabled", False):
225-
continue
224+
if name == "malwarebazaar":
225+
# config under [abusech]
226+
if not integrations_conf.__dict__.get("abusech", {}).get("malwarebazaar", False):
227+
continue
228+
else:
229+
if not getattr(module, "enabled", False) and not integrations_conf.__dict__.get(name, {}).get("enabled", False):
230+
continue
226231
downloaders[name] = module
227232
except (ImportError, IndexError, AttributeError) as e:
228-
print(f"Downloader: No module named {name} - {e}")
233+
log.error("Downloader: No module named %s - %s", name, e)
229234

230235
return downloaders

lib/downloaders/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class Downloaders(object):
3232
def __init__(self, destination_folder=None):
3333
self.downloaders = load_downloaders(CUCKOO_ROOT)
3434
if integrations_cfg.downloaders.order:
35-
self.downloaders_order = [k.strip() for k in self.downloaders.keys() if k.strip() in integrations_cfg.downloaders.order]
35+
order_list = [item.strip() for item in integrations_cfg.downloaders.order.split(',')]
36+
self.downloaders_order = [k for k in order_list if k in self.downloaders.keys()]
3637
else:
3738
self.downloaders_order = list(self.downloaders.keys())
3839

0 commit comments

Comments
 (0)