Add and use a callback to report meterpreter commands that are disabled

This commit is contained in:
Spencer McIntyre 2021-01-14 15:09:32 -05:00 committed by Grant Willcox
parent b983365665
commit a587c166cb
No known key found for this signature in database
GPG Key ID: D35E05C0F2B81E83
2 changed files with 25 additions and 1 deletions

View File

@ -38,6 +38,7 @@ module Console::CommandDispatcher
def initialize(shell)
@msf_loaded = nil
@filtered_commands = []
super
end
@ -53,10 +54,22 @@ module Console::CommandDispatcher
#
def filter_commands(all, reqs)
all.delete_if do |cmd, _desc|
reqs[cmd]&.any? { |req| !client.commands.include?(req) }
if reqs[cmd]&.any? { |req| !client.commands.include?(req) }
@filtered_commands << cmd
true
end
end
end
def unknown_command(cmd, line)
if @filtered_commands.include?(cmd)
print_error("The '#{cmd}' command is not supported by this Meterpreter type (#{client.session_type})")
return true
end
super
end
#
# Return the subdir of the `documentation/` directory that should be used
# to find usage documentation

View File

@ -328,6 +328,15 @@ module DispatcherShell
end
addresses
end
#
# A callback that can be used to handle unknown commands. This can for example, allow a dispatcher to mark a command
# as being disabled.
#
# @return [Boolean] Returns true when the dispatcher has handled the command.
def unknown_command(method, line)
false
end
end
#
@ -474,6 +483,8 @@ module DispatcherShell
self.on_command_proc.call(line.strip) if self.on_command_proc
run_command(dispatcher, method, arguments)
found = true
elsif dispatcher.unknown_command(method, line)
found = true
end
rescue ::Interrupt
found = true