Replace some unnecessary eval action.

Metaprogramming should be reserved for when you don't know things. Here
we're making methods from literal strings, so replace the
metaprogramming with much easier to understand regular programming. Also
has the benefit that yard can parse it.
bug/bundler_fix
James Lee 2015-04-03 23:28:45 -05:00
parent 2a3ed890d2
commit da0e7282d5
No known key found for this signature in database
GPG Key ID: 2D6094C7CEA0A321
1 changed files with 64 additions and 38 deletions

View File

@ -2,47 +2,73 @@
module Msf module Msf
# #
# Builtin framework options with shortcut methods # Builtin framework options with shortcut methods
# #
module Opt # @example
# register_options(
# [
# Opt::RHOST,
# Opt::RPORT(21),
# ]
# )
# register_advanced_options([Opt::Proxies])
#
module Opt
@@builtin_opts = # @return [OptAddress]
{ def self.CHOST(default=nil, required=false, desc="The local client address")
'RHOST' => [ Msf::OptAddress, 'nil', true, '"The target address"' ], Msf::OptAddress.new(__method__.to_s, [ required, desc, default ])
'RPORT' => [ Msf::OptPort, 'nil', true, '"The target port"' ], end
'LHOST' => [ Msf::OptAddress, 'nil', true, '"The listen address"' ],
'LPORT' => [ Msf::OptPort, 'nil', true, '"The listen port"' ],
'CPORT' => [ Msf::OptPort, 'nil', false, '"The local client port"' ],
'CHOST' => [ Msf::OptAddress, 'nil', false, '"The local client address"' ],
'Proxies' => [ Msf::OptString, 'nil', 'false', '"A proxy chain of format type:host:port[,type:host:port][...]"']
}
# # @return [OptPort]
# Build the builtin_xyz methods on the fly using the type information for each def self.CPORT(default=nil, required=false, desc="The local client port")
# of the builtin framework options, such as RHOST. Msf::OptPort.new(__method__.to_s, [ required, desc, default ])
# end
class <<self
@@builtin_opts.each_pair { |opt, info|
eval(
"
def builtin_#{opt.downcase}(default = #{info[1]}, required = #{info[2]}, desc = #{info[3]})
#{info[0]}.new('#{opt}', [ required, desc, default ])
end
alias #{opt} builtin_#{opt.downcase} # @return [OptAddress]
") def self.LHOST(default=nil, required=true, desc="The listen address")
} Msf::OptAddress.new(__method__.to_s, [ required, desc, default ])
end end
# # @return [OptPort]
# Define the constant versions of the options which are merely redirections to def self.LPORT(default=nil, required=true, desc="The listen port")
# the class methods. Msf::OptPort.new(__method__.to_s, [ required, desc, default ])
# end
@@builtin_opts.each_pair { |opt, info|
eval("#{opt} = Msf::Opt::builtin_#{opt.downcase}") # @return [OptString]
} def self.Proxies(default=nil, required=false, desc="A proxy chain of format type:host:port[,type:host:port][...]")
Msf::OptString.new(__method__.to_s, [ required, desc, default ])
end end
# @return [OptAddress]
def self.RHOST(default=nil, required=true, desc="The target address")
Msf::OptAddress.new(__method__.to_s, [ required, desc, default ])
end
# @return [OptPort]
def self.RPORT(default=nil, required=true, desc="The target port")
Msf::OptPort.new(__method__.to_s, [ required, desc, default ])
end
# These are unused but remain for historical reasons
class << self
alias builtin_chost CHOST
alias builtin_cport CPORT
alias builtin_lhost LHOST
alias builtin_lport LPORT
alias builtin_proxies Proxies
alias builtin_rhost RHOST
alias builtin_rport RPORT
end
CHOST = CHOST()
CPORT = CPORT()
LHOST = LHOST()
LPORT = LPORT()
Proxies = Proxies()
RHOST = RHOST()
RPORT = RPORT()
end
end end