Visit our newest sister site!
Hundreds of free aircraft flight manuals
Civilian • Historical • Military • Declassified • FREE!


TUCoPS :: Web :: Apache :: b06-4166.htm

CGI Script Source Code Disclosure Vulnerability in Apache for Windows



CGI Script Source Code Disclosure Vulnerability in Apache for Windows
CGI Script Source Code Disclosure Vulnerability in Apache for Windows



ADVISORY NAME:=0D
CGI Script Source Code Disclosure Vulnerability in Apache for Windows=0D
=0D
VULNERABLE SYSTEMS:=0D
The vulnerability has been verified on Apache 2.2.2 running on Microsoft Windows XP, Version 2002, Service Pack 2.=0D
=0D
FOUND BY:=0D
Susam Pal=0D
=0D
FOUND ON:=0D
8th August, 2007=0D
=0D
VULNERABILITY TYPE:=0D
Information Disclosure=0D
=0D
SYSTEM DESCRIPTION:=0D
Apache HTTPD is a web server that can run on many platforms to provide web-service. The basic server configuration is controlled by the file 'httpd.conf'. The 'DocumentRoot' directive controls which directory is considered to be root for serving documents. For instance:-=0D
=0D
DocumentRoot "/home/webmaster/site/docroot/"=0D
=0D
In the above example, a request to 'http://[target]/foo.html' would fetch the 'foo.html' page from '/home/webmaster/site/docroot/' directory of the server.=0D 
=0D
The 'ScriptAlias' directive controls which directory contains server scripts. The following is an example of a typical 'ScriptAlias' directive:-=0D
=0D
ScriptAlias /cgi-bin/ "/home/webmaster/site/docroot/cgi-bin"=0D
=0D
If a user makes a direct request to 'http://[target]/cgi-bin/foo' where 'cgi-bin' is the scripts' directory and 'foo' is the script, the user gets the output of the 'foo' script. In a secure system, the user is not supposed to view the source-code of 'foo' by making an HTTP GET request.=0D 
=0D
VULNERABILITY DESCRIPTION:=0D
Usually the following directives in 'httpd.conf' file can be considered safe for Unix/Linux (assuming that other directives haven't been insanely edited):-=0D
=0D
# Sample Safe Configuration for Unix/Linux=0D
DocumentRoot "/home/webmaster/site/docroot/"=0D
ScriptAlias /cgi-bin/ "/home/webmaster/site/docroot/cgi-bin"=0D
=0D
But a similar configuration isn't safe in Windows. For instance:-=0D
=0D
# Sample Unsafe Configuration for Windows=0D
DocumentRoot "C:/Documents and Settings/webmaster/site/docroot"=0D
ScriptAlias /cgi-bin/ "C:/Documents and Settings/webmaster/site/docroot/cgi-bin/"=0D
=0D
If the scripts' directory (represented by 'ScriptAlias') lies inside the document-root directory (represented by 'DocumentRoot') and the name of the script-alias is same as that of the directory containing the scripts then the attacker can obtain the source code of the CGI scripts by making a direct request to 'http://[target]/CGI-BIN/foo'.=0D 
=0D
Apache web-server checks for the exact case mentioned in the 'ScriptAlias' directive before deciding whether the directory mentioned in the HTTP GET request is a scripts' directory or not. So, when Apache web-server receives a request for a file in 'CGI-BIN' directory, it finds it to be different from 'cgi-bin' mentioned in the 'ScriptAlias' directive. So, it concludes that it is not a script-alias. Then it checks for 'CGI-BIN' directory in the document-root directory and finds it since file-names and directory-names are not case-sensitive on Windows. So, it simply sends the content of the 'foo' file as the HTTP response. It doesn't execute the 'foo' script because it isn't found in a directory pointed by script-alias.=0D
=0D
EXPLOIT:=0D
The vulnerability can be exploited by making a direct request to http://[target]/CGI-BIN/foo=0D 
=0D
PREVENTION:=0D
1. Choosing a name for the 'ScriptAlias' different from the name of the actual directory will reduce the risk. For instance,=0D
=0D
# Sample Configuration for Reducing Risk=0D
DocumentRoot "C:/Documents and Settings/webmaster/site/docroot"=0D
ScriptAlias /cgi-bin/ "C:/Documents and Settings/webmaster/site/docroot/sdy1x9y/"=0D
=0D
The attacker can still get the source code by making a direct request to 'http://[target]/sdy1x9y/foo' if the attacker can somehow determine that the 'ScriptAlias /cgi-bin/' refers to the 'sdy1x9y' directory.=0D 
=0D
2. A more secure preventive measure would be to place the scripts folder outside the 'DocumentRoot' directory and then form a 'ScriptAlias' to it. For instance,=0D
=0D
# Sample Configuration for Increased Security=0D
DocumentRoot "C:/Documents and Settings/webmaster/site/docroot"=0D
ScriptAlias /cgi-bin/ "C:/Documents and Settings/webmaster/site/cgi-bin"=0D
=0D
DISCLAIMER:=0D
The information, codes and exploits in this advisory should be used for research, experimentation, bug-fixes and patch-releases only. The author shall not be liable in any event of any damages, incidental or consequential, in connection with, or arising out of this advisory, or its codes and exploits.=0D
=0D
CONTACT INFORMATION:=0D
For more information, please contact:- =0D
=0D
Susam Pal=0D
Infosys Technologies Ltd.=0D
Survey No. 210, Manikonda Village=0D
Lingampally, Rangareddy District=0D
Hyderabad, PIN 500019=0D
India=0D
Phone No.: +91-9985259521=0D
Email: susam.pal@gmail.com=0D 
http://susampal.blogspot.com/=0D 
http://securecoding.blogspot.com/=0D 


TUCoPS is optimized to look best in Firefox® on a widescreen monitor (1440x900 or better).
Site design & layout copyright © 1986-2014 AOH