RPC `module.execute` swallows option-validation failures for `exploit`/`evasion`, returning a 200 `{job_id: nil, uuid: nil}` with no structured error (unlike the `auxiliary` branch)

Author: Panchal-SahilCreated Sep 20, 2026Updated Sep 20, 2026
Labelsbug

Steps to reproduce

Against a running msfrpcd (v10 MSGPACK), call module.execute for an exploit whose options fail the module's own validation (e.g. a multi/handler with a reverse payload but no LHOST):

ruby
# msfrpcd -a 127.0.0.1 -p 55553 -U msf -P test -S -n
require 'msf/core/rpc/v10/client'
c = Msf::RPC::Client.new(host: '127.0.0.1', port: 55553, ssl: false)
c.login('msf', 'test')

# exploit path: LHOST omitted -> payload option validation raises Msf::OptionValidateError
p c.call('module.execute', 'exploit', 'multi/handler',
         { 'PAYLOAD' => 'windows/meterpreter/reverse_tcp' })
# => {"job_id"=>nil, "uuid"=>nil}          (HTTP 200, no "error" key)
p c.call('job.list')
# => {}                                     (no job was created)

# same failure class, auxiliary path: RHOSTS omitted
p c.call('module.execute', 'auxiliary', 'scanner/portscan/tcp', {})
# => raises Msf::RPC::ServerException, error_class "Msf::OptionValidateError",
#    "One or more options failed to validate: RHOSTS."   (HTTP 500, structured)

The repro above uses multi/handler. Any exploit fails the same way: exploit_simple validates the datastore before starting the job and rescues the failure identically, so an exploit run without a required option such as RHOSTS never sets job_id. The evasion branch is identical by source inspection, though I have not run it over RPC.

Environment: current metasploitframework/metasploit-framework:latest Docker image (Framework 6.5.4-dev, Ruby 3.3.8); code path confirmed present on current master.

Were you following a specific guide/tutorial or reading documentation?

No.

Expected behavior

module.execute should report an option-validation failure consistently across module types. The auxiliary branch already does: it surfaces Msf::OptionValidateError as a structured Msf::RPC::Exception (HTTP 500) naming the failed option. The documented return of module.execute is { 'job_id' [Integer], 'uuid' [String] } (lib/msf/core/rpc/v10/rpc_module.rb), i.e. a job was launched, so a rejected run should either return that structured error or otherwise signal, through the RPC response, that no job was launched and why.

Current behavior

For exploit and evasion, module.execute returns HTTP 200 with {"job_id"=>nil, "uuid"=>nil} and no error/error_class/error_message key. No job runs (job.list stays empty), and since uuid is nil the caller has no handle to query module.results with. The rejection reason (which option failed) does not appear in the RPC response, the job/session tables, or the job-result tracker. On the exploit path it also never reaches framework.log or the daemon output: the wrapper hands it to the module's user_output, which is nil under RPC, so it goes nowhere.

A programmatic RPC client therefore gets a success-shaped, non-raising response for a run that was rejected, and cannot recover the reason from any structured channel. The identical Msf::OptionValidateError becomes a structured 500 on the auxiliary branch of the same method.

Root cause:

  • _run_exploit/_run_auxiliary/_run_post/_run_evasion discard the return value of their Msf::Simple::* wrapper and unconditionally return { "job_id" => mod.job_id, "uuid" => mod.run_uuid }; job_id/run_uuid are only set on the wrapper's happy path.
  • Msf::Simple::Exploit.exploit_simple (and Evasion.run_simple) wrap option validation in a begin/rescue ::Msf::OptionValidateError arm that returns without setting job_id/ run_uuid, so the RPC returns {job_id: nil, uuid: nil}.
  • Msf::Simple::Auxiliary.run_simple calls mod.validate synchronously with no such rescue, so the error propagates to the RPC service's rescue StandardError and becomes a structured error body. (The rescue ::Msf::OptionValidateError in auxiliary.rb is inside job_run_proc, the spawned job thread, not run_simple.)

The fix likely belongs in rpc_module.rb rather than the shared wrapper. exploit_simple's rescue → print + return looks intentional for msfconsole, where printing the failed option and returning is the right behavior. So the RPC helper could stop reporting a job_id when no job launched (check mod.job_id after the call; nil means no job) and surface a structured error, matching what _run_payload already does for generation failures. That leaves console behavior unchanged. I've opened a PR against this issue that implements this with regression tests, and I'm happy to adjust the return-contract choice if you'd prefer a different shape.

Metasploit version

6.5.4-dev (current metasploitframework/metasploit-framework:latest); path confirmed on current master.

Additional Information

n/a

Source: rapid7/metasploit-framework