Skip to content

Commit cd947e2

Browse files
committed
Landing rapid7#1861 - Implement check for auxiliary modules
[FixRM:rapid7#7975]
2 parents 3a550ae + eeea1d9 commit cd947e2

File tree

8 files changed

+179
-50
lines changed

8 files changed

+179
-50
lines changed

lib/msf/base/simple/auxiliary.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,39 @@ def run_simple(opts = {}, &block)
9292
Msf::Simple::Auxiliary.run_simple(self, opts, &block)
9393
end
9494

95+
#
96+
# Initiates a check, setting up the exploit to be used. The following
97+
# options can be specified:
98+
#
99+
# LocalInput
100+
#
101+
# The local input handle that data can be read in from.
102+
#
103+
# LocalOutput
104+
#
105+
# The local output through which data can be displayed.
106+
#
107+
def self.check_simple(mod, opts)
108+
if opts['LocalInput']
109+
mod.init_ui(opts['LocalInput'], opts['LocalOutput'])
110+
end
111+
112+
# Validate the option container state so that options will
113+
# be normalized
114+
mod.validate
115+
116+
# Run check
117+
mod.check
118+
end
119+
120+
#
121+
# Calls the class method.
122+
#
123+
def check_simple(opts)
124+
Msf::Simple::Auxiliary.check_simple(self, opts)
125+
end
126+
127+
95128
protected
96129

97130
#

lib/msf/core/exploit.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -415,16 +415,6 @@ def initialize(info = {})
415415
#
416416
##
417417

418-
#
419-
# Checks to see if the target is vulnerable, returning unsupported if it's
420-
# not supported.
421-
#
422-
# This method is designed to be overriden by exploit modules.
423-
#
424-
def check
425-
CheckCode::Unsupported
426-
end
427-
428418
#
429419
# Kicks off the actual exploit. Prior to this call, the framework will
430420
# have validated the data store using the options associated with this

lib/msf/core/module.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,16 @@ def disclosure_date
355355
date_str = Date.parse(module_info['DisclosureDate'].to_s) rescue nil
356356
end
357357

358+
#
359+
# Checks to see if the target is vulnerable, returning unsupported if it's
360+
# not supported.
361+
#
362+
# This method is designed to be overriden by exploit modules.
363+
#
364+
def check
365+
Msf::Exploit::CheckCode::Unsupported
366+
end
367+
358368
#
359369
# Returns the hash that describes this module's compatibilities.
360370
#

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class Exploit
2929
#
3030
def commands
3131
super.update({
32-
"check" => "Check to see if a target is vulnerable",
3332
"exploit" => "Launch an exploit attempt",
3433
"rcheck" => "Reloads the module and checks if the target is vulnerable",
3534
"rexploit" => "Reloads the module and launches an exploit attempt",
@@ -46,44 +45,6 @@ def name
4645
"Exploit"
4746
end
4847

49-
#
50-
# Checks to see if a target is vulnerable.
51-
#
52-
def cmd_check(*args)
53-
defanged?
54-
55-
begin
56-
57-
code = mod.check_simple(
58-
'LocalInput' => driver.input,
59-
'LocalOutput' => driver.output)
60-
61-
if (code and code.kind_of?(Array) and code.length > 1)
62-
63-
if (code == Msf::Exploit::CheckCode::Vulnerable)
64-
print_good(code[1])
65-
else
66-
print_status(code[1])
67-
end
68-
69-
else
70-
print_error("Check failed: The state could not be determined.")
71-
end
72-
73-
rescue ::Interrupt
74-
raise $!
75-
rescue ::Exception => e
76-
print_error("Exploit check failed: #{e.class} #{e}")
77-
if(e.class.to_s != 'Msf::OptionValidateError')
78-
print_error("Call stack:")
79-
e.backtrace.each do |line|
80-
break if line =~ /lib.msf.base.simple/
81-
print_error(" #{line}")
82-
end
83-
end
84-
end
85-
end
86-
8748
#
8849
# Launches an exploitation attempt.
8950
#

lib/msf/ui/console/module_command_dispatcher.rb

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module ModuleCommandDispatcher
1717
def commands
1818
{
1919
"pry" => "Open a Pry session on the current module",
20-
"reload" => "Reload the current module from disk"
20+
"reload" => "Reload the current module from disk",
21+
"check" => "Check to see if a target is vulnerable"
2122
}
2223
end
2324

@@ -35,6 +36,38 @@ def mod=(m)
3536
self.driver.active_module = m
3637
end
3738

39+
#
40+
# Checks to see if a target is vulnerable.
41+
#
42+
def cmd_check(*args)
43+
defanged?
44+
begin
45+
code = mod.check_simple(
46+
'LocalInput' => driver.input,
47+
'LocalOutput' => driver.output)
48+
if (code and code.kind_of?(Array) and code.length > 1)
49+
if (code == Msf::Exploit::CheckCode::Vulnerable)
50+
print_good(code[1])
51+
else
52+
print_status(code[1])
53+
end
54+
else
55+
print_error("Check failed: The state could not be determined.")
56+
end
57+
rescue ::Interrupt
58+
raise $!
59+
rescue ::Exception => e
60+
print_error("Exploit check failed: #{e.class} #{e}")
61+
if(e.class.to_s != 'Msf::OptionValidateError')
62+
print_error("Call stack:")
63+
e.backtrace.each do |line|
64+
break if line =~ /lib.msf.base.simple/
65+
print_error(" #{line}")
66+
end
67+
end
68+
end
69+
end
70+
3871
def cmd_pry_help
3972
print_line "Usage: pry"
4073
print_line

test/modules/auxiliary/test/check.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# Framework web site for more information on licensing and terms of use.
5+
# http://metasploit.com/framework/
6+
##
7+
8+
require 'msf/core'
9+
10+
class Metasploit3 < Msf::Auxiliary
11+
12+
include Msf::Auxiliary::Report
13+
include Msf::Exploit::Remote::HttpClient
14+
15+
def initialize(info = {})
16+
super(update_info(info,
17+
'Name' => "Check Test",
18+
'Description' => %q{
19+
This module ensures that 'check' actually functions for Auxiilary modules.
20+
},
21+
'References' =>
22+
[
23+
[ 'OSVDB', '0' ]
24+
],
25+
'Author' =>
26+
[
27+
'todb'
28+
],
29+
'License' => MSF_LICENSE
30+
))
31+
32+
register_options(
33+
[
34+
Opt::RPORT(80)
35+
], self.class)
36+
end
37+
38+
def check
39+
print_debug "Check is successful"
40+
return Msf::Exploit::CheckCode::Vulnerable
41+
end
42+
43+
def run
44+
print_debug "Run is successful."
45+
end
46+
47+
end

test/modules/exploits/test/check.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# Framework web site for more information on licensing and terms of use.
5+
# http://metasploit.com/framework/
6+
##
7+
8+
require 'msf/core'
9+
10+
class Metasploit3 < Msf::Exploit
11+
12+
def initialize(info = {})
13+
super(update_info(info,
14+
'Name' => "Check Test Exploit",
15+
'Description' => %q{
16+
This module ensures that 'check' actually functions for Exploit modules.
17+
},
18+
'References' =>
19+
[
20+
[ 'OSVDB', '0' ]
21+
],
22+
'Author' =>
23+
[
24+
'todb'
25+
],
26+
'License' => MSF_LICENSE,
27+
'DisclosureDate' => 'May 23 2013'
28+
))
29+
30+
register_options(
31+
[
32+
Opt::RPORT(80)
33+
], self.class)
34+
end
35+
36+
def check
37+
print_debug "Check is successful"
38+
return Msf::Exploit::CheckCode::Vulnerable
39+
end
40+
41+
def exploit
42+
print_debug "Exploit is successful."
43+
end
44+
45+
end

test/scripts/test-check.rc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Usage:
2+
# msfconsole -qLm test/modules -r test/scripts/test-check.rc
3+
4+
use auxiliary/test/check
5+
set rhost www.metasploit.com
6+
check
7+
8+
use exploit/test/check
9+
set rhost www.metasploit.com
10+
check

0 commit comments

Comments
 (0)