Skip to content

Commit 9a2ec90

Browse files
committed
Add alert to show user the new session options available in Metasploit 6.4
1 parent d05b85d commit 9a2ec90

File tree

8 files changed

+82
-8
lines changed

8 files changed

+82
-8
lines changed

lib/msf/core/module.rb

+1
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ def default_cred?
397397
false
398398
end
399399

400+
def activate; end
400401
#
401402
# The array of zero or more platforms.
402403
#

lib/msf/core/module/alert.rb

+48
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ def add_error(msg = nil, &block)
4040
add_alert(:error, msg, &block)
4141
end
4242

43+
# Add an info message that will be provided to the user as early possible when using
44+
# this instance of a module, either when they select it with the `use`
45+
# command, when the module is about to start running, or when the module
46+
# generates its output.
47+
#
48+
# @param msg [String] an optional info message
49+
# @param block [Proc] an optional block that will be executed in the
50+
# context of the module instance at alert time to generate the
51+
# message. If provided the msg parameter is ignored.
52+
# @return [true, nil] whether or not the message was added to the list of
53+
# info messages
54+
def add_info(msg = nil, &block)
55+
add_alert(:info, msg, &block)
56+
end
57+
4358
# @return [Array<String, Proc>] a list of warning message strings, or
4459
# blocks (see #get_alerts)
4560
def warnings
@@ -52,6 +67,12 @@ def errors
5267
get_alerts(:error)
5368
end
5469

70+
# @return [Array<String, Proc>] a list of info message strings, or
71+
# blocks (see #get_alerts)
72+
def infos
73+
get_alerts(:info)
74+
end
75+
5576
# @param level [Symbol] The alert level to return
5677
# @return [Array<String, Proc>] A list of `level` alerts, either in string
5778
# or block form. Blocks expect to be executed in the context of a fully
@@ -135,6 +156,21 @@ def add_error(msg = nil, &block)
135156
add_alert(:error, msg, &block)
136157
end
137158

159+
# Add an info message that will be provided to the user as early possible when using
160+
# this instance of a module, either when they select it with the `use`
161+
# command, when the module is about to start running, or when the module
162+
# generates its output.
163+
#
164+
# @param msg [String] an optional info message
165+
# @param block [Proc] an optional block that will be executed in the
166+
# context of the module instance at alert time to generate the
167+
# message. If provided the msg parameter is ignored.
168+
# @return [true, nil] whether or not the message was added to the list of
169+
# info messages
170+
def add_info(msg = nil, &block)
171+
add_alert(:info, msg, &block)
172+
end
173+
138174
# This method allows modules to tell the framework if they are usable
139175
# on the system that they are being loaded on in a generic fashion.
140176
# By default, all modules are indicated as being usable. An example of
@@ -160,6 +196,11 @@ def errors
160196
get_alerts(:error)
161197
end
162198

199+
# @return [Array<String>] a list of info strings to show the user
200+
def infos
201+
get_alerts(:info)
202+
end
203+
163204
# Similar to {ClassMethods#get_alerts}, but executes each registered block in
164205
# the context of this module instance and returns a flattened list of strings.
165206
# (see {ClassMethods#get_alerts})
@@ -215,5 +256,12 @@ def alert_user
215256
self.you_have_been_warned[msg.hash] = true
216257
end
217258
end
259+
260+
infos.each do |msg|
261+
if msg && !self.you_have_been_warned[msg.hash]
262+
print_line(msg)
263+
self.you_have_been_warned[msg.hash] = true
264+
end
265+
end
218266
end
219267
end

lib/msf/core/optional_session.rb

+5
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ def session
3737

3838
super
3939
end
40+
41+
def activate
42+
super
43+
add_info('New in Metasploit 6.4 - This module can target a %grnSESSION%clr or an %grnRHOST%clr')
44+
end
4045
end

lib/msf/ui/console/command_dispatcher.rb

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def active_module
4545
#
4646
def active_module=(mod)
4747
driver.active_module = mod
48+
mod.activate unless mod.nil?
4849
end
4950

5051
#

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,6 @@ def cmd_search(*args)
596596
end
597597
end
598598
end
599-
if @module_search_results.length == 1 && use
600-
used_module = @module_search_results_with_usage_metadata.first[:mod].fullname
601-
cmd_use(used_module, true)
602-
end
603599
rescue ArgumentError
604600
print_error("Invalid argument(s)\n")
605601
cmd_search_help
@@ -611,13 +607,18 @@ def cmd_search(*args)
611607
::File.open(output_file, "wb") { |ofd|
612608
ofd.write(tbl.to_csv)
613609
}
614-
else
615-
print_line(tbl.to_s)
616-
print_module_search_results_usage
610+
return true
611+
end
612+
613+
print_line(tbl.to_s)
614+
print_module_search_results_usage
617615

618-
print_status("Using #{used_module}") if used_module
616+
if @module_search_results.length == 1 && use
617+
used_module = @module_search_results_with_usage_metadata.first[:mod].fullname
618+
cmd_use(used_module, true)
619619
end
620620

621+
print_status("Using #{used_module}") if used_module
621622
true
622623
end
623624

modules/auxiliary/scanner/postgres/postgres_login.rb

+6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ def create_session?
6161
end
6262
end
6363

64+
# Called when the module is set as the currently active module
65+
def activate
66+
super
67+
add_info('New in Metasploit 6.4 - The %grnCreateSession%clr option within this module can open an interactive session')
68+
end
69+
6470
# Loops through each host in turn. Note the current IP address is both
6571
# ip and datastore['RHOST']
6672
def run_host(ip)

modules/auxiliary/scanner/smb/smb_login.rb

+6
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def create_session?
8484
end
8585
end
8686

87+
# Called when the module is set as the currently active module
88+
def activate
89+
super
90+
add_info('New in Metasploit 6.4 - The %grnCreateSession%clr option within this module can open an interactive session')
91+
end
92+
8793
def run_host(ip)
8894
print_brute(level: :vstatus, ip: ip, msg: 'Starting SMB login bruteforce')
8995

modules/exploits/windows/smb/smb_relay.rb

+6
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ def available_actions
155155
actions
156156
end
157157

158+
# Called when the module is set as the currently active module
159+
def activate
160+
super
161+
add_info('New in Metasploit 6.4 - The %SMB_SESSION%clr action within this module can open an interactive session')
162+
end
163+
158164
def smb_logger
159165
log_device = datastore['VERBOSE'] ? Msf::Exploit::Remote::SMB::LogAdapter::LogDevice::Module.new(self) : Msf::Exploit::Remote::SMB::LogAdapter::LogDevice::Framework.new(framework)
160166
Msf::Exploit::Remote::SMB::LogAdapter::Logger.new(self, log_device)

0 commit comments

Comments
 (0)