Load from the user's module store
This commit is contained in:
@@ -22,6 +22,13 @@ module Msf::Modules::Metadata::Store
|
||||
load_metadata
|
||||
end
|
||||
|
||||
def get_user_store
|
||||
store_dir = ::File.join(Msf::Config.config_directory, "store")
|
||||
FileUtils.makedirs(store_dir) if !::File.exist?(store_dir)
|
||||
return ::File.join(store_dir, UserMetaDataFile)
|
||||
end
|
||||
|
||||
|
||||
#######
|
||||
private
|
||||
#######
|
||||
@@ -107,12 +114,6 @@ module Msf::Modules::Metadata::Store
|
||||
return copied
|
||||
end
|
||||
|
||||
def get_user_store
|
||||
store_dir = ::File.join(Msf::Config.config_directory, "store")
|
||||
FileUtils.makedirs(store_dir) if !::File.exist?(store_dir)
|
||||
return ::File.join(store_dir, UserMetaDataFile)
|
||||
end
|
||||
|
||||
def load_cache_from_file_store
|
||||
cache_map = JSON.parse(File.read(@path_to_user_metadata))
|
||||
cache_map.each {|k,v|
|
||||
|
||||
+2
-1
@@ -44,6 +44,7 @@ module Msf
|
||||
#
|
||||
def cmd_fzuse(*args)
|
||||
previewer = File.join(Msf::Config.install_root, 'tools', 'modules', 'print.py')
|
||||
metadata_path = Msf::Modules::Metadata::Cache.instance.get_user_store
|
||||
|
||||
module_types = framework.modules.module_types
|
||||
|
||||
@@ -52,7 +53,7 @@ module Msf
|
||||
selection = nil
|
||||
# alternative preview:
|
||||
# jq \'to_entries[] | select(.value.fullname == "{1}") | .value\' db/modules_metadata_base.json | bat --language=json --color=always
|
||||
stdin, stdout, stderr, wait_thr = Open3.popen3('fzf', '--select-1', '--query', query, '--preview', "#{previewer} {1}", '--preview-label', "Module Information") do |stdin, stdout, stderr, wait_thr|
|
||||
stdin, stdout, stderr, wait_thr = Open3.popen3('fzf', '--select-1', '--query', query, '--preview', "#{previewer} --metadata-path '#{metadata_path}' '{1}'", '--preview-label', "Module Information") do |stdin, stdout, stderr, wait_thr|
|
||||
module_types
|
||||
module_types.each do |module_type|
|
||||
framework.modules.module_names(module_type).each do |module_name|
|
||||
|
||||
+11
-4
@@ -23,6 +23,7 @@ RANKS = {
|
||||
}
|
||||
|
||||
framework_root = pathlib.Path(__file__).parent.parent.parent
|
||||
default_metadata_path = (framework_root / 'db' / 'modules_metadata_base.json')
|
||||
|
||||
def get_notes(module_metadata):
|
||||
tree = Tree('Notes', hide_root=True)
|
||||
@@ -64,10 +65,11 @@ def get_bulleted_list(items):
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='fzuse helper', conflict_handler='resolve')
|
||||
parser.add_argument('module_name', help='module name to display')
|
||||
parser.add_argument('--metadata-path', default=default_metadata_path, type=pathlib.Path, help='the path to the module metadata')
|
||||
parser.add_argument('-v', '--version', action='version', version='%(prog)s Version: ' + __version__)
|
||||
arguments = parser.parse_args()
|
||||
|
||||
with (framework_root / 'db' / 'modules_metadata_base.json').open('r') as file_h:
|
||||
with arguments.metadata_path.open('r') as file_h:
|
||||
all_metadata = json.load(file_h)
|
||||
module_metadata = next((metadata for metadata in all_metadata.values() if metadata['fullname'] == arguments.module_name), None)
|
||||
if not module_metadata:
|
||||
@@ -84,7 +86,7 @@ def main():
|
||||
table.add_row('[bold]Rank[/bold]', RANKS[module_metadata['rank']])
|
||||
table.add_row('[bold]Disclosed[/bold]', module_metadata['disclosure_date'])
|
||||
|
||||
console = Console()
|
||||
console = Console(color_system='256')
|
||||
console.print(table)
|
||||
|
||||
panel_title = lambda v: f"[bold]{v}[/bold]"
|
||||
@@ -96,8 +98,13 @@ def main():
|
||||
if module_metadata.get('references'):
|
||||
console.print(Panel(get_references(module_metadata), title=panel_title('References'), title_align='left'))
|
||||
if module_metadata.get('path', ''):
|
||||
syntax = Syntax.from_path(framework_root / module_metadata['path'][1:], background_color='default', line_numbers=True)
|
||||
console.print(Panel(syntax, title=panel_title('Source code'), title_align='left'))
|
||||
if pathlib.Path(module_metadata['path']).is_file():
|
||||
module_path = pathlib.Path(module_metadata['path'])
|
||||
elif pathlib.Path(framework_root / module_metadata['path'][1:]).is_file():
|
||||
module_path = pathlib.Path(framework_root / module_metadata['path'][1:])
|
||||
if module_path:
|
||||
syntax = Syntax.from_path(module_path, background_color='default', line_numbers=True)
|
||||
console.print(Panel(syntax, title=panel_title('Source code'), title_align='left'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user