Skip to content

Commit a852304

Browse files
author
Tod Beardsley
committed
DRY: Move check things to the common module level
While it makes lots of sense to bring check to all modules, of course some modules will not be able to actually use it. Namely modules like nop and payload modules. If you're feeling creative, you could probably come up with semantically similar checks for those, too.
1 parent 7436fda commit a852304

File tree

6 files changed

+44
-100
lines changed

6 files changed

+44
-100
lines changed

lib/msf/core/auxiliary.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@ 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-
5747
#
5848
# Creates a singleton instance of this auxiliary class
5949
#

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

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

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-
10060
#
10161
# Reloads an auxiliary module and executes it
10262
#

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

0 commit comments

Comments
 (0)