From b5b2fd7c0efe5c08b4d428217bee1bec6a29b450 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Thu, 30 May 2019 09:03:23 +0300 Subject: [PATCH] PBA created after we check if it's going to run --- .../post_breach/actions/users_custom_pba.py | 11 +++++++++-- monkey/infection_monkey/post_breach/pba.py | 3 ++- .../post_breach/post_breach_handler.py | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/monkey/infection_monkey/post_breach/actions/users_custom_pba.py b/monkey/infection_monkey/post_breach/actions/users_custom_pba.py index a297dbd1c..61ec6f5d7 100644 --- a/monkey/infection_monkey/post_breach/actions/users_custom_pba.py +++ b/monkey/infection_monkey/post_breach/actions/users_custom_pba.py @@ -58,8 +58,15 @@ class UsersPBA(PBA): UsersPBA.download_pba_file(get_monkey_dir_path(), self.filename) return super(UsersPBA, self)._execute_default() - def should_run(self, class_name): - return self.command + @staticmethod + def should_run(class_name): + if not is_windows_os(): + if WormConfiguration.PBA_linux_filename or WormConfiguration.custom_PBA_linux_cmd: + return True + else: + if WormConfiguration.PBA_windows_filename or WormConfiguration.custom_PBA_windows_cmd: + return True + return False @staticmethod def download_pba_file(dst_dir, filename): diff --git a/monkey/infection_monkey/post_breach/pba.py b/monkey/infection_monkey/post_breach/pba.py index 38c9c13da..8be04a468 100644 --- a/monkey/infection_monkey/post_breach/pba.py +++ b/monkey/infection_monkey/post_breach/pba.py @@ -30,7 +30,8 @@ class PBA(object): """ return self - def should_run(self, class_name): + @staticmethod + def should_run(class_name): """ Decides if post breach action is enabled in config :return: True if it needs to be ran, false otherwise diff --git a/monkey/infection_monkey/post_breach/post_breach_handler.py b/monkey/infection_monkey/post_breach/post_breach_handler.py index 17e2a8950..8522f412f 100644 --- a/monkey/infection_monkey/post_breach/post_breach_handler.py +++ b/monkey/infection_monkey/post_breach/post_breach_handler.py @@ -45,7 +45,7 @@ class PostBreach(object): if ((m[1].__module__ == module.__name__) and issubclass(m[1], PBA))] # Get post breach action object from class for pba_class in pba_classes: - pba = pba_class() - if pba.should_run(pba_class.__name__): + if pba_class.should_run(pba_class.__name__): + pba = pba_class() pba_list.append(pba) return pba_list