邪恶八进制信息安全团队技术讨论组's Archiver

金州 2006-2-20 08:46

[转载]对ikonboard v2.1.9物理路径泄露的分析

文章作者:analysist

ikonboard是当前比较流行的论坛,目前提供下载的最新版本是ikonboard v2.1.9,可以从[url]http://www.ikonboard.com/downloads/ib219.zip[/url]
下载。

   旧版本的ikonboard 存在一个泄露系统文件的漏洞,主要是没有过滤掉".."和"/",再结合"poison null-byte", 我们可以通过类似
下面的形式访问"/etc/passwd"文件:

   [url]http://www..notfound.org/cgi-bin/ikonboard/help.cgi?helpon=../../../../../etc/passwd%00[/url]

   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 = ;
   close (FILE);

   乍一看,似乎没有什么问题。如果文件存在;一切OK。如果文件不存在,就会显示错误信息"Cannot locate the required files",
我们看看实际情况:

   输入地址:[url]http://www.notfound.org/ib219/cgi-bin/help.cgi?helpon=12345678[/url],返回信息:

   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 ([email]webmaster@notfound.org[/email]), 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函数还有一个作用,它还会在错误信息的后面附加一些调试信息,这主要是为了调试的方便。

   那么,是不是有什么参数可以去掉这些调试信息呢?毕竟很多时候这些调试信息会给我们带来麻烦。我在[url]http://www.perl.com/[/url]没有
找到答案,但是我却在那里找到了一个抑制错误信息的方法。

   我们来看:
   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的结果:
   输入地址:[url]http://www.notfound.org/ib219/cgi-bin/help.cgi?helpon=12345678[/url],返回信息:

   Content-type: text/html
   Software error:
   Cannot locate the required files.
   For help, please send mail to the webmaster ([email]webmaster@notfound.org[/email]), 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

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

lanker 2006-2-21 08:20

好久都没见过 analysist 的文章了  又学东西了 呵呵
这也是篇老文章吧

页: [1]
© 1999-2008 EvilOctal Security Team