Skip to content

Commit b028424

Browse files
committed
Land rapid7#3752 - add "show missing"
2 parents cf13597 + 2977e8e commit b028424

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

lib/msf/base/serializer/readable_text.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,9 @@ def self.dump_generic_module(mod, indent = '')
311311
#
312312
# @param mod [Msf::Module] the module.
313313
# @param indent [String] the indentation to use.
314+
# @param missing [Boolean] dump only empty required options.
314315
# @return [String] the string form of the information.
315-
def self.dump_options(mod, indent = '')
316+
def self.dump_options(mod, indent = '', missing = false)
316317
tbl = Rex::Ui::Text::Table.new(
317318
'Indent' => indent.length,
318319
'Columns' =>
@@ -325,13 +326,13 @@ def self.dump_options(mod, indent = '')
325326

326327
mod.options.sorted.each { |entry|
327328
name, opt = entry
329+
val = mod.datastore[name] || opt.default
328330

329331
next if (opt.advanced?)
330332
next if (opt.evasion?)
333+
next if (missing && opt.valid?(val))
331334

332-
val_display = opt.display_value(mod.datastore[name] || opt.default)
333-
334-
tbl << [ name, val_display, opt.required? ? "yes" : "no", opt.desc ]
335+
tbl << [ name, opt.display_value(val), opt.required? ? "yes" : "no", opt.desc ]
335336
}
336337

337338
return tbl.to_s

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,7 @@ def cmd_show_help
20702070
global_opts = %w{all encoders nops exploits payloads auxiliary plugins options}
20712071
print_status("Valid parameters for the \"show\" command are: #{global_opts.join(", ")}")
20722072

2073-
module_opts = %w{ advanced evasion targets actions }
2073+
module_opts = %w{ missing advanced evasion targets actions }
20742074
print_status("Additional module-specific parameters are: #{module_opts.join(", ")}")
20752075
end
20762076

@@ -2113,6 +2113,12 @@ def cmd_show(*args)
21132113
else
21142114
show_global_options
21152115
end
2116+
when 'missing'
2117+
if (mod)
2118+
show_missing(mod)
2119+
else
2120+
print_error("No module selected.")
2121+
end
21162122
when 'advanced'
21172123
if (mod)
21182124
show_advanced_options(mod)
@@ -2167,7 +2173,7 @@ def cmd_show_tabs(str, words)
21672173

21682174
res = %w{all encoders nops exploits payloads auxiliary post plugins options}
21692175
if (active_module)
2170-
res.concat(%w{ advanced evasion targets actions })
2176+
res.concat(%w{ missing advanced evasion targets actions })
21712177
if (active_module.respond_to? :compatible_sessions)
21722178
res << "sessions"
21732179
end
@@ -3144,6 +3150,29 @@ def show_options(mod) # :nodoc:
31443150
#print("\nTarget: #{mod.target.name}\n\n")
31453151
end
31463152

3153+
def show_missing(mod) # :nodoc:
3154+
mod_opt = Serializer::ReadableText.dump_options(mod, ' ', true)
3155+
print("\nModule options (#{mod.fullname}):\n\n#{mod_opt}\n") if (mod_opt and mod_opt.length > 0)
3156+
3157+
# If it's an exploit and a payload is defined, create it and
3158+
# display the payload's options
3159+
if (mod.exploit? and mod.datastore['PAYLOAD'])
3160+
p = framework.payloads.create(mod.datastore['PAYLOAD'])
3161+
3162+
if (!p)
3163+
print_error("Invalid payload defined: #{mod.datastore['PAYLOAD']}\n")
3164+
return
3165+
end
3166+
3167+
p.share_datastore(mod.datastore)
3168+
3169+
if (p)
3170+
p_opt = Serializer::ReadableText.dump_options(p, ' ', true)
3171+
print("\nPayload options (#{mod.datastore['PAYLOAD']}):\n\n#{p_opt}\n") if (p_opt and p_opt.length > 0)
3172+
end
3173+
end
3174+
end
3175+
31473176
def show_global_options
31483177
columns = [ 'Option', 'Current Setting', 'Description' ]
31493178
tbl = Table.new(

msfcli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Msfcli
4444
tbl << ['(H)elp', "You're looking at it baby!"]
4545
tbl << ['(S)ummary', 'Show information about this module']
4646
tbl << ['(O)ptions', 'Show available options for this module']
47+
tbl << ['(M)issing', 'Show empty required options for this module']
4748
tbl << ['(A)dvanced', 'Show available advanced options for this module']
4849
tbl << ['(I)DS Evasion', 'Show available ids evasion options for this module']
4950
tbl << ['(P)ayloads', 'Show available payloads for this module']
@@ -385,6 +386,15 @@ class Msfcli
385386
end
386387

387388

389+
def show_missing(m)
390+
readable = Msf::Serializer::ReadableText
391+
$stdout.puts("\n" + readable.dump_options(m[:module], @indent, true))
392+
$stdout.puts("\nPayload:\n\n" + readable.dump_options(m[:payload], @indent, true)) if m[:payload]
393+
$stdout.puts("\nEncoder:\n\n" + readable.dump_options(m[:encoder], @indent, true)) if m[:encoder]
394+
$stdout.puts("\nNOP\n\n" + readable.dump_options(m[:nop], @indent, true)) if m[:nop]
395+
end
396+
397+
388398
def show_advanced(m)
389399
readable = Msf::Serializer::ReadableText
390400
$stdout.puts("\n" + readable.dump_advanced_options(m[:module], @indent))
@@ -483,6 +493,8 @@ class Msfcli
483493
show_summary(modules)
484494
when "o"
485495
show_options(modules)
496+
when "m"
497+
show_missing(modules)
486498
when "a"
487499
show_advanced(modules)
488500
when "i"

0 commit comments

Comments
 (0)