Skip to content

[BUG] hook_preload #92

@Ektoplasma

Description

@Ektoplasma

Describe the bug
When the preload hook is triggered, the hook function of the module iris_check_module fails.

app_1 | 2022-04-12 10:25:43 :: CRITICAL :: module_handler :: call_modules_hook :: Failed to run hook on_preload_ioc_create with module iris_check_module. Error 0

To Reproduce
Steps to reproduce the behavior:

  1. Enable iris_check_module hooks
  2. Goto Case->Iocs
  3. Create an IOC
  4. See error

Expected behavior
Should not return any error or additional log message.

Additional context
The module expects a list of data in the hook function, but we send only the data as it is (a dictionary). We should either modify the call_modules_hook function is iris_engine/module_handler, to send a list of data just like the asynchronous hooks, or edit the iris_check_module to handle hooks differently when it's either asynchronous or not (preload is not asynchronous).

Example of (dirty) patch (./source/app/iris_engine/module_handler/module_handler.py):

  • Before:
        else:
            # Direct call. Should be fast
            log.info(f'Calling module {module.module_name} for hook {hook_name}')

            try:
                mod_inst = instantiate_module_from_name(module_name=module.module_name)
                status = mod_inst.hooks_handler(hook_name, module.manual_hook_ui_name, data=data)
            except Exception as e:
                log.critical(f"Failed to run hook {hook_name} with module {module.module_name}. Error {str(e)}")
                continue

            if status.is_success():
                data = status.get_data()
  • After:
        else:
            # Direct call. Should be fast
            log.info(f'Calling module {module.module_name} for hook {hook_name}')

            try:
                mod_inst = instantiate_module_from_name(module_name=module.module_name)
                data = [data]
                status = mod_inst.hooks_handler(hook_name, module.manual_hook_ui_name, data=data)
            except Exception as e:
                log.critical(f"Failed to run hook {hook_name} with module {module.module_name}. Error {str(e)}")
                continue

            if status.is_success():
                data = status.get_data()
                data = data[0]

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions