Skip to content

Commit e71b67a

Browse files
committed
Converted all marketplace and module listing to searching.
Created a private method for smart searching modules. Replaced module string searching with regex.
1 parent b9a65e6 commit e71b67a

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

recon-cli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def recon_cli(args):
4141
return
4242
# if requested, show modules and exit
4343
if args.show_modules:
44-
x._do_module_list('')
44+
x._do_module_search('')
4545
return
4646
# exit if module not specified
4747
if not args.module:

recon/core/base.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -520,13 +520,13 @@ def do_marketplace(self, params):
520520
self.help_marketplace()
521521
return
522522
arg, params = self._parse_params(params)
523-
if arg in ['list', 'info', 'install', 'remove']:
523+
if arg in ['search', 'info', 'install', 'remove']:
524524
return getattr(self, '_do_marketplace_'+arg)(params)
525525
else:
526526
self.help_marketplace()
527527

528-
def _do_marketplace_list(self, params):
529-
'''Lists all available modules in the marketplace'''
528+
def _do_marketplace_search(self, params):
529+
'''Searches marketplace modules'''
530530
modules = [m for m in self._module_index]
531531
if params:
532532
self.output(f"Searching module index for '{params}'...")
@@ -546,7 +546,7 @@ def _do_marketplace_list(self, params):
546546
print(f"{self.spacer}K = Requires keys. See info for details.{os.linesep}")
547547
else:
548548
self.error('No modules found.')
549-
self._help_marketplace_list()
549+
self._help_marketplace_search()
550550

551551
def _do_marketplace_info(self, params):
552552
'''Shows detailed information about available modules'''
@@ -602,7 +602,7 @@ def do_workspaces(self, params):
602602
self.help_workspaces()
603603

604604
def _do_workspaces_list(self, params):
605-
'''Lists all existing workspaces'''
605+
'''Lists existing workspaces'''
606606
self.table([[x] for x in self._get_workspaces()], header=['Workspaces'])
607607

608608
def _do_workspaces_create(self, params):
@@ -641,7 +641,7 @@ def do_snapshots(self, params):
641641
self.help_snapshots()
642642

643643
def _do_snapshots_list(self, params):
644-
'''Lists all existing database snapshots'''
644+
'''Lists existing database snapshots'''
645645
snapshots = self._get_snapshots()
646646
if snapshots:
647647
self.table([[x] for x in snapshots], header=['Snapshots'])
@@ -693,7 +693,7 @@ def _do_module_load(self, params):
693693
self._help_module_load()
694694
return
695695
# finds any modules that contain params
696-
modules = [params] if params in self._loaded_modules else [x for x in self._loaded_modules if params in x]
696+
modules = self._match_modules(params)
697697
# notify the user if none or multiple modules are found
698698
if len(modules) != 1:
699699
if not modules:
@@ -746,11 +746,11 @@ def help_index(self):
746746

747747
def help_marketplace(self):
748748
print(getattr(self, 'do_marketplace').__doc__)
749-
print(f"{os.linesep}Usage: marketplace <list|info|install|remove> [...]{os.linesep}")
749+
print(f"{os.linesep}Usage: marketplace <search|info|install|remove> [...]{os.linesep}")
750750

751-
def _help_marketplace_list(self):
752-
print(getattr(self, '_do_marketplace_list').__doc__)
753-
print(f"{os.linesep}Usage: marketplace list [<regex>]{os.linesep}")
751+
def _help_marketplace_search(self):
752+
print(getattr(self, '_do_marketplace_search').__doc__)
753+
print(f"{os.linesep}Usage: marketplace search [<regex>]{os.linesep}")
754754

755755
def _help_marketplace_info(self):
756756
print(getattr(self, '_do_marketplace_info').__doc__)
@@ -803,12 +803,12 @@ def complete_index(self, text, line, *ignored):
803803

804804
def complete_marketplace(self, text, line, *ignored):
805805
arg, params = self._parse_params(line.split(' ', 1)[1])
806-
subs = ['list', 'info', 'install', 'remove']
806+
subs = ['search', 'info', 'install', 'remove']
807807
if arg in subs:
808808
return getattr(self, '_complete_marketplace_'+arg)(text, params)
809809
return [sub for sub in subs if sub.startswith(text)]
810810

811-
def _complete_marketplace_list(self, text, *ignored):
811+
def _complete_marketplace_search(self, text, *ignored):
812812
return []
813813

814814
def _complete_marketplace_info(self, text, *ignored):

recon/core/framework.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,13 @@ def request(self, url, method='GET', timeout=None, payload={}, headers={}, agent
777777
# MODULES METHODS
778778
#==================================================
779779

780+
def _match_modules(self, params):
781+
# return an exact match
782+
if params in Framework._loaded_modules:
783+
return [params]
784+
# use the provided name as a keyword search and return the results
785+
return [x for x in Framework._loaded_modules if params in x]
786+
780787
def _list_modules(self, modules):
781788
if modules:
782789
key_len = len(max(modules, key=len)) + len(self.spacer)
@@ -906,22 +913,22 @@ def do_module(self, params):
906913
self.help_module()
907914
return
908915
arg, params = self._parse_params(params)
909-
if arg in ['list', 'load', 'reload']:
916+
if arg in ['search', 'load', 'reload']:
910917
return getattr(self, '_do_module_'+arg)(params)
911918
else:
912919
self.help_module()
913920

914-
def _do_module_list(self, params):
915-
'''Lists installed modules'''
921+
def _do_module_search(self, params):
922+
'''Searches installed modules'''
916923
modules = [x for x in Framework._loaded_modules]
917924
if params:
918925
self.output(f"Searching installed modules for '{params}'...")
919-
modules = [x for x in Framework._loaded_modules if params in x]
926+
modules = [x for x in Framework._loaded_modules if re.search(params, x)]
920927
if modules:
921928
self._list_modules(modules)
922929
else:
923930
self.error('No modules found.')
924-
self._help_module_list()
931+
self._help_module_search()
925932

926933
def _do_module_load(self, params):
927934
raise NotImplementedError
@@ -1216,11 +1223,11 @@ def _help_keys_remove(self):
12161223

12171224
def help_module(self):
12181225
print(getattr(self, 'do_module').__doc__)
1219-
print(f"{os.linesep}Usage: module <list|load|reload> [...]{os.linesep}")
1226+
print(f"{os.linesep}Usage: module <search|load|reload> [...]{os.linesep}")
12201227

1221-
def _help_module_list(self):
1222-
print(getattr(self, '_do_module_list').__doc__)
1223-
print(f"{os.linesep}Usage: module list [<string>]{os.linesep}")
1228+
def _help_module_search(self):
1229+
print(getattr(self, '_do_module_search').__doc__)
1230+
print(f"{os.linesep}Usage: module search [<regex>]{os.linesep}")
12241231

12251232
def _help_module_load(self):
12261233
print(getattr(self, '_do_module_load').__doc__)
@@ -1307,14 +1314,14 @@ def _complete_keys_add(self, text, *ignored):
13071314

13081315
def complete_module(self, text, line, *ignored):
13091316
arg, params = self._parse_params(line.split(' ', 1)[1])
1310-
subs = ['list', 'load', 'reload']
1317+
subs = ['search', 'load', 'reload']
13111318
if arg in subs:
13121319
return getattr(self, '_complete_module_'+arg)(text, params)
13131320
return [sub for sub in subs if sub.startswith(text)]
13141321

1315-
def _complete_module_list(self, text, *ignored):
1322+
def _complete_module_search(self, text, *ignored):
13161323
return []
1317-
_complete_module_reload = _complete_module_list
1324+
_complete_module_reload = _complete_module_search
13181325

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

recon/core/module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ def _do_module_load(self, params):
531531
self._help_module_load()
532532
return
533533
# finds any modules that contain params
534-
modules = [params] if params in framework.Framework._loaded_modules else [x for x in framework.Framework._loaded_modules if params in x]
534+
modules = self._match_modules(params)
535535
# notify the user if none or multiple modules are found
536536
if len(modules) != 1:
537537
if not modules:

0 commit comments

Comments
 (0)