BlogEngine.NET js.axd bug

in Develop

在gmail的垃圾邮件里找到一封标题为《网站有漏洞哦》的邮件,好奇地打开邮件,内容是:

详细的参考:
http://blog.119797.com/post/BlogEngine-fix-js-Download-bug.aspx



by benben
:)

由于涉及到链接,不敢用ie,用firefox打开一看,是一篇名为BlogEngine.NET js.axd 模块漏洞及修复的文章,往下一看,果然在js.axd文件有致命的bug,该bug可以让攻击者拿到用户名及密码,有了这些,等于完全操纵了你的blog程序,可怕!

Bug分析:

js.axd文件是一个实现了IHttpHandler接口的处理文件,它的作用是将指定的js文件进行压缩与缓存,该文件需要传递一个path参数,如:js.axd?path=xxx.js,js.axd就会将xxx.js文件中的空白去掉以减小js文件的体积。

部分方法:

</p>
<p>private static string RetrieveLocalScript(string file)<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; string path = HttpContext.Current.Server.MapPath(file);<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; string script = null;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; using (StreamReader reader = new StreamReader(path))<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; script = reader.ReadToEnd();<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; HttpContext.Current.Cache.Insert(file, script, new CacheDependency(path));<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return script;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p>

但这里出现的bug就是前面所提到的,没有对传入的file文件格式做判断

访问js.axd?path=/web.config时,居然将我的web.config文件内容原样读取出来

继续访问js.axd?path=app_data/users.xml,结果同上,将这个xml文件的内容一行不漏地读取了,而该文件中存储的正是帐户信息!!

修补方法:

在private static string RetrieveLocalScript(string file)方法及private static string RetrieveRemoteScript(string file)方法中添加以下代码:

//判断是不是请求.js文件,如果不是则抛出安全性异常。

if (!file.EndsWith(".js", StringComparison.OrdinalIgnoreCase))
            {
                throw new System.Security.SecurityException("No access");
            }

再访问上述地址时:

 

 

问题基本得到修复,官方也就此bug发布了更新版本http://www.dotnetblogengine.net/post/Critical-Security-Patch-Available.aspx

使用dotnetblogengine的朋友一定要打此补丁,否则欲哭无泪了

在此,谢谢给我邮件的朋友,他的blog地址:

http://blog.119797.com/

10 Comments

10 Comments

  1. :p
    谢谢你的消息,我更新程序了。

  2. 早上浏览官方网站时发现发布了补丁,原来是从你这里发现的啊

  3. 呵呵,官方远程调用js那个没处理,可以欺骗跨站的!建议把远程调用js的,干掉,这功能没用吧!

  4. 由于涉及到链接,不敢用ie,用firefox打开一看

    我有那么坏嘛?:cry:

  5. @benben:
    网络啊~~~
    所以小心为妙咯^_^

  6. benben 好人呀,赞一个~

  7. 很好 支持一下!!!!!!!!!

  8. 如果不介意,我们做个链接吧。我已经把您的加了,我是个.net新手!才毕业的。呵呵!

Leave a Reply

Using Gravatars in the comments - get your own and be recognized!

XHTML: These are some of the tags you can use: <a href=""> <b> <blockquote> <code> <em> <i> <strike> <strong>