Skip to content

Commit 2d51584

Browse files
David MaloneyBrent Cook
authored andcommitted
add YARD docs to auto target methods
added YARD docs MS-2325
1 parent a61b92a commit 2d51584

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

lib/msf/core/exploit/auto_target.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
module Msf
33
module Exploit::AutoTarget
44

5+
# Checks to see if the auto-generated Automatic Targeting
6+
# has been selected. If the module had an already defined
7+
# Automatic target, then we let the module handle the targeting
8+
# itself.
9+
#
10+
# @return [Boolean] whether or not to use our automatic targeting routine
511
def auto_target?
612
selected_target = targets[target_index]
713
if selected_target.name =~ /Automatic/ && selected_target['AutoGenerated'] == true
@@ -11,6 +17,11 @@ def auto_target?
1117
end
1218
end
1319

20+
# Returns the Target Index of the automatically selected Target from
21+
# our Automatic Targeting routine.
22+
#
23+
# @return [Integer] the index of the selected Target
24+
# @return [nil] if no target could be selected
1425
def auto_targeted_index
1526
selected_target = select_target
1627
return nil if selected_target.nil?
@@ -20,6 +31,10 @@ def auto_targeted_index
2031
nil
2132
end
2233

34+
# Chooses the best possible Target for what we know about
35+
# the targeted host.
36+
#
37+
# @return [Msf::Module::Target] the Target that our automatic routine selected
2338
def select_target
2439
return nil unless auto_target?
2540
host_record = target_host
@@ -28,13 +43,22 @@ def select_target
2843
filtered_targets.first
2944
end
3045

46+
# Finds an <Mdm::Host> for the RHOST if one exists
47+
#
48+
# @return [Mdm:Host] the Host record if one exists
49+
# @return [nil] if no Host record is present, or the DB is not active
3150
def target_host
3251
return nil unless self.respond_to?(:rhost)
3352
return nil unless framework.db.active
3453
current_workspace = framework.db.find_workspace(self.workspace)
3554
current_workspace.hosts.where(address: rhost).first
3655
end
3756

57+
# Returns the best matching Targets based on the target host's
58+
# OS information. It looks at the OS Family, OS Name, and OS SP.
59+
#
60+
# @param host_record [Mdm::Host] the target host record
61+
# @return [Array<Msf::Module::Target>] an array of matching targets
3862
def filter_by_os(host_record)
3963
filtered_by_family = filter_by_os_family(host_record)
4064
filtered_by_name = filter_by_os_name(filtered_by_family, host_record)
@@ -46,6 +70,11 @@ def filter_by_os(host_record)
4670
filtered_by_sp
4771
end
4872

73+
# Returns all Targets that match the target host's OS Family
74+
# e.g Windows, Linux, OS X, etc
75+
#
76+
# @param host_record [Mdm::Host] the target host record
77+
# @return [Array<Msf::Module::Target>] an array of matching targets
4978
def filter_by_os_family(host_record)
5079
return [] if host_record.os_family.blank?
5180
filtered_targets = targets.collect do |target|
@@ -58,6 +87,12 @@ def filter_by_os_family(host_record)
5887
filtered_targets.compact
5988
end
6089

90+
# Returns all Targets that match the target host's OS Name
91+
# e.g Windows 7, Windows XP, Windows Vista, etc
92+
#
93+
# @param potential_targets [Array<Msf::Module::Target>] the filtered targets that we wish to filter further
94+
# @param host_record [Mdm::Host] the target host record
95+
# @return [Array<Msf::Module::Target>] an array of matching targets
6196
def filter_by_os_name(potential_targets, host_record)
6297
return [] if host_record.os_name.blank?
6398
filtered_targets = []
@@ -67,6 +102,11 @@ def filter_by_os_name(potential_targets, host_record)
67102
filtered_targets
68103
end
69104

105+
# Returns all Targets that match the target host's OS SP
106+
#
107+
# @param potential_targets [Array<Msf::Module::Target>] the filtered targets that we wish to filter further
108+
# @param host_record [Mdm::Host] the target host record
109+
# @return [Array<Msf::Module::Target>] an array of matching targets
70110
def filter_by_os_sp(potential_targets, host_record)
71111
return [] if host_record.os_sp.blank?
72112
filtered_targets = []

0 commit comments

Comments
 (0)