Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reverted all module commands back to modules.
Created a `module` command for the module context.

Modified the `run` command to be a subcommand of the `module` command in the module context.
  • Loading branch information
lanmaster53 committed Jun 6, 2019
1 parent f47d917 commit 20de40c
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 44 deletions.
4 changes: 2 additions & 2 deletions recon-cli
Expand Up @@ -41,14 +41,14 @@ def recon_cli(args):
return
# if requested, show modules and exit
if args.show_modules:
x._do_module_search('')
x._do_modules_search('')
return
# exit if module not specified
if not args.module:
output('No module provided.')
return
# load the module
y = x._do_module_load(args.module)
y = x._do_modules_load(args.module)
# exit if module not successfully loaded
if not y: return
print(f"MODULE => {args.module}")
Expand Down
20 changes: 10 additions & 10 deletions recon/core/base.py
Expand Up @@ -573,7 +573,7 @@ def _do_marketplace_install(self, params):
if modules:
for module in modules:
self._install_module(module['path'])
self._do_module_reload('')
self._do_modules_reload('')
else:
self.error('Invalid module path.')

Expand All @@ -586,7 +586,7 @@ def _do_marketplace_remove(self, params):
if modules:
for module in modules:
self._remove_module(module['path'])
self._do_module_reload('')
self._do_modules_reload('')
else:
self.error('Invalid module path.')

Expand Down Expand Up @@ -681,7 +681,7 @@ def _do_snapshots_delete(self, params):
else:
self.error(f"No snapshot named '{params}'.")

def _do_module_load(self, params):
def _do_modules_load(self, params):
'''Loads a module'''
# validate global options before loading the module
try:
Expand All @@ -690,7 +690,7 @@ def _do_module_load(self, params):
self.error(e)
return
if not params:
self._help_module_load()
self._help_modules_load()
return
# finds any modules that contain params
modules = self._match_modules(params)
Expand Down Expand Up @@ -731,7 +731,7 @@ def _do_module_load(self, params):
# shuffle category counts?
break

def _do_module_reload(self, params):
def _do_modules_reload(self, params):
'''Reloads installed modules'''
self.output('Reloading modules...')
self._load_modules()
Expand Down Expand Up @@ -792,9 +792,9 @@ def _help_snapshots_delete(self):
print(getattr(self, '_do_snapshots_delete').__doc__)
print(f"{os.linesep}Usage: snapshots delete <name>{os.linesep}")

def _help_module_load(self):
print(getattr(self, '_do_module_load').__doc__)
print(f"{os.linesep}Usage: module load <path>{os.linesep}")
def _help_modules_load(self):
print(getattr(self, '_do_modules_load').__doc__)
print(f"{os.linesep}Usage: modules load <path>{os.linesep}")

#==================================================
# COMPLETE METHODS
Expand Down Expand Up @@ -852,10 +852,10 @@ def _complete_snapshots_load(self, text, *ignored):
return [x for x in self._get_snapshots() if x.startswith(text)]
_complete_snapshots_delete = _complete_snapshots_load

def _complete_module_load(self, text, *ignored):
def _complete_modules_load(self, text, *ignored):
return [x for x in Framework._loaded_modules if x.startswith(text)]

def _complete_module_reload(self, text, *ignored):
def _complete_modules_reload(self, text, *ignored):
return []

#=================================================
Expand Down
39 changes: 19 additions & 20 deletions recon/core/framework.py
Expand Up @@ -818,9 +818,8 @@ def _get_show_names(self):
def _parse_subcommands(self, command):
subcommands = []
for method in dir(self):
if callable(getattr(self, method)):
if f"_do_{command}" in method:
subcommands.append(method.split('_')[-1])
if f"_do_{command}_" in method:
subcommands.append(method.split('_')[-1])
return subcommands

def _parse_params(self, params):
Expand Down Expand Up @@ -915,18 +914,18 @@ def _do_keys_remove(self, params):
else:
self.error('Invalid key name.')

def do_module(self, params):
def do_modules(self, params):
'''Interfaces with installed modules'''
if not params:
self.help_module()
self.help_modules()
return
arg, params = self._parse_params(params)
if arg in self._parse_subcommands('module'):
return getattr(self, '_do_module_'+arg)(params)
if arg in self._parse_subcommands('modules'):
return getattr(self, '_do_modules_'+arg)(params)
else:
self.help_module()
self.help_modules()

def _do_module_search(self, params):
def _do_modules_search(self, params):
'''Searches installed modules'''
modules = [x for x in Framework._loaded_modules]
if params:
Expand All @@ -936,7 +935,7 @@ def _do_module_search(self, params):
self._list_modules(modules)
else:
self.error('No modules found.')
self._help_module_search()
self._help_modules_search()

def do_show(self, params):
'''Shows various framework items'''
Expand Down Expand Up @@ -1223,13 +1222,13 @@ def _help_keys_remove(self):
print(getattr(self, '_do_keys_remove').__doc__)
print(f"{os.linesep}Usage: keys remove <name>{os.linesep}")

