Add service manager commands to msfconsle

This commit is contained in:
adfoster-r7 2022-02-02 22:26:41 +00:00
parent b86d5c5dd1
commit 5647e1a94f
No known key found for this signature in database
GPG Key ID: 3BD4FA3818818F04
1 changed files with 63 additions and 1 deletions

View File

@ -9,6 +9,10 @@ class Msf::Ui::Console::CommandDispatcher::Developer
'-e' => [true, 'Expression to evaluate.']
)
@@servicemanager_opts = Rex::Parser::Arguments.new(
['-l', '--list'] => [false, 'View the currently running services' ]
)
def initialize(driver)
super
end
@ -24,7 +28,8 @@ class Msf::Ui::Console::CommandDispatcher::Developer
'edit' => 'Edit the current module or a file with the preferred editor',
'reload_lib' => 'Reload Ruby library files from specified paths',
'log' => 'Display framework.log paged to the end if possible',
'time' => 'Time how long it takes to run a particular command'
'time' => 'Time how long it takes to run a particular command',
'servicemanager' => 'Manage running framework services',
}
end
@ -312,6 +317,63 @@ class Msf::Ui::Console::CommandDispatcher::Developer
end
end
#
# Interact with framework's service manager
#
def cmd_servicemanager(*args)
if args.include?('-h') || args.include?('--help')
cmd_servicemanager_help
return false
end
opts = {}
@@servicemanager_opts.parse(args) do |opt, idx, val|
case opt
when '-l', '--list'
opts[:list] = true
end
end
if opts.empty?
opts[:list] = true
end
if opts[:list]
table = Rex::Text::Table.new(
'Header' => 'Services',
'Indent' => 1,
'Columns' => ['Id', 'Name', 'References']
)
Rex::ServiceManager.instance.each.with_index do |(name, instance), id|
# TODO: Update rex-core to support querying the reference count
table << [id, name, instance.instance_variable_get(:@_references)]
end
if table.rows.empty?
print_status("No framework services are currently running.")
else
print_line(table.to_s)
end
end
end
#
# Tab completion for the servicemanager command
#
def cmd_servicemanager_tabs(_str, words)
return [] if words.length > 1
@@servicemanager_opts.option_keys
end
def cmd_servicemanager_help
print_line 'Usage: servicemanager'
print_line
print_line 'Manage running framework services'
print @@servicemanager_opts.usage
print_line
end
#
# Time how long in seconds a command takes to execute
#