Skip to content

Commit 1abaef4

Browse files
committed
Move new session information alerts behind a feature flag
1 parent 9a2ec90 commit 1abaef4

File tree

8 files changed

+43
-47
lines changed

8 files changed

+43
-47
lines changed

lib/msf/core/module.rb

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

400-
def activate; end
401400
#
402401
# The array of zero or more platforms.
403402
#

lib/msf/core/module/alert.rb

+27-15
Original file line numberDiff line numberDiff line change
@@ -242,26 +242,38 @@ def add_alert(level, msg, &block)
242242
# with this method will not be displayed again.
243243
def alert_user
244244
self.you_have_been_warned ||= {}
245-
246-
errors.each do |msg|
247-
if msg && !self.you_have_been_warned[msg.hash]
248-
print_error(msg)
249-
self.you_have_been_warned[msg.hash] = true
245+
without_prompt do
246+
errors.each do |msg|
247+
if msg && !self.you_have_been_warned[msg.hash]
248+
print_error(msg)
249+
self.you_have_been_warned[msg.hash] = true
250+
end
250251
end
251-
end
252252

253-
warnings.each do |msg|
254-
if msg && !self.you_have_been_warned[msg.hash]
255-
print_warning(msg)
256-
self.you_have_been_warned[msg.hash] = true
253+
warnings.each do |msg|
254+
if msg && !self.you_have_been_warned[msg.hash]
255+
print_warning(msg)
256+
self.you_have_been_warned[msg.hash] = true
257+
end
257258
end
258-
end
259259

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
260+
infos.each do |msg|
261+
if msg && !self.you_have_been_warned[msg.hash]
262+
# Make prefix an empty string to avoid adding clutter (timestamps, rhost, rport, etc.) to the output
263+
print_status(msg, prefix: '')
264+
self.you_have_been_warned[msg.hash] = true
265+
end
264266
end
265267
end
266268
end
269+
270+
# Temporarily set the prompt mode to false to ensure that there are not additional lines printed
271+
# A workaround for the prompting bug spotted in https://github.com/rapid7/metasploit-framework/pull/18761#issuecomment-1916645095
272+
def without_prompt(&block)
273+
previous_prompting_value = user_output.prompting
274+
user_output.prompting(false)
275+
yield
276+
ensure
277+
user_output.prompting(previous_prompting_value)
278+
end
267279
end

lib/msf/core/module/ui/message.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ def print_prefix
3030
prefix
3131
end
3232

33-
def print_status(msg='')
34-
super(print_prefix + msg)
33+
def print_status(msg='', prefix: nil)
34+
msg_prefix = prefix.nil? ? print_prefix : prefix
35+
super(msg_prefix + msg)
3536
end
3637

3738
def print_warning(msg='')

lib/msf/core/optional_session.rb

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def initialize(info = {})
1717
Msf::Opt::RPORT(nil, false)
1818
]
1919
)
20+
add_info('New in Metasploit 6.4 - This module can target a %grnSESSION%clr or an %grnRHOST%clr')
2021
end
2122

2223
if framework.features.enabled?(Msf::FeatureManager::POSTGRESQL_SESSION_TYPE)
@@ -29,6 +30,7 @@ def initialize(info = {})
2930
Msf::Opt::RPORT(nil, false)
3031
]
3132
)
33+
add_info('New in Metasploit 6.4 - This module can target a %grnSESSION%clr or an %grnRHOST%clr')
3234
end
3335
end
3436

@@ -37,9 +39,4 @@ def session
3739

3840
super
3941
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
4542
end

lib/msf/ui/console/command_dispatcher.rb

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

5150
#

modules/auxiliary/scanner/postgres/postgres_login.rb

+3-8
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ def initialize(info = {})
4646
])
4747

4848
options_to_deregister = %w[SQL PASSWORD_SPRAY]
49-
unless framework.features.enabled?(Msf::FeatureManager::POSTGRESQL_SESSION_TYPE)
49+
if framework.features.enabled?(Msf::FeatureManager::POSTGRESQL_SESSION_TYPE)
50+
add_info('New in Metasploit 6.4 - The %grnCreateSession%clr option within this module can open an interactive session')
51+
else
5052
options_to_deregister << 'CreateSession'
5153
end
5254
deregister_options(*options_to_deregister)
53-
5455
end
5556

5657
def create_session?
@@ -61,12 +62,6 @@ def create_session?
6162
end
6263
end
6364

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-
7065
# Loops through each host in turn. Note the current IP address is both
7166
# ip and datastore['RHOST']
7267
def run_host(ip)

modules/auxiliary/scanner/smb/smb_login.rb

+3-7
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def initialize
6565

6666
options_to_deregister = %w[USERNAME PASSWORD PASSWORD_SPRAY CommandShellCleanupCommand AutoVerifySession]
6767

68-
unless framework.features.enabled?(Msf::FeatureManager::SMB_SESSION_TYPE)
68+
if framework.features.enabled?(Msf::FeatureManager::SMB_SESSION_TYPE)
69+
add_info('New in Metasploit 6.4 - The %grnCreateSession%clr option within this module can open an interactive session')
70+
else
6971
# Don't give the option to create a session unless smb sessions are enabled
7072
options_to_deregister << 'CreateSession'
7173
end
@@ -84,12 +86,6 @@ def create_session?
8486
end
8587
end
8688

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-
9389
def run_host(ip)
9490
print_brute(level: :vstatus, ip: ip, msg: 'Starting SMB login bruteforce')
9591

modules/exploits/windows/smb/smb_relay.rb

+5-8
Original file line numberDiff line numberDiff line change
@@ -142,25 +142,22 @@ module is not able to clean up after itself. The service and payload
142142
deregister_options(
143143
'RPORT', 'RHOSTS', 'SMBPass', 'SMBUser', 'CommandShellCleanupCommand', 'AutoVerifySession', 'CreateSession'
144144
)
145+
if framework.features.enabled?(Msf::FeatureManager::SMB_SESSION_TYPE)
146+
add_info('New in Metasploit 6.4 - The %grnCREATE_SMB_SESSION%clr action within this module can open an interactive session')
147+
end
145148
end
146149

147150
def available_actions
148151
actions = [
149152
['PSEXEC', { 'Description' => 'Run psexec against the relay target' }]
150153
]
151154
if framework.features.enabled?(Msf::FeatureManager::SMB_SESSION_TYPE)
152-
actions << ['SMB_SESSION', { 'Description' => 'Get an SMB session' }]
155+
actions << ['CREATE_SMB_SESSION', { 'Description' => 'Get an SMB session' }]
153156
end
154157

155158
actions
156159
end
157160

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-
164161
def smb_logger
165162
log_device = datastore['VERBOSE'] ? Msf::Exploit::Remote::SMB::LogAdapter::LogDevice::Module.new(self) : Msf::Exploit::Remote::SMB::LogAdapter::LogDevice::Framework.new(framework)
166163
Msf::Exploit::Remote::SMB::LogAdapter::Logger.new(self, log_device)
@@ -310,7 +307,7 @@ def on_relay_success(relay_connection:)
310307
case action.name
311308
when 'PSEXEC'
312309
run_psexec(relay_connection)
313-
when 'SMB_SESSION'
310+
when 'CREATE_SMB_SESSION'
314311
begin
315312
session_setup(relay_connection)
316313
rescue StandardError => e

0 commit comments

Comments
 (0)