-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix edgecase in Meterpreter job persistence #19002
Fix edgecase in Meterpreter job persistence #19002
Conversation
elsif (opts['OptionStr']) | ||
self.datastore.import_options_from_s(opts['OptionStr']) | ||
if (value = opts['Options']) | ||
if value.is_a?(String) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows persisted jobs to still be loaded correctly, i.e. the scenario of Options
being a string instead of hash
@@ -257,7 +257,7 @@ def add_persist_job(job_id) | |||
|
|||
payload_opts = { | |||
'Payload' => payload.refname, | |||
'Options' => payload.datastore, | |||
'Options' => payload.datastore.to_h, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Serializing payload.datastore
as JSON led to a string being saved, this allows a hash to be persisted instead
@@ -208,7 +208,21 @@ def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = { | |||
|
|||
restore_handlers.each do |handler_opts| | |||
handler = framework.modules.create(handler_opts['mod_name']) | |||
handler.exploit_simple(handler_opts['mod_options']) | |||
handler.init_ui(self.input, self.output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wiring up init_ui
allows the user to have the job startup error messages logged to the console instead of them silently being ignored - which immediately showed the original hidden error
Before: No errors logged
After: Errors logged
bundle exec ruby ./msfconsole --quiet
[*] Using configured payload linux/x64/meterpreter/reverse_tcp
[*] Starting persistent handler(s)...
[-] Msf::OptionValidateError One or more options failed to validate: MeterpreterDebugLogging.
[*] Failed to start persistent payload handler #0 (exploit/multi/handler)
[-] Msf::OptionValidateError One or more options failed to validate: MeterpreterDebugLogging.
[*] Failed to start persistent payload handler #1 (exploit/multi/handler)
msf6 exploit(multi/handler) >
ca1b677
to
9b4fb8e
Compare
@@ -17,4 +19,18 @@ | |||
] | |||
|
|||
it_behaves_like 'an option', valid_values, invalid_values, 'meterpreterdebuglogging' | |||
|
|||
describe '.parse_logging_options' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests to verify the handling of MeterpreterDebugLogging
being set to an empty string and causing validation errors is fixed, because the to_h
method persists nil as the empty string ""
:
metasploit-framework/lib/msf/core/data_store_with_fallbacks.rb
Lines 263 to 272 in 685a2e9
# Override Hash's to_h method so we can include the original case of each key | |
# (failing to do this breaks a number of places in framework and pro that use | |
# serialized datastores) | |
def to_h | |
datastore_hash = {} | |
self.keys.each do |k| | |
datastore_hash[k.to_s] = self[k].to_s | |
end | |
datastore_hash | |
end |
9b4fb8e
to
d6eb8e5
Compare
if framework.jobs.key?(job) | ||
ctx_1 = framework.jobs[job.to_s].ctx[1] | ||
job_list.map(&:to_s).each do |job_id| | ||
job_id = job_id.to_i < 0 ? framework.jobs.keys[job_id.to_i] : job_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pattern from: #15492
a37d05b
to
8f1472f
Compare
8f1472f
to
0bba494
Compare
I followed the setup instructions with setting up a multi/handler. BeforeJob does not survive a reboot of Console
AfterJob persists
|
Release NotesFixed persistent jobs not working when rebooting MSF console. |
closes #18995
Verification
Ensure the job is available on console boot
jobs
jobs -v
correctly detects when a job is persistedjobs -k 1
and with a negative indexjobs -k -1