Windows Manage Set Port Forwarding With PortProxy - Metasploit


This page contains detailed information about how to use the post/windows/manage/portproxy metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: Windows Manage Set Port Forwarding With PortProxy
Module: post/windows/manage/portproxy
Source code: modules/post/windows/manage/portproxy.rb
Disclosure date: -
Last modification time: 2017-07-24 06:26:21 +0000
Supported architecture(s): -
Supported platform(s): Windows
Target service / protocol: -
Target network port(s): -
List of CVEs: -

This module uses the PortProxy interface from netsh to set up port forwarding persistently (even after reboot). PortProxy supports TCP IPv4 and IPv6 connections.

Module Ranking and Traits


Module Ranking:

  • normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.

Basic Usage


There are two ways to execute this post module.

From the Meterpreter prompt

The first is by using the "run" command at the Meterpreter prompt. It allows you to run the post module against that specific session:

meterpreter > run post/windows/manage/portproxy

From the msf prompt

The second is by using the "use" command at the msf prompt. You will have to figure out which session ID to set manually. To list all session IDs, you can use the "sessions" command.

msf > use post/windows/manage/portproxy
msf post(portproxy) > show options
    ... show and set options ...
msf post(portproxy) > set SESSION session-id
msf post(portproxy) > exploit

If you wish to run the post against all sessions from framework, here is how:

1 - Create the following resource script:


framework.sessions.each_pair do |sid, session|
  run_single("use post/windows/manage/portproxy")
  run_single("set SESSION #{sid}")
  run_single("run")
end

2 - At the msf prompt, execute the above resource script:

msf > resource path-to-resource-script

Required Options


  • SESSION: The session to run this module on.

  • LOCAL_ADDRESS: IPv4/IPv6 address to which to listen.

  • CONNECT_ADDRESS: IPv4/IPv6 address to which to connect.

  • CONNECT_PORT: Port number to which to connect.

  • LOCAL_PORT: Port number to which to listen.

Go back to menu.

Msfconsole Usage


Here is how the windows/manage/portproxy post exploitation module looks in the msfconsole:

msf6 > use post/windows/manage/portproxy

msf6 post(windows/manage/portproxy) > show info

       Name: Windows Manage Set Port Forwarding With PortProxy
     Module: post/windows/manage/portproxy
   Platform: Windows
       Arch: 
       Rank: Normal

Provided by:
  Borja Merino <[email protected]>

Compatible session types:
  Meterpreter

Basic options:
  Name             Current Setting  Required  Description
  ----             ---------------  --------  -----------
  CONNECT_ADDRESS                   yes       IPv4/IPv6 address to which to connect.
  CONNECT_PORT                      yes       Port number to which to connect.
  IPV6_XP          true             yes       Install IPv6 on Windows XP (needed for v4tov4).
  LOCAL_ADDRESS                     yes       IPv4/IPv6 address to which to listen.
  LOCAL_PORT                        yes       Port number to which to listen.
  SESSION                           yes       The session to run this module on.
  TYPE             v4tov4           yes       Type of forwarding (Accepted: v4tov4, v6tov6, v6tov4, v4tov6)

Description:
  This module uses the PortProxy interface from netsh to set up port 
  forwarding persistently (even after reboot). PortProxy supports TCP 
  IPv4 and IPv6 connections.

Module Options


This is a complete list of options available in the windows/manage/portproxy post exploitation module:

msf6 post(windows/manage/portproxy) > show options

Module options (post/windows/manage/portproxy):

   Name             Current Setting  Required  Description
   ----             ---------------  --------  -----------
   CONNECT_ADDRESS                   yes       IPv4/IPv6 address to which to connect.
   CONNECT_PORT                      yes       Port number to which to connect.
   IPV6_XP          true             yes       Install IPv6 on Windows XP (needed for v4tov4).
   LOCAL_ADDRESS                     yes       IPv4/IPv6 address to which to listen.
   LOCAL_PORT                        yes       Port number to which to listen.
   SESSION                           yes       The session to run this module on.
   TYPE             v4tov4           yes       Type of forwarding (Accepted: v4tov4, v6tov6, v6tov4, v4tov6)

