Microsoft KB Archive/908472

= How to configure RPC to use certain ports and how to help secure those ports by using IPsec =

Article ID: 908472

Article Last Modified on 10/18/2007

-

APPLIES TO

 Microsoft Windows Server 2003 SP1, when used with:  Microsoft Windows Server 2003, Datacenter Edition (32-bit x86)

 Microsoft Windows Server 2003, Enterprise Edition

 Microsoft Windows Server 2003, Standard Edition (32-bit x86)

 Microsoft Windows Server 2003, Web Edition</li></ul> </li> Microsoft Windows 2000 Service Pack 4, when used with:  Microsoft Windows 2000 Professional Edition</li></ul>

 Microsoft Windows 2000 Server</li></ul> </li> Microsoft Windows XP Home Edition</li> Microsoft Windows XP Media Center Edition 2005</li> Microsoft Windows XP Professional</li> Microsoft Windows XP Tablet PC Edition 2005</li></ul>

-

<div class="notice_section">

<div class="summary_section">

SUMMARY
''This article describes how to configure RPC to use a specific dynamic port range and how to help secure the ports in that range by using an Internet Protocol security (IPsec) policy. By default, RPC uses ports in the ephemeral port range (1024-5000) when it assigns ports to RPC applications that have to listen on a TCP endpoint. This behavior can make restricting access to these ports challenging for network administrators. This article discusses ways to reduce the number of ports available to RPC applications and how to restrict access to these ports by using a registry-based IPsec policy.

Because the steps in this article involve computer-wide changes that require the computer to be restarted, all these steps should be performed first in nonproduction environments to identify any application-compatibility issues that may occur as the result of these changes.

''

<div class="moreinformation_section">

MORE INFORMATION
There are multiple configuration tasks that must be completed in order to relocate, reduce, and restrict access to RPC ports.

First, the RPC dynamic port range should be restricted to a smaller, more manageable port range that is easier to block by using a firewall or IPsec policy. By default, RPC dynamically allocates ports in the range of 1024 to 5000 for endpoints that do not specify a port on which to listen.

Note This article uses the port range of 5001 to 5021 to avoid exhausting ephemeral ports and to reduce the number of ports available to RPC endpoints from 3,976 to 20.

Next, an IPsec policy must be created to restrict access to this port range to deny access to all hosts on the network.

Finally, the IPsec policy can be updated to give certain IP addresses or network subnets access to the blocked RPC ports and to exclude all others.

To start the task of reconfiguring the RPC dynamic port range, download the RPC Configuration Tool (RPCCfg.exe), and then copy it to the workstation or to the server that will be reconfigured. To do this, visit the following Microsoft Web site:

http://www.microsoft.com/downloads/details.aspx?FamilyID=0f9cde2f-8632-4da8-ae70-645e1ddaf369&DisplayLang=en

To perform the subsequent tasks of creating an IPsec policy, download the Internet Protocol Security Policies Tool (Ipsecpol.exe), and then copy it to the workstation or to the server that will be reconfigured. To do this, visit the following Microsoft Web site:

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=7D40460C-A069-412E-A015-A2AB904B7361

Note To create an IPsec policy for Microsoft Windows XP or for a later version of the Windows operating system, use Ipseccmd.exe. Ipseccmd.exe is part of the Windows XP support tools. The syntax and usage of IPseccmd.exe are the same as the syntax and usage of Ipsecpol.exe. For more information about the Windows XP support tools, click the following article number to view the article in the Microsoft Knowledge Base:

838079 Windows XP Service Pack 2 Support Tools

Relocate and reduce the RPC dynamic port range by using RPCCfg.exe
To relocate and reduce the RPC dynamic port range by using RPCCfg.exe, follow these steps: <ol> Copy RPCCfg.exe to the server that is to be configured</li> At the command prompt, type rpccfg.exe -pe 5001-5021 -d 0.

Note This port range is recommended for use by RPC endpoints because ports in this range are not likely to be allocated for use by other applications. By default, RPC uses the port range of 1024 to 5000 for allocating ports for endpoints. However, ports in this range are also dynamically allocated for use by the Windows operating system for all Windows sockets applications and can be exhausted on heavily used servers such as terminal servers and middle-tier servers that make many outgoing calls to remote systems.

For example, when Internet Explorer contacts a Web server on port 80, it listens on a port in the 1024-5000 range for the response from the server. A middle-tier COM server that makes outgoing calls to other remote servers also uses a port in this range for the incoming reply to that call. Moving the range of ports that RPC uses for its endpoints to the 5001 port range will reduce the chance that these ports will be used by other applications.

For more information about ephemeral port usage in Windows operating systems, visit the following Microsoft Web sites.  For Windows 2000:

http://technet.microsoft.com/library/bb726981.aspx

</li> For Windows Server 2003:

http://technet2.microsoft.com/WindowsServer/en/library/823ca085-8b46-4870-a83e-8032637a87c81033.mspx?mfr=true

</li></ul> </li></ol>

Use an IPsec or firewall policy to block access to the vulnerable ports on the affected host
After you follow the instructions for restricting the RPC dynamic port range, the new RPC dynamic port range that is made available is 5001 to 5021. TCP 135 should be blocked by an IPsec or firewall policy. Additionally, this port range should be screened or filtered either at the perimeter or on the host. Additionally, this port range should be filtered by using an IPsec policy.

In the commands in the following section, any text that appears between percent (%) signs is intended to represent text in the command that must be entered by the person who creates the IPsec policy. For example, wherever the text &quot;%IPSECTOOL%&quot; appears, the person who creates the policy should substitute that text as follows:
 * For Windows 2000, substitute &quot;%IPSECTOOL%&quot; with &quot;ipsecpol.exe.&quot;
 * For Windows XP or a later version of Windows, substitute &quot;%IPSECTOOL%&quot; with &quot;ipseccmd.exe.&quot;

For more information about how to use IPsec to block ports, click the following article number to view the article in the Microsoft Knowledge Base:

813878 How to block specific network protocols and ports by using IPSec

Block access to the RPC Endpoint Mapper for all IP addresses
To block access to the RPC Endpoint Mapper for all IP addresses, use the following syntax.

Note On Windows XP and on later operating systems, use Ipseccmd.exe. On Windows 2000, use Ipsecpol.exe (Windows 2000). %IPSECTOOL% -w REG -p &quot;Block RPC Ports&quot; -r &quot;Block Inbound TCP 135 Rule&quot; -f *=0:135:TCP -n BLOCK Note Do not type &quot;%IPSECTOOL%&quot; in this command. &quot;%IPSECTOOL%&quot; is intended to represent the part of the command that must be customized. For example, on Windows 2000, type the following command from a directory that contains Ipsecpol.exe to block all incoming access to TCP 135: ipsecpol.exe -w REG -p &quot;Block RPC Ports&quot; -r &quot;Block Inbound TCP 135 Rule&quot; -f *=0:135:TCP -n BLOCK On Windows XP and on later operating systems, type the following command from a directory that contains Ipseccmd.exe to block all incoming access to TCP 135: ipseccmd.exe -w REG -p &quot;Block RPC Ports&quot; -r &quot;Block Inbound TCP 135 Rule&quot; -f *=0:135:TCP -n BLOCK

Block access to the RPC dynamic port range for all IP addresses
To block access to the RPC dynamic port range for all IP addresses, use the following syntax.

Note On Windows XP and on later operating systems, use Ipseccmd.exe. On Windows 2000, use Ipsecpol.exe (Windows 2000). %IPSECTOOL% -w REG -p &quot;Block RPC Ports&quot; -r &quot;Block Inbound TCP %PORT% Rule&quot; -f *=0:%PORT%:TCP -n BLOCK Note Do not type &quot;%IPSECTOOL%&quot; or &quot;%PORT%&quot; in this command. &quot;%IPSECTOOL%&quot; and &quot;%PORT%&quot; are intended to represent parts of the command that must be customized. For example, type the following command on Windows 2000 hosts to block all incoming access to TCP 5001: ipsecpol.exe -w REG -p &quot;Block RPC Ports&quot; -r &quot;Block Inbound TCP 5001 Rule&quot; -f *=0:5001:TCP -n BLOCK To block all incoming access to TCP 5001, type the following command on Windows XP hosts and on hosts of later Windows operating systems: ipseccmd.exe -w REG -p &quot;Block RPC Ports&quot; -r &quot;Block Inbound TCP 5001 Rule&quot; -f *=0:5001:TCP -n BLOCK Repeat this command for each RPC port that must be blocked by changing the port number that is listed in this command. Ports that must be blocked are in the 5001-5021 range.

Note Do not forget to change the port number in the rule name (the -r switch) and in the filter (the -f switch).

Optional: Give access to the RPC Endpoint Mapper for specific subnets if access is needed
If you must give specific subnets access to the restricted RPC ports, you must first give these subnets access to the RPC Endpoint Mapper that you blocked earlier. To give a specific subnet access to the RPC Endpoint Mapper, use the following command: %IPSECTOOL% -w REG -p &quot;Block RPC Ports&quot; -r &quot;Allow Inbound TCP 135 from %SUBNET% Rule&quot; -f %SUBNET%/%MASK%=0:135:TCP -n PASS Note In this command, the following statements apply:  &quot;%IPSECTOOL%&quot; represents the command to use. This command is either &quot;ipsecpol.exe&quot; or &quot;ipseccmd.exe.&quot; Which command is used depends upon which operating system you are configuring.</li> <li>&quot;%SUBNET%&quot; represents the remote IP subnet to which you want to give access, for example, 10.1.1.0.</li> <li> &quot;%MASK%&quot; represents the subnet mask to use, for example, 255.255.255.0.

For example, the following command enables all hosts from the 10.1.1.0/255.255.255.0 subnet to connect to port TCP 135. All other hosts will have their connections denied by the default block rule that was created earlier for this port. %IPSECTOOL% -w REG -p &quot;Block RPC Ports&quot; -r &quot;Allow Inbound TCP Port 135 from 10.1.1.0 Rule&quot; -f 10.1.1.0/255.255.255.0=0:135:TCP -n PASS </li></ul>

Optional: Give access to the new RPC dynamic port range for specific subnets if access is needed
Each subnet that was given access to the RPC Endpoint Mapper earlier should also be given access to all the ports in the new RPC dynamic port range (5001-5021).

If you enable subnets to reach the RPC Endpoint Mapper but not the dynamic port range, the application may stop responding, or you may experience other problems.

The following command gives a specific subnet access to a port in the new RPC dynamic port range: %IPSECTOOL% -w REG -p &quot;Block RPC Ports&quot; -r &quot;Allow Inbound TCP %PORT% from %SUBNET% Rule&quot; -f %SUBNET%/%MASK%=0:%PORT%:TCP -n PASS Note In this command, the following statements apply: <ul> <li>&quot;%IPSECTOOL%&quot; represents the command to use. This command is either &quot;ipsecpol.exe&quot; or &quot;ipseccmd.exe.&quot; Which command is used depends upon which operating system you are configuring.</li> <li>&quot;%PORT%&quot; represents the port in the dynamic port range to which to give access.</li> <li>&quot;%SUBNET%&quot; represents the remote IP subnet to which you want to give access, for example, 10.1.1.0.</li> <li> &quot; %MASK%&quot; represents the subnet mask to use, for example, 255.255.255.0.

For example, the following command enables all hosts from the 10.1.1.0/255.255.255.0 subnet to connect to port TCP 5001. All other hosts will have their connections denied by the default block rule that was created earlier for this port. %IPSECTOOL% -w REG -p &quot;Block RPC Ports&quot; -r &quot;Allow Inbound TCP Port 5001 from 10.1.1.0 Rule&quot; -f 10.1.1.0/255.255.255.0=0:5001:TCP -n PASS </li></ul>

Note This command should be repeated for each subnet and port in the new RPC dynamic port range.

Assign the IPsec policy
Note The commands in this section take effect immediately.

After you create all the block rules and all the optional allow rules for the configured RPC ports, assign the policy by using the following command: %IPSECTOOL% -w REG -p &quot;Block RPC Ports&quot; –x Note To immediately unassign the policy, use the following command: %IPSECTOOL% -w REG -p &quot;Block RPC Ports&quot; –y Note To delete the policy from the registry, use the following command: %IPSECTOOL% -w REG -p &quot;Block RPC Ports&quot; -o You must restart the host for the changes to take effect.

Notes
 * The RPC configuration changes require a restart.
 * The IPsec policy changes take effect immediately and do not require a restart.

After the workstation or server restarts, any RPC interfaces that use the ncacn_ip_tcp protocol sequence and do not specify a specific TCP port to which to bind will have a port allocated from this range by the RPC runtime when the RPC server starts.

Note The server may require more than 20 TCP ports. You can use the rpcdump.exe command to count the number of RPC endpoints that are bound to a TCP port and to increase this number if you must. For more information about how to obtain the RPC Dump tool, visit the following Microsoft Web site:

http://www.microsoft.com/downloads/details.aspx?displaylang=en&familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd

Keywords: kbinfo KB908472

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.