1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-09-11 17:08:02 +02:00

add a module for testing services, update some tests for registry, cleanup some comments for rdoc compat, and add a ParseError exception class. see #3745

git-svn-id: file:///home/svn/framework3/trunk@13739 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
James Lee 2011-09-16 20:32:22 +00:00
parent 2ebef435a0
commit 58880d3457
2 changed files with 189 additions and 28 deletions

View File

@ -20,8 +20,8 @@ class Metasploit3 < Msf::Post
def initialize(info={})
super( update_info( info,
'Name' => 'test',
'Description' => %q{ This module will test registry stuff },
'Name' => 'registry_post_testing',
'Description' => %q{ This module will test registry code used in post modules},
'License' => MSF_LICENSE,
'Author' => [ 'kernelsmith'],
'Version' => '$Revision$',
@ -37,50 +37,97 @@ class Metasploit3 < Msf::Post
def run
print_status("Running against session #{datastore["SESSION"]}")
print_status("Session type is #{session.type}")
print_status "testing get_val_info for key:#{datastore['KEY']}, val:#{datastore['VALUE']}"
print_status()
print_status("TESTING: registry_value_exist? for key:#{datastore['KEY']}, val:#{datastore['VALUE']}")
results = registry_value_exist?(datastore['KEY'],datastore['VALUE'])
print_status("RESULTS: #{results.class} #{results.inspect}")
print_status()
print_status("TESTING: registry_value_exist? for key:#{'HKLM\\Non\Existent\key'}, val:#{datastore['VALUE']}")
results = registry_value_exist?('HKLM\\Non\Existent\key',datastore['VALUE'])
print_status("RESULTS (Expecting false): #{results.class} #{results.inspect}")
print_status()
print_status("TESTING: registry_value_exist? for key:#{datastore['KEY']}, val:'NonExistentValue'")
results = registry_value_exist?(datastore['KEY'],'NonExistentValue')
print_status("RESULTS (Expecting false): #{results.class} #{results.inspect}")
print_status()
print_status("TESTING: registry_key_exist? for key: 'HKLM\\Non\Existent\key'")
results = registry_key_exist?('HKLM\\Non\Existent\key') # need to error handle this properly in meterp ver
print_status("RESULTS (Expecting false): #{results.class} #{results.inspect}")
print_status()
print_status("TESTING: registry_key_exist? for key:#{datastore['KEY']}")
results = registry_key_exist?(datastore['KEY'])
print_status("RESULTS: #{results.class} #{results.inspect}")
print_status()
print_status("TESTING: registry_getvalinfo for key:#{datastore['KEY']}, val:#{datastore['VALUE']}")
results = registry_getvalinfo(datastore['KEY'], datastore['VALUE'])
print_status("results: #{results.class} #{results.inspect}")
print_status "testing get_val_data for key:#{datastore['KEY']}, val:#{datastore['VALUE']}"
print_error("reported failure") unless results
print_status("RESULTS: #{results.class} #{results.inspect}")
print_status()
print_status("TESTING: registry_getvaldata for key:#{datastore['KEY']}, val:#{datastore['VALUE']}")
results = registry_getvaldata(datastore['KEY'], datastore['VALUE'])
print_status("results: #{results.class} #{results.inspect}")
print_error("reported failure") unless results
print_status("RESULTS: #{results.class} #{results.inspect}")
print_status "testing create_key for key:#{datastore['KEY']}\\test"
print_status()
print_status("TESTING: registry_createkey for key:#{datastore['KEY']}\\test")
results = registry_createkey("#{datastore['KEY']}\\test")
print_status("results: #{results.class} #{results.inspect}")
print_error("reported failure") if results
print_status("RESULTS: #{results.class} #{results.inspect}")
print_status "testing set_val_data for key:#{datastore['KEY']}\\test, val:test, data:test, type:REG_SZ"
print_status()
print_status("TESTING: registry_setvaldata for key:#{datastore['KEY']}\\test, val:test, data:test, type:REG_SZ")
results = registry_setvaldata("#{datastore['KEY']}\\test", "test", "test", "REG_SZ")
print_status("results: #{results.class} #{results.inspect}")
print_error("reported failure") if results
print_status("RESULTS: #{results.class} #{results.inspect}")
print_status "getting newly created val_info for key:#{datastore['KEY']}\\test, val:test"
print_status()
print_status("Running registry_getvalinfo for freshly created key:#{datastore['KEY']}\\test, val:test")
results = registry_getvalinfo("#{datastore['KEY']}\\test", "test")
print_status("results: #{results.class} #{results.inspect}")
print_error("reported failure") unless results
print_status("RESULTS: #{results.class} #{results.inspect}")
print_status "testing del_val_data for key:#{datastore['KEY']}\\test, val:test"
print_status()
print_status("TESTING: registry_deleteval for key:#{datastore['KEY']}\\test, val:test")
results = registry_deleteval("#{datastore['KEY']}\\test", "test")
print_errror("registry_deleteval reported failure") unless results
print_status("results: #{results.class} #{results.inspect}")
print_error("reported failure") if results
print_status("RESULTS: #{results.class} #{results.inspect}")
print_status "testing del_key"
print_status()
print_status("TESTING: registry_deletekey")
results = registry_deletekey("#{datastore['KEY']}\\test")
print_status("results: #{results.class} #{results.inspect}")
print_error("reported failure") if results
print_status("RESULTS: #{results.class} #{results.inspect}")
print_status "getting deleted val_info for key:#{datastore['KEY']}\\test, val:test, this should return nils"
print_status()
print_status("Running registry_getvalinfo for deleted key:#{datastore['KEY']}\\test, val:test")
print_status("NOTE: this OUGHT to return nil")
results = registry_getvalinfo("#{datastore['KEY']}\\test", "test")
if (results.nil?)
print_status("Delete worked correctly")
else
print_error("Deleted key is still there!")
end
print_status "testing enum_keys"
print_status("RESULTS (Expecting nil): #{results.class} #{results.inspect}")
print_error("reported failure") if results
print_status("nil is correct. sweet.") if !results
print_status()
print_status("TESTING: registry_enumkeys")
results = registry_enumkeys(datastore['KEY'])
print_status("results: #{results.class} #{results.inspect}")
print_error("reported failure") unless results
print_status("RESULTS: #{results.class} #{results.inspect}")
print_status "testing enum_vals"
print_status()
print_status("TESTING: registry_enumvals")
results = registry_enumvals(datastore['KEY'])
print_status("results: #{results.class} #{results.inspect}")
print_error("reported failure") unless results
print_status("RESULTS: #{results.class} #{results.inspect}")
print_status()
print_status("Testing Complete!")
end

View File

@ -0,0 +1,114 @@
#
# by kernelsmith (kernelsmith+\x40+kernelsmith+\.com)
#
require 'msf/core'
require 'rex'
require 'msf/core/post/windows/services'
class Metasploit3 < Msf::Post
include Msf::Post::Windows::WindowsServices
def initialize(info={})
super( update_info( info,
'Name' => 'services_post_testing',
'Description' => %q{ This module will test windows services methods within a shell},
'License' => MSF_LICENSE,
'Author' => [ 'kernelsmith'],
'Version' => '$Revision: 11663 $',
'Platform' => [ 'windows' ],
'SessionTypes' => [ 'shell' ]
))
register_options(
[
OptBool.new("VERBOSE" , [true, "Verbose test, shows service status after each test", false]),
OptString.new("QSERVICE" , [true, "Service (keyname) to query", "winmgmt"]),
OptString.new("NSERVICE" , [true, "New Service (keyname) to create/del", "testes"]),
OptString.new("SSERVICE" , [true, "Service (keyname) to start/stop", "W32Time"]),
OptString.new("MODE" , [true, "Mode to use for startup/create tests", "demand"]),
OptString.new("DNAME" , [true, "Display name used for create test", "Cool display name"]),
OptString.new("BINPATH" , [true, "Binary path for create test", "C:\\WINDOWS\\system32\\svchost.exe -k netsvcs"]),
], self.class)
end
def run
blab = datastore['VERBOSE']
print_status("Running against session #{datastore["SESSION"]}")
print_status("Session type is #{session.type}")
print_status("Verbosity is set to #{blab.to_s}")
print_status("Don't be surprised to see some errors as the script is faster")
print_line("than the windows SCM, just make sure the errors are sane. You can")
print_line("set VERBOSE to true to see more details")
print_status()
print_status("TESTING service_list")
results = service_list
print_status("RESULTS: #{results.class} #{results.pretty_inspect}")
print_status()
print_status("TESTING service_list_running")
results = service_list_running
print_status("RESULTS: #{results.class} #{results.pretty_inspect}")
print_status()
print_status("TESTING service_info on servicename: #{datastore["QSERVICE"]}")
results = service_info(datastore['QSERVICE'])
print_status("RESULTS: #{results.class} #{results.pretty_inspect}")
print_status()
print_status("TESTING service_query_ex on servicename: #{datastore["QSERVICE"]}")
results = service_query_ex(datastore['QSERVICE'])
print_status("RESULTS: #{results.class} #{results.pretty_inspect}")
print_status()
print_status("TESTING service_query_config on servicename: #{datastore["QSERVICE"]}")
results = service_query_config(datastore['QSERVICE'])
print_status("RESULTS: #{results.class} #{results.pretty_inspect}")
print_status()
print_status("TESTING service_change_startup on servicename: #{datastore['QSERVICE']} " +
"to #{datastore['MODE']}")
results = service_change_startup(datastore['QSERVICE'],datastore['MODE'])
print_status("RESULTS: #{results.class} #{results.pretty_inspect}")
print_status("Current status of this service " +
"#{service_query_ex(datastore['QSERVICE']).pretty_inspect}") if blab
print_status()
print_status("TESTING service_create on servicename: #{datastore['NSERVICE']} using\n" +
"display_name: #{datastore['DNAME']}, executable_on_host: " +
"#{datastore['BINPATH']}, and startupmode: #{datastore['MODE']}")
results = service_create(datastore['NSERVICE'],datastore['DNAME'],datastore['BINPATH'],datastore['MODE'])
print_status("RESULTS: #{results.class} #{results.pretty_inspect}")
print_status("Current status of this service " +
"#{service_query_ex(datastore['QSERVICE']).pretty_inspect}") if blab
print_status()
print_status("TESTING service_start on servicename: #{datastore['SSERVICE']}")
results = service_start(datastore['SSERVICE'])
print_status("RESULTS: #{results.class} #{results.pretty_inspect}")
print_status("Current status of this service " +
"#{service_query_ex(datastore['SSERVICE']).pretty_inspect}") if blab
print_status("Sleeping to give the service a chance to start")
select(nil, nil, nil, 2) # give the service time to start, reduces false negatives
print_status()
print_status("TESTING service_stop on servicename: #{datastore['SSERVICE']}")
results = service_stop(datastore['SSERVICE'])
print_status("RESULTS: #{results.class} #{results.pretty_inspect}")
print_status("Current status of this service " +
"#{service_query_ex(datastore['SSERVICE']).pretty_inspect}") if blab
print_status()
print_status("TESTING service_delete on servicename: #{datastore['NSERVICE']}")
results = service_delete(datastore['NSERVICE'])
print_status("RESULTS: #{results.class} #{results.pretty_inspect}")
print_status("Current status of this service " +
"#{service_query_ex(datastore['QSERVICE']).pretty_inspect}") if blab
print_status()
print_status("Testing complete.")
end
end