teach exploit how to parse datastore options too

GSoC/Meterpreter_Web_Console
Brent Cook 2017-09-25 08:09:39 -05:00
parent d8e5cc60bb
commit fbbfa0e0c3
2 changed files with 46 additions and 28 deletions

View File

@ -121,6 +121,7 @@ class Exploit
# #
def cmd_exploit(*args) def cmd_exploit(*args)
force = false force = false
module_opts = []
opts = { opts = {
'Encoder' => mod.datastore['ENCODER'], 'Encoder' => mod.datastore['ENCODER'],
'Payload' => mod.datastore['PAYLOAD'], 'Payload' => mod.datastore['PAYLOAD'],
@ -138,31 +139,42 @@ class Exploit
opts['RunAsJob'] = true opts['RunAsJob'] = true
end end
@@exploit_opts.parse(args) { |opt, idx, val| @@exploit_opts.parse(args) do |opt, idx, val|
case opt case opt
when '-e' when '-e'
opts['Encoder'] = val opts['Encoder'] = val
when '-f' when '-f'
force = true force = true
when '-j' when '-j'
opts['RunAsJob'] = true opts['RunAsJob'] = true
when '-J' when '-J'
opts['RunAsJob'] = false opts['RunAsJob'] = false
when '-n' when '-n'
opts['Nop'] = val opts['Nop'] = val
when '-o' when '-o'
opts['OpttionStr'] = val module_opts.push(val)
when '-p' when '-p'
opts['Payload'] = val opts['Payload'] = val
when '-t' when '-t'
opts['Target'] = val.to_i opts['Target'] = val.to_i
when '-z' when '-z'
opts['Background'] = true opts['Background'] = true
when '-h' when '-h'
cmd_exploit_help
return false
else
if val[0] != '-' && val.match?('=')
module_opts.push(val)
else
cmd_exploit_help cmd_exploit_help
return false return false
end
end end
} end
unless module_opts.empty?
opts['OptionStr'] = module_opts.join(',')
end
minrank = RankingName.invert[framework.datastore['MinimumRank']] || 0 minrank = RankingName.invert[framework.datastore['MinimumRank']] || 0
if minrank > mod.rank if minrank > mod.rank

View File

@ -20,7 +20,7 @@ module Msf
@@generate_opts = Rex::Parser::Arguments.new( @@generate_opts = Rex::Parser::Arguments.new(
"-p" => [ true, "The platform of the payload" ], "-p" => [ true, "The platform of the payload" ],
"-n" => [ true, "Prepend a nopsled of [length] size on to the payload" ], "-n" => [ true, "Prepend a nopsled of [length] size on to the payload" ],
"-f" => [ true, "Output format: #{supported_formats.join(',')}" ], "-f" => [ true, "Output format: #{@@supported_formats.join(',')}" ],
"-E" => [ false, "Force encoding" ], "-E" => [ false, "Force encoding" ],
"-e" => [ true, "The encoder to use" ], "-e" => [ true, "The encoder to use" ],
"-s" => [ true, "NOP sled length." ], "-s" => [ true, "NOP sled length." ],
@ -67,6 +67,13 @@ module Msf
"Payload" "Payload"
end end
def cmd_generate_help
print_line "Usage: generate [options]"
print_line
print_line "Generates a payload."
print @@generate_opts.usage
end
# #
# Generates a payload. # Generates a payload.
# #
@ -111,16 +118,15 @@ module Msf
when '-x' when '-x'
template = val template = val
when '-h' when '-h'
print( cmd_generate_help
"Usage: generate [options]\n\n" \ return false
"Generates a payload.\n" +
@@generate_opts.usage
)
return true
else else
(key, val) = val.split('=') (key, val) = val.split('=')
if key && val if key && val
mod.datastore[key] = val mod.datastore[key] = val
else
cmd_generate_help
return false
end end
end end
end end