Advanced Options


Here is a complete list of advanced options supported by the windows/manage/portproxy post exploitation module:

msf6 post(windows/manage/portproxy) > show advanced

Module advanced options (post/windows/manage/portproxy):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   VERBOSE    false            no        Enable detailed status messages
   WORKSPACE                   no        Specify the workspace for this module

Post Actions


This is a list of all post exploitation actions which the windows/manage/portproxy module can do:

msf6 post(windows/manage/portproxy) > show actions

Post actions:

   Name  Description
   ----  -----------

Evasion Options


Here is the full list of possible evasion options supported by the windows/manage/portproxy post exploitation module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 post(windows/manage/portproxy) > show evasion

Module evasion options:

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------

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.

You don't have enough privileges. Try getsystem.


Here is a relevant code snippet related to the "You don't have enough privileges. Try getsystem." error message:

31:	      ])
32:	    end
33:	
34:	  def run
35:	    if not is_admin?
36:	      print_error("You don't have enough privileges. Try getsystem.")
37:	      return
38:	    end
39:	
40:	    # Due to a bug in Windows XP you need to install IPv6
41:	    # http://support.microsoft.com/kb/555744/en-us

Setup error. Verify parameters and syntax.


Here is a relevant code snippet related to the "Setup error. Verify parameters and syntax." error message:

62:	    netsh_args << "listenaddress=#{datastore['LOCAL_ADDRESS']} "
63:	    netsh_args << "connectport=#{datastore['CONNECT_PORT']} "
64:	    netsh_args << "connectaddress=#{datastore['CONNECT_ADDRESS']}"
65:	    output = cmd_exec("netsh", netsh_args)
66:	    if output.size > 2
67:	      print_error("Setup error. Verify parameters and syntax.")
68:	      return false
69:	    else
70:	      print_good("PortProxy added.")
71:	    end
72:	

IPv6 is not installed. You need IPv6 to use portproxy.


Here is a relevant code snippet related to the "IPv6 is not installed. You need IPv6 to use portproxy." error message:

90:	  def check_ipv6
91:	    if ipv6_installed
92:	      print_status("IPv6 is already installed.")
93:	      return true
94:	    elsif not datastore['IPV6_XP']
95:	      print_error("IPv6 is not installed. You need IPv6 to use portproxy.")
96:	      print_status("IPv6 can be installed with \"netsh interface ipv6 install\"")
97:	      return false
98:	    else
99:	      print_status("Installing IPv6... can take a little long")
100:	      cmd_exec("netsh","interface ipv6 install",120)

IPv6 was not successfully installed. Run it again.


Here is a relevant code snippet related to the "IPv6 was not successfully installed. Run it again." error message:

97:	      return false
98:	    else
99:	      print_status("Installing IPv6... can take a little long")
100:	      cmd_exec("netsh","interface ipv6 install",120)
101:	      if not ipv6_installed
102:	        print_error("IPv6 was not successfully installed. Run it again.")
103:	        return false
104:	      end
105:	      print_good("IPv6 was successfully installed.")
106:	      return true
107:	    end

There was an error enabling the port.


Here is a relevant code snippet related to the "There was an error enabling the port." error message:

115:	      cmd_exec("netsh","firewall set portopening protocol=TCP port=\"#{datastore['LOCAL_PORT']}\"")
116:	    end
117:	    output = cmd_exec("netsh","firewall show state")
118:	
119:	    if output =~ /^#{datastore['LOCAL_PORT']} /
120:	      print_good("Port opened in Windows Firewall.")
121:	    else
122:	      print_error("There was an error enabling the port.")
123:	    end
124:	  end
125:	end

Go back to menu.


Go back to menu.

See Also


Check also the following modules related to this module:

Authors


  • Borja Merino <bmerinofe[at]gmail.com>

Version


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

Go back to menu.