动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   Cgi/Perl → 阅读文章

 对ikonboard v2.1.9物理路径泄露的分析

作者来源: 
阅读 1295 人次 , 2006-3-29 4:02:00 

ikonboard是当前比较流行的论坛,目前提供下载的最新版本是ikonboard v2.1.9,可以从http://www.ikonboard.com/downloads/ib219.zip下载。
旧版本的ikonboard 存在一个泄露系统文件的漏洞,主要是没有过滤掉“..”和“/”,再结合“poison null-byte”,我们可以通过类似下面的形式访问“/etc/passwd”文件:
http://www..notfound.org/cgi-bin/ikonboard/help.cgi?helpon=../../../../../etc/passwd%00
ikonboard v2.1.9已经修正了这个问题,把用户输入的“..”和“/”都过滤掉了,但是我发现它存在着物理路径泄露的问题。问题还是出在help.cgi上,相关程序代码如下:

#过滤“..”和“/”
$inhelpon =~ s/\///g;
$inhelpon =~ s/\.\.//g;

#读取指定的文件
$filetoopen = "$ikondir" . "help/$inhelpon.dat";
$filetoopen = &stripmeta($filetoopen);
open (file, "$filetoopen") or die "cannot locate the required files";
@helpdata = <file>;
close (file);

乍一看,似乎没有什么问题。如果文件存在;一切ok。如果文件不存在,就会显示错误信息“cannot locate the required files”。
我们看看实际情况:
输入地址:http://www.notfound.org/ib219/cgi-bin/help.cgi?helpon=12345678
返回信息:

content-type: text/html
software error:
cannot locate the required files at c:\apache\htdocs\ib219\cgi-bin\help.cgi line 100.
for help, please send mail to the webmaster (webmaster@notfound.org), giving this error message and the time and date of the error.

好象结果和我们想象的不一样哦,现实与梦想总是有距离的!:(
通过分析,我们知道问题出在第99行,即:
open (file, "$filetoopen") or die "cannot locate the required files";
open函数应该没有什么问题,看来是die函数的问题了。用过perl的人应该知道,die函数的作用是显示错误信息,然后退出。但是,die函数还有一个作用,它还会在错误信息的后面附加一些调试信息,这主要是为了调试的方便。
那么,是不是有什么参数可以去掉这些调试信息呢?毕竟很多时候这些调试信息会给我们带来麻烦。我在http://www.perl.com/没有找到答案,但是我却在那里找到了一个抑制错误信息的方法。
我们来看:
test1.pl
#!/usr/bin/perl
open(“c:/123”) || die “file open error!”;

c:\>perl test1.pl
file open error! at c:\test1.pl line 3.

c:\>
我们再看:
test2.pl
#!/usr/bin/perl
open(“c:/123”) || die “file open error!\n”;

c:\>perl test2.pl
file open error!

c:\>
good!显然满足了我们的要求,我们再来看看修改了help.cgi的结果:
输入地址:http://www.notfound.org/ib219/cgi-bin/help.cgi?helpon=12345678
返回信息:

content-type: text/html
software error:
cannot locate the required files.
for help, please send mail to the webmaster (webmaster@notfound.org), giving this error message and the time and date of the error.

perfect,we got it!

发现了问题,解决了问题,我们再来看看是不是还有其它的地方也是同样的问题。经过查找,研究,排除,确认,又发现了以下具有相同问题的cgi程序:

/ib219/cgi-bin/checklog.cgi
/ib219/cgi-bin/forums.cgi
/ib219/cgi-bin/topic.cgi

好了,到此为止,希望用perl开发cgi的程序员能够从中得到一些启示,如果您对本文的观点有什么疑问,请直接给我发信!

声明:
本文测试环境是windows 2000+apache 1.3.20+active perl 5.6.1

参考资料:
1. http://www.perl.com/pub/doc/manual/html/pod/perlfunc/die.html
2. http://www.securityfocus.com/vdb/bottom.html?vid=2471

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:WEB服务CGI接口漏洞分析
· 下一篇:使用脚本下载网页
· cgi学习简明教程
· CGI教学:CGI安全问题(三)
· 联网调试CGI程序心得
· 跟我学Perl(5)
· perl中的变量插值


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077