def help_module(self):
print(getattr(self, 'do_module').__doc__)
print(f"{os.linesep}Usage: module <{'|'.join(self._parse_subcommands('module'))}> [...]{os.linesep}")
def help_modules(self):
print(getattr(self, 'do_modules').__doc__)
print(f"{os.linesep}Usage: modules <{'|'.join(self._parse_subcommands('modules'))}> [...]{os.linesep}")

def _help_module_search(self):
print(getattr(self, '_do_module_search').__doc__)
print(f"{os.linesep}Usage: module search [<regex>]{os.linesep}")
def _help_modules_search(self):
print(getattr(self, '_do_modules_search').__doc__)
print(f"{os.linesep}Usage: modules search [<regex>]{os.linesep}")

def help_show(self):
options = sorted(self._get_show_names() + self.get_tables())
Expand Down Expand Up @@ -1310,14 +1309,14 @@ def _complete_keys_add(self, text, *ignored):
return [x for x in self._get_key_names() if x.startswith(text)]
_complete_keys_remove = _complete_keys_add

def complete_module(self, text, line, *ignored):
def complete_modules(self, text, line, *ignored):
arg, params = self._parse_params(line.split(' ', 1)[1])
subs = self._parse_subcommands('module')
subs = self._parse_subcommands('modules')
if arg in subs:
return getattr(self, '_complete_module_'+arg)(text, params)
return getattr(self, '_complete_modules_'+arg)(text, params)
return [sub for sub in subs if sub.startswith(text)]

def _complete_module_search(self, text, *ignored):
def _complete_modules_search(self, text, *ignored):
return []

def complete_show(self, text, line, *ignored):
Expand Down
46 changes: 34 additions & 12 deletions recon/core/module.py
Expand Up @@ -465,10 +465,10 @@ def _do_goptions_list(self, params):
'''Shows the global context options'''
self._list_options(self._global_options)

def _do_module_load(self, params):
def _do_modules_load(self, params):
'''Loads a module'''
if not params:
self._help_module_load()
self._help_modules_load()
return
# finds any modules that contain params
modules = self._match_modules(params)
Expand All @@ -489,13 +489,24 @@ def _do_module_load(self, params):
sys.stdin = io.StringIO(f"modules load {modules[0]}{os.linesep}{end_string}")
return True

def do_module(self, params):
'''Interfaces with the loaded module'''
if not params:
self.help_module()
return
arg, params = self._parse_params(params)
if arg in self._parse_subcommands('module'):
return getattr(self, '_do_module_'+arg)(params)
else:
self.help_module()

def _do_module_reload(self, params):
'''Reloads the current module'''
'''Reloads the loaded module'''
self._reload = 1
return True

def _do_module_info(self, params):
'''Shows the current module details'''
'''Shows details about the loaded module'''
print('')
# meta info
for item in ['name', 'author', 'version']:
Expand Down Expand Up @@ -530,8 +541,8 @@ def _do_module_info(self, params):
print(f"{self.spacer}{textwrap.fill(prefix+comment, 100, subsequent_indent=self.spacer)}")
print('')

def _do_module_inputs(self, params):
'''Shows the current inputs based on the source option'''
def _do_module_input(self, params):
'''Shows inputs based on the source option'''
if hasattr(self, '_default_source'):
try:
self._validate_options()
Expand All @@ -542,8 +553,8 @@ def _do_module_inputs(self, params):
else:
self.output('Source option not available for this module.')

def do_run(self, params):
'''Runs the module'''
def _do_module_run(self, params):
'''Runs the loaded module'''
try:
self._summary_counts = {}
self._validate_options()
Expand Down Expand Up @@ -583,9 +594,13 @@ def help_goptions(self):
print(getattr(self, 'do_options').__doc__)
print(f"{os.linesep}Usage: options list{os.linesep}")

def _help_module_load(self):
print(getattr(self, '_do_module_load').__doc__)
print(f"{os.linesep}Usage: module load <path>{os.linesep}")
def _help_modules_load(self):
print(getattr(self, '_do_modules_load').__doc__)
print(f"{os.linesep}Usage: modules load <path>{os.linesep}")

def help_module(self):
print(getattr(self, 'do_module').__doc__)
print(f"{os.linesep}Usage: module <{'|'.join(self._parse_subcommands('module'))}>{os.linesep}")

#==================================================
# COMPLETE METHODS
Expand All @@ -601,9 +616,16 @@ def complete_goptions(self, text, line, *ignored):
def _complete_goptions_list(self, text, *ignored):
return []

def complete_module(self, text, line, *ignored):
arg, params = self._parse_params(line.split(' ', 1)[1])
subs = self._parse_subcommands('module')
if arg in subs:
return getattr(self, '_complete_module_'+arg)(text, params)
return [sub for sub in subs if sub.startswith(text)]

def _complete_module_reload(self, text, *ignored):
return []
_complete_module_info = _complete_module_inputs = _complete_module_reload
_complete_module_info = _complete_module_input = _complete_module_run = _complete_module_reload

#==================================================
# HOOK METHODS
Expand Down

0 comments on commit 20de40c

Please sign in to comment.