CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/core/auxiliary.rb
Views: 11780
1
# -*- coding: binary -*-
2
3
module Msf
4
5
###
6
#
7
# The auxiliary class acts as a base class for all modules that perform
8
# reconnaissance, retrieve data, brute force logins, or any other action
9
# that doesn't fit our concept of an 'exploit' (involving payloads and
10
# targets and whatnot).
11
#
12
###
13
class Auxiliary < Msf::Module
14
15
class Complete < RuntimeError
16
end
17
18
class Failed < RuntimeError
19
end
20
21
22
include HasActions
23
24
#
25
# Returns MODULE_AUX to indicate that this is an auxiliary module.
26
#
27
def self.type
28
Msf::MODULE_AUX
29
end
30
31
#
32
# Returns MODULE_AUX to indicate that this is an auxiliary module.
33
#
34
def type
35
Msf::MODULE_AUX
36
end
37
38
#
39
# Creates an instance of the auxiliary module.
40
#
41
def initialize(info = {})
42
43
# Call the parent constructor after making any necessary modifications
44
# to the information hash.
45
super(info)
46
47
self.sockets = Array.new
48
self.queue = Array.new
49
end
50
51
#
52
# Creates a singleton instance of this auxiliary class
53
#
54
def self.create(info = {})
55
return @@aux_singleton if @@aux_singleton
56
@@aux_singleton = self.new(info)
57
end
58
59
def run
60
print_status("Running the default Auxiliary handler")
61
end
62
63
def auxiliary_commands
64
return { }
65
end
66
67
#
68
# Performs last-minute sanity checking of auxiliary parameters. This method
69
# is called during automated exploitation attempts and allows an
70
# auxiliary module to filter bad attempts, obtain more information, and choose
71
# better parameters based on the available data. Returning anything that
72
# evaluates to "false" will cause this specific auxiliary attempt to
73
# be skipped. This method can and will change datastore values and
74
# may interact with the backend database. The default value for auxiliary
75
# modules is false, since not all auxiliary modules actually attempt
76
# to exploit a vulnerability.
77
#
78
def autofilter
79
false
80
end
81
82
#
83
# Provides a list of ports that can be used for matching this module
84
# against target systems.
85
#
86
def autofilter_ports
87
@autofilter_ports || []
88
end
89
90
#
91
# Provides a list of services that can be used for matching this module
92
# against target systems.
93
#
94
def autofilter_services
95
@autofilter_services || []
96
end
97
98
#
99
# Adds a port into the list of ports
100
#
101
def register_autofilter_ports(ports=[])
102
@autofilter_ports ||= []
103
@autofilter_ports << ports
104
@autofilter_ports.flatten!
105
@autofilter_ports.uniq!
106
end
107
108
def register_autofilter_services(services=[])
109
@autofilter_services ||= []
110
@autofilter_services << services
111
@autofilter_services.flatten!
112
@autofilter_services.uniq!
113
end
114
115
116
#
117
# Called directly before 'run'
118
#
119
def setup
120
alert_user
121
end
122
123
#
124
# Called after 'run' returns
125
#
126
def cleanup
127
abort_sockets()
128
end
129
130
#
131
# Adds a socket to the list of sockets opened by this exploit.
132
#
133
def add_socket(sock)
134
self.sockets << sock
135
end
136
137
#
138
# Removes a socket from the list of sockets.
139
#
140
def remove_socket(sock)
141
self.sockets.delete(sock)
142
end
143
144
#
145
# This method is called once a new session has been created on behalf of
146
# this module instance and all socket connections created by this
147
# module should be closed.
148
#
149
def abort_sockets
150
sockets.delete_if { |sock|
151
152
begin
153
sock.close
154
rescue ::Exception
155
end
156
true
157
}
158
end
159
160
# Override Msf::Module#fail_with for Msf::Simple::Auxiliary::job_run_proc
161
def fail_with(reason, msg = nil)
162
raise Msf::Auxiliary::Failed, "#{reason.to_s}: #{msg}"
163
end
164
165
attr_accessor :queue
166
167
protected
168
169
attr_accessor :sockets
170
attr_writer :passive
171
172
end
173
174
end
175
176
177