Skip to content
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

Job persist function doesn't seem to work #18995

Open
dotslashsuperstar opened this issue Mar 22, 2024 · 5 comments · May be fixed by #19002
Open

Job persist function doesn't seem to work #18995

dotslashsuperstar opened this issue Mar 22, 2024 · 5 comments · May be fixed by #19002
Assignees
Labels
bug confirmed Issues confirmed by a committer

Comments

@dotslashsuperstar
Copy link
Contributor

Steps to reproduce

How'd you do it?

  1. use exploit/multi/handler
  2. set payload linux/x64/meterpreter/reverse_tcp
  3. setg lhost ip
  4. run -j
  5. jobs -p job_id
  6. exit
  7. msfconsole
  8. jobs

Expected behavior

What should happen?
Job should survive.

Current behavior

What happens instead?
Job does not.

In persist file it stores payload options with key 'Options' and the value as a string like
[
{
"mod_name": "exploit/multi/handler",
"mod_options": {
"Payload": "linux/x64/meterpreter/reverse_tcp",
"Options": "AppendExit=false ... WfsDelay=2 payload=linux/x64/meterpreter/reverse_tcp ",
"RunAsJob": true
}
}
]

When parsing the options it tries to do a .each on the string resulting in load fail with this entry in log...
[03/22/2024 10:34:11] [e(0)] core: Exploit failed (multi/handler) - NoMethodError undefined method `each' for "AppendExit=false ... WfsDelay=2 payload=linux/x64/meterpreter/reverse_tcp ":String

It looks like it dumps the datastore into the persist file in

And starts to load it here

handler.exploit_simple(handler_opts['mod_options'])

Metasploit version

Framework: 6.4.0-dev
Console : 6.4.0-dev

@adfoster-r7 adfoster-r7 added the confirmed Issues confirmed by a committer label Mar 22, 2024
@dotslashsuperstar
Copy link
Contributor Author

It looks like changing the 'Options' key to 'OptionStr' does parse it correctly but the job still is not starting. Also it is a space sperated string and I think the multi/meterpreter/reverse_https payload has spaces in a couple fields like 'HttpUserAgent' and 'HttpUnknownRequestResponse'.

self.datastore.import_options_from_s(opts['OptionStr'])

@adfoster-r7 adfoster-r7 self-assigned this Mar 23, 2024
@dotslashsuperstar
Copy link
Contributor Author

I was able to get it to work by changing

to 'Options' => payload.datastore.to_h,
but it throws an error on
raise Msf::OptionValidateError.new(error_options),
for option 'MeterpreterDebugLogging' but deleting that option lets it work.

@adfoster-r7
Copy link
Contributor

adfoster-r7 commented Mar 23, 2024

Thanks for the pull request! Sorry that there's been a bit of a race condition here, I had a PoC working for a fix when I self-assigned the issue but was going to put up a pull request for it later - but I see you were able to get a solution working too in that time! 💯

I think we've achieved the same end result here, but I've wired up some extra things: #19002

If you want to test that the above PR works, I'd be able to merge mine in - then I could merge in the logging changes that you've added to lib/msf/ui/console/command_dispatcher/jobs.rb? Or would your changes to lib/msf/base/serializer/readable_text.rb still be needed 👀

@dotslashsuperstar
Copy link
Contributor Author

Yeah it works great. It looks like you were able to get everything I had and more. I added the datastore.to_h to lib/msf/base/serializer/readable_text.rb so jobs -v shows the correct persist state. The best way to test your PR is to clone your fork then checkout the branch, right? I'm rather new to git and just making sure I'm doing it right. Also I should close that PR I made too, right?

I also think the 'LocalOutput' option is not being written to the file but I havent verified that yet. Thanks

@dotslashsuperstar
Copy link
Contributor Author

I just added an update to lib/msf/ui/console/command_dispatcher/jobs.rb so jobs -k id will remove the job from file correctly.

payload_option = ctx_1.datastore.user_defined.to_h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug confirmed Issues confirmed by a committer
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants