2
2
module Msf
3
3
module Exploit ::AutoTarget
4
4
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
5
11
def auto_target?
6
12
selected_target = targets [ target_index ]
7
13
if selected_target . name =~ /Automatic/ && selected_target [ 'AutoGenerated' ] == true
@@ -11,6 +17,11 @@ def auto_target?
11
17
end
12
18
end
13
19
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
14
25
def auto_targeted_index
15
26
selected_target = select_target
16
27
return nil if selected_target . nil?
@@ -20,6 +31,10 @@ def auto_targeted_index
20
31
nil
21
32
end
22
33
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
23
38
def select_target
24
39
return nil unless auto_target?
25
40
host_record = target_host
@@ -28,13 +43,22 @@ def select_target
28
43
filtered_targets . first
29
44
end
30
45
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
31
50
def target_host
32
51
return nil unless self . respond_to? ( :rhost )
33
52
return nil unless framework . db . active
34
53
current_workspace = framework . db . find_workspace ( self . workspace )
35
54
current_workspace . hosts . where ( address : rhost ) . first
36
55
end
37
56
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
38
62
def filter_by_os ( host_record )
39
63
filtered_by_family = filter_by_os_family ( host_record )
40
64
filtered_by_name = filter_by_os_name ( filtered_by_family , host_record )
@@ -46,6 +70,11 @@ def filter_by_os(host_record)
46
70
filtered_by_sp
47
71
end
48
72
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
49
78
def filter_by_os_family ( host_record )
50
79
return [ ] if host_record . os_family . blank?
51
80
filtered_targets = targets . collect do |target |
@@ -58,6 +87,12 @@ def filter_by_os_family(host_record)
58
87
filtered_targets . compact
59
88
end
60
89
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
61
96
def filter_by_os_name ( potential_targets , host_record )
62
97
return [ ] if host_record . os_name . blank?
63
98
filtered_targets = [ ]
@@ -67,6 +102,11 @@ def filter_by_os_name(potential_targets, host_record)
67
102
filtered_targets
68
103
end
69
104
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
70
110
def filter_by_os_sp ( potential_targets , host_record )
71
111
return [ ] if host_record . os_sp . blank?
72
112
filtered_targets = [ ]
0 commit comments