From b7439258c9cdadc7bd14a0a0b49e2db2d0f5b537 Mon Sep 17 00:00:00 2001 From: Olivier Cervello Date: Sun, 10 Nov 2024 12:29:08 -0500 Subject: [PATCH] fix: mix bugfixes for stable release --- secator/celery.py | 3 ++- secator/configs/workflows/host_recon.yaml | 1 - secator/decorators.py | 20 +++++++++++++++----- secator/tasks/naabu.py | 2 +- secator/tasks/nmap.py | 2 +- secator/tasks/searchsploit.py | 2 ++ secator/utils.py | 2 +- 7 files changed, 22 insertions(+), 10 deletions(-) diff --git a/secator/celery.py b/secator/celery.py index b6fecba4..28bb9bc4 100644 --- a/secator/celery.py +++ b/secator/celery.py @@ -252,8 +252,9 @@ def run_command(self, results, name, targets, opts={}): results = deduplicate(results, attr='_uuid') # Get expanded targets - if not chunk: + if not chunk and results: targets, opts = run_extractors(results, opts, targets) + debug('after extractors', obj={'targets': targets, 'opts': opts}, sub='celery.state') try: # Get task class diff --git a/secator/configs/workflows/host_recon.yaml b/secator/configs/workflows/host_recon.yaml index 7f3e8570..48d5e2f6 100644 --- a/secator/configs/workflows/host_recon.yaml +++ b/secator/configs/workflows/host_recon.yaml @@ -9,7 +9,6 @@ input_types: tasks: naabu: description: Find open ports - ports: "-" # scan all ports nmap: description: Search for vulnerabilities on open ports skip_host_discovery: True diff --git a/secator/decorators.py b/secator/decorators.py index 9c351510..15982a37 100644 --- a/secator/decorators.py +++ b/secator/decorators.py @@ -174,23 +174,33 @@ def get_command_options(config): if conf.get('required', False): debug('OPT (skipped: opt is required and defined in config)', obj={'opt': opt}, sub=f'cli.{config.name}', verbose=True) # noqa: E501 continue - if opt_default is not None and opt_value_in_config != opt_default and opt_is_flag: - conf['reverse'] = True - conf['default'] = not conf['default'] + mapped_value = cls.opt_value_map.get(opt) + if callable(mapped_value): + opt_value_in_config = mapped_value(opt_value_in_config) + elif mapped_value: + opt_value_in_config = mapped_value + if opt_value_in_config != opt_default: + if opt in opt_cache: + continue + if opt_is_flag: + conf['reverse'] = True + conf['default'] = not conf['default'] + # print(f'{opt}: change default to {opt_value_in_config}') + conf['default'] = opt_value_in_config # If opt is a flag but the default is True, add opposite flag if opt_is_flag and opt_default is True: conf['reverse'] = True # Check if opt already processed before - opt = opt.replace('_', '-') if opt in opt_cache: # debug('OPT (skipped: opt is already in opt cache)', obj={'opt': opt}, sub=f'cli.{config.name}', verbose=True) continue # Build help - all_opts[opt] = conf opt_cache.append(opt) + opt = opt.replace('_', '-') + all_opts[opt] = conf # Debug debug_conf = OrderedDict({'opt': opt, 'config_val': opt_value_in_config or 'N/A', **conf.copy()}) diff --git a/secator/tasks/naabu.py b/secator/tasks/naabu.py index 5acf5ca0..26eeacda 100644 --- a/secator/tasks/naabu.py +++ b/secator/tasks/naabu.py @@ -15,7 +15,7 @@ class naabu(ReconPort): file_flag = '-list' json_flag = '-json' opts = { - PORTS: {'type': str, 'short': 'p', 'help': 'Ports (default: nmap\'s top 100 ports'}, + PORTS: {'type': str, 'short': 'p', 'help': 'Ports'}, TOP_PORTS: {'type': str, 'short': 'tp', 'help': 'Top ports'}, 'scan_type': {'type': str, 'short': 'st', 'help': 'Scan type (SYN (s)/CONNECT(c))'}, # 'health_check': {'is_flag': True, 'short': 'hc', 'help': 'Health check'} diff --git a/secator/tasks/nmap.py b/secator/tasks/nmap.py index 192f55a5..1bc42882 100644 --- a/secator/tasks/nmap.py +++ b/secator/tasks/nmap.py @@ -30,7 +30,7 @@ class nmap(VulnMulti): opt_prefix = '--' output_types = [Port, Vulnerability, Exploit] opts = { - PORTS: {'type': str, 'short': 'p', 'help': 'Ports to scan (default: most common 1000 ports for each protocol)'}, + PORTS: {'type': str, 'short': 'p', 'default': 'top-1000', 'help': 'Ports to scan'}, TOP_PORTS: {'type': int, 'short': 'tp', 'help': 'Top ports to scan [full, 100, 1000]'}, SCRIPT: {'type': str, 'default': 'vulners', 'help': 'NSE scripts'}, 'skip_host_discovery': {'is_flag': True, 'short': 'Pn', 'default': False, 'help': 'Skip host discovery (no ping)'}, diff --git a/secator/tasks/searchsploit.py b/secator/tasks/searchsploit.py index ee4335f4..7d2a1401 100644 --- a/secator/tasks/searchsploit.py +++ b/secator/tasks/searchsploit.py @@ -58,6 +58,8 @@ def tags_extractor(item): @staticmethod def before_init(self): + if len(self.inputs) == 0: + return _in = self.inputs[0] self.matched_at = None if '~' in _in: diff --git a/secator/utils.py b/secator/utils.py index 746662da..d4dac9f4 100644 --- a/secator/utils.py +++ b/secator/utils.py @@ -380,7 +380,7 @@ def debug(msg, sub='', id='', obj=None, lazy=None, obj_after=True, obj_breakline if isinstance(obj, dict): obj_str += sep.join(f'[dim blue]{k}[/] [dim yellow]->[/] [dim green]{v}[/]' for k, v in obj.items() if v is not None) elif isinstance(obj, list): - obj_str += f'[dim]{sep.join(obj)}[/]' + obj_str += f'[dim green]{sep.join(obj)}[/]' if obj_str and not obj_after: s = f'{s} {obj_str} ' s += f'[dim yellow]{msg}[/] '