Reintroduces chao-mu's OptRegexp

Revert "Revert "Merge pull request #101 from chao-mu/master""

[See #101]

This reverts commit c5ce575543.
unstable
Tod Beardsley 2012-01-23 12:25:52 -06:00 committed by James Lee
parent a328bb21f1
commit f6b951ac36
3 changed files with 57 additions and 10 deletions

View File

@ -312,9 +312,9 @@ class ReadableText
next if (opt.advanced?)
next if (opt.evasion?)
val = mod.datastore[name] || opt.default.to_s
val_display = opt.display_value(mod.datastore[name] || opt.default)
tbl << [ name, val.to_s, opt.required? ? "yes" : "no", opt.desc ]
tbl << [ name, val_display, opt.required? ? "yes" : "no", opt.desc ]
}
return tbl.to_s

View File

@ -81,6 +81,13 @@ class OptBase
value
end
#
# Returns a string representing a user-friendly display of the chosen value
#
def display_value(value)
value.to_s
end
#
# The name of the option.
#
@ -137,6 +144,7 @@ end
# OptEnum - Select from a set of valid values
# OptAddressRange - A subnet or range of addresses
# OptSession - A session identifier
# OptRegexp - Valid Ruby regular expression
#
###
@ -440,6 +448,44 @@ class OptInt < OptBase
end
end
###
#
# Regexp option
#
###
class OptRegexp < OptBase
def type
return 'regexp'
end
def valid?(value)
unless super
return false
end
begin
Regexp.compile(value)
return true
rescue RegexpError => e
return false
end
end
def normalize(value)
return Regexp.compile(value)
end
def display_value(value)
if value.kind_of?(Regexp)
return value.source
elsif value.kind_of?(String)
return display_value(normalize(value))
end
return super
end
end
###
#

View File

@ -1,4 +1,3 @@
##
# $Id$
##
@ -12,9 +11,12 @@
require 'msf/core'
require 'rex'
require 'msf/core/post/windows/railgun'
class Metasploit3 < Msf::Post
include Msf::Post::Windows::Railgun
def initialize(info={})
super( update_info( info,
'Name' => 'railgun_testing',
@ -28,26 +30,25 @@ class Metasploit3 < Msf::Post
[
OptInt.new("ERR_CODE" , [true, "Error code to reverse lookup", 0x420]),
OptInt.new("WIN_CONST", [true, "Windows constant to reverse lookup", 4]),
OptString.new("WCREGEX", [false,"Regexp to apply to constant rev lookup", "^SERVICE"]),
OptString.new("ECREGEX", [false,"Regexp to apply to error code lookup", "^ERROR_SERVICE_"]),
OptRegexp.new("WCREGEX", [false,"Regexp to apply to constant rev lookup", '^SERVICE']),
OptRegexp.new("ECREGEX", [false,"Regexp to apply to error code lookup", '^ERROR_SERVICE_']),
], self.class)
end
def run
print_debug datastore['ECREGEX']
print_status("Running against session #{datastore["SESSION"]}")
print_status("Session type is #{session.type}")
@rg = session.railgun
print_status()
print_status("TESTING: const_reverse_lookup on #{datastore['WIN_CONST']} filtering by #{datastore['WCREGEX'].to_s}")
results = @rg.const_reverse_lookup(datastore['WIN_CONST'],datastore['WCREGEX'])
print_status("TESTING: select_const_names on #{datastore['WIN_CONST']} filtering by #{datastore['WCREGEX'].to_s}")
results = select_const_names(datastore['WIN_CONST'],datastore['WCREGEX'])
print_status("RESULTS: #{results.class} #{results.pretty_inspect}")
print_status()
print_status("TESTING: error_lookup on #{datastore['ERR_CODE']} filtering by #{datastore['ECREGEX'].to_s}")
results = @rg.error_lookup(datastore['ERR_CODE'],datastore['ECREGEX'])
results = lookup_error(datastore['ERR_CODE'],datastore['ECREGEX'])
print_status("RESULTS: #{results.class} #{results.inspect}")
print_status()