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

`jobs -i` stack traces with undefined method 'show_options' #8258

Closed
egypt opened this Issue Apr 17, 2017 · 3 comments

Comments

Projects
None yet
4 participants
@egypt
Copy link
Contributor

egypt commented Apr 17, 2017

Initially reported by octet in IRC, reproduced locally on master

Steps to reproduce

  1. Run a module as a job
  • use auxiliary/server/socks4a
  • run
  1. List detailed job info
  • jobs -i 0

Expected behavior

Msfconsole displays detailed job info with datastore options for the given job

Current behavior

16:19:39 default j:1 s:1 auxiliary(socks4a) > jobs -i 1
\nName: Socks4a Proxy Server, started at 2017-04-17 16:07:38 -0500
[-] Error while running command jobs: undefined method `show_options' for #<Msf::Ui::Console::CommandDispatcher::Jobs:0x000000060ead48>

Call stack:
/home/egypt/repo/metasploit-framework/lib/msf/ui/console/command_dispatcher/jobs.rb:172:in `cmd_jobs'
/home/egypt/repo/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:430:in `run_command'
/home/egypt/repo/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:392:in `block in run_single'
/home/egypt/repo/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:386:in `each'
/home/egypt/repo/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:386:in `run_single'
/home/egypt/repo/metasploit-framework/lib/rex/ui/text/shell.rb:205:in `run'
/home/egypt/repo/metasploit-framework/lib/metasploit/framework/command/console.rb:48:in `start'
/home/egypt/repo/metasploit-framework/lib/metasploit/framework/command/base.rb:82:in `start'
./msfconsole:48:in `<main>'

System stuff

Metasploit version

Current master (85845b3)

I installed Metasploit with:

OS

Ubuntu

@wvu-r7

This comment has been minimized.

Copy link
Contributor

wvu-r7 commented Apr 18, 2017

@bcoles

This comment has been minimized.

Copy link
Contributor

bcoles commented May 20, 2017

This patch will fix the issue. Although probably not the best approach.

Basically just a copy/paste of the show_options(mod) method from lib/msf/ui/console/command_dispatcher/modules.rb.

It also fixes an output issue with '\n' instead of "\n".

diff --git a/lib/msf/ui/console/command_dispatcher/jobs.rb b/lib/msf/ui/console/command_dispatcher/jobs.rb
index ac184be..58cc2f3 100644
--- a/lib/msf/ui/console/command_dispatcher/jobs.rb
+++ b/lib/msf/ui/console/command_dispatcher/jobs.rb
@@ -164,12 +164,45 @@ module Msf
                 job = framework.jobs[job_id.to_s]
                 mod = job.ctx[0]
 
-                output  = '\n'
+                output  = "\n"
                 output += "Name: #{mod.name}"
                 output += ", started at #{job.start_time}" if job.start_time
                 print_line(output)
 
-                show_options(mod) if mod.options.has_options?
+            # ----- SNIP -----
+            mod_opt = Serializer::ReadableText.dump_options(mod, '   ')
+            print("\nModule options (#{mod.fullname}):\n\n#{mod_opt}\n") if (mod_opt and mod_opt.length > 0)
+
+            # If it's an exploit and a payload is defined, create it and
+            # display the payload's options
+            if (mod.exploit? and mod.datastore['PAYLOAD'])
+              p = framework.payloads.create(mod.datastore['PAYLOAD'])
+
+              if (!p)
+                print_error("Invalid payload defined: #{mod.datastore['PAYLOAD']}\n")
+                return
+              end
+
+              p.share_datastore(mod.datastore)
+
+              if (p)
+                p_opt = Serializer::ReadableText.dump_options(p, '   ')
+                print("\nPayload options (#{mod.datastore['PAYLOAD']}):\n\n#{p_opt}\n") if (p_opt and p_opt.len
+              end
+            end
+
+            # Print the selected target
+            if (mod.exploit? and mod.target)
+              mod_targ = Serializer::ReadableText.dump_exploit_target(mod, '   ')
+              print("\nExploit target:\n\n#{mod_targ}\n") if (mod_targ and mod_targ.length > 0)
+            end
+
+            # Print the selected action
+            if mod.kind_of?(Msf::Module::HasActions) && mod.action
+              mod_action = Serializer::ReadableText.dump_module_action(mod, '   ')
+              print("\n#{mod.type.capitalize} action:\n\n#{mod_action}\n") if (mod_action and mod_action.length
+            end
+            # ----- /SNIP -----
 
                 if verbose
                   mod_opt = Serializer::ReadableText.dump_advanced_options(mod, '   ')

@darkbushido darkbushido self-assigned this Jun 1, 2017

@darkbushido

This comment has been minimized.

Copy link
Contributor

darkbushido commented Jun 1, 2017

I think we should fix this the same way I'm trying to do it in creds, #8493 mostly to avoid code duplication.

@darkbushido darkbushido referenced this issue Jun 5, 2017

Merged

renaming db_common to common #8517

4 of 4 tasks complete

@wvu-r7 wvu-r7 closed this in #8517 Jun 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment