Friday, August 31, 2012

How to remove or modify "Server" http header in IIS 7 / IIS 7.5?


Server: Microsoft-IIS/7.0


Few methods are used to prevent IIS from sending the identification of the server to a client. This prevents the client from identifying the server hence delaying easy break through into the server.


One such method is writing a custom module (code given below) and saving the Class file under App_Code folder


Code from Stefan Gossner





using System; 
using System.Text; 
using System.Web; 

namespace StefanG.ServerModules 
{ 
    public class CustomServerHeaderModule : IHttpModule 
    { 
        public void Init(HttpApplication context) 
        { 
            context.PreSendRequestHeaders += OnPreSendRequestHeaders; 
        } 

        public void Dispose() 
        { } 

        void OnPreSendRequestHeaders(object sender, EventArgs e) 
        { 
            // modify the "Server" Http Header
            HttpContext.Current.Response.Headers.Set("Server", "My Test Server"); 
        } 
    } 
}



Then, go to IIS 7 server and double click on "Modules". Then click "Add Managed Module". A dialog will open asking you to enter Name and Type. Enter a strong name for the module and choose the module (the one that we saved under App_Code) from the drop down and click OK. Restart the server.


Thats it! When you browse the website, Server identification will now be removed or modified based on the code in your module.


For IIS 6 UrlScan needs to be setup.

Thursday, August 30, 2012

How to remove ASP.Net version header from IIS 7 , IIS 7.5?

How to remove ASP.Net version header from IIS 7 , IIS 7.5?
Add the following line to web.config within System.web node

<system.web>
<httpRuntime enableVersionHeader="false" />
</system.web>

Friday, March 23, 2012

How to check IP PING results automatically in Windows?

Write the following command in a file and save it as a .bat file in Windows.

FOR /L %i IN (1,1,20) DO ping -n 1 192.168.1.%i | FIND /i "Reply">> d:\ipreplies.txt

Run the .bat file and it will save the results to "d:\ipreplies.txt"

In the above FOR loop we check for the usage of IP's starting from 192.168.1.1 incremented by 1 to 192.168.1.20.

Thursday, March 8, 2012

How to open a set of ports in windows firewall?

Go to Control Panel > Windows Firewall (or type firewall.cpl in the Run prompt). Under the Exceptions tab you can add the program or port number to which you would want to allow access.

If you want to add multiple ports there is no option for you to open multiple ports (port range) with a simple addition of a filter.

To do this we need to type the following in the command prompt (Run > cmd):

FOR /L %I IN (9000,1,9100) DO netsh firewall add portopening TCP %I "Site Ports" %I

The ports will be incremented by 1 from 9000 until 9100.

In windows 2008 it is much easier than this. You can easily add a port range in the Firewall filter rules