Skip to content

Commit 7436fda

Browse files
author
Tod Beardsley
committed
First, copy-pasta and add a test
1 parent bfcd860 commit 7436fda

File tree

5 files changed

+137
-0
lines changed

5 files changed

+137
-0
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/auxiliary.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ def initialize(info = {})
4444
self.queue = Array.new
4545
end
4646

47+
#
48+
# Checks to see if the target is vulnerable, returning unsupported if it's
49+
# not supported.
50+
#
51+
# This method is designed to be overriden by exploit modules.
52+
#
53+
def check
54+
Msf::Exploit::CheckCode::Unsupported
55+
end
56+
4757
#
4858
# Creates a singleton instance of this auxiliary class
4959
#

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Auxiliary
2727
#
2828
def commands
2929
super.update({
30+
"check" => "Check to see if a target is vulnerable",
3031
"run" => "Launches the auxiliary module",
3132
"rerun" => "Reloads and launches the auxiliary module",
3233
"exploit" => "This is an alias for the run command",
@@ -57,6 +58,45 @@ def name
5758
"Auxiliary"
5859
end
5960

61+
#
62+
# Checks to see if a target is vulnerable.
63+
#
64+
def cmd_check(*args)
65+
defanged?
66+
67+
begin
68+
69+
code = mod.check_simple(
70+
'LocalInput' => driver.input,
71+
'LocalOutput' => driver.output)
72+
73+
if (code and code.kind_of?(Array) and code.length > 1)
74+
75+
if (code == Msf::Exploit::CheckCode::Vulnerable)
76+
print_good(code[1])
77+
else
78+
print_status(code[1])
79+
end
80+
81+
else
82+
print_error("Check failed: The state could not be determined.")
83+
end
84+
85+
rescue ::Interrupt
86+
raise $!
87+
rescue ::Exception => e
88+
print_error("Module check failed: #{e.class} #{e}")
89+
if(e.class.to_s != 'Msf::OptionValidateError')
90+
print_error("Call stack:")
91+
e.backtrace.each do |line|
92+
break if line =~ /lib.msf.base.simple/
93+
print_error(" #{line}")
94+
end
95+
end
96+
end
97+
end
98+
99+
60100
#
61101
# Reloads an auxiliary module and executes it
62102
#

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/scripts/test-check.rc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+
exit

0 commit comments

Comments
 (0)