综述:有几种办法可以暴露html" class="wordstyle">JSP代码,不过经过大量测试,这和WEB SERVER的配置有绝对的关系,就拿IBM Websphere Commerce Suite而言,还有别的方法看到html" class="wordstyle">JSP源代码,但相信是IBM HTTP SERVER的配置造成的。
如果想发现html" class="wordstyle">JSP暴露源代码的BUG的话,首先需要了解html" class="wordstyle">JSP的工作原理。
html" class="wordstyle">JSP和其它的html" class="wordstyle">PHP、html" class="wordstyle">ASP工作机制不一样,虽然它也是一种web编程语言。首次调用html" class="wordstyle">JSP文件其实是执行一个编译为Servlet的过程。注意我们就要在这上边做文章,明白吗?我们要干的事情是,让html" class="wordstyle">JSP在编译前被浏览器当作一个文本或其它文件发送给客户端,或在html" class="wordstyle">JSP装载的时候不去执行编译好的Servlet而直接读html" class="wordstyle">JSP的内容并发送给客户端。
明白了道理及所要达到的目的就好下手了,仔细观察调用及返回过程可以发现:html" class="wordstyle">JSP被编译为了Servlet保存在指定的目录下,如:html" class="wordstyle">jsp>http://www.x.com/lovehacker/index.html" class="wordstyle">jsp很可能存放在X:\IBM\WAServer\temp\default_host\default_app\pagecompile\_lovehacker_index_xhtml" class="wordstyle">jsp.class,这是已经编译过的index.html" class="wordstyle">jsp。_lovehacker_index_xhtml" class="wordstyle">jsp.class显然是我们不需要的文件,而且我们得到它的可能性也不大,我们要干的是不去执行_lovehacker_index_xhtml" class="wordstyle">jsp.class而是直接读index.html" class="wordstyle">jsp的内容。
据分析最初的xxx.html" class="wordstyle">JSP暴露源代码也是因为前边的这种想法造成的,本来目录中存放了一个_xxx_xhtml" class="wordstyle">jsp.class,但访问xxx.html" class="wordstyle">JSP本来是个合法的请求,而又找不到对应的Servlet所以就把xxx.html" class="wordstyle">JSP当做一个文本或其它文件发送给了用户。
也许这是因为IBM HTTP SERVER配置不当造成的,但相信如果能成功的话,会有一种成就感,很爽的哦!
顺便说一下暴露文件存放真实路径可能会带来的危害:
1.先会让入侵者了解磁盘配置情况 2.明的入侵者甚至可以分析出管理员的水平高低 3.为入侵者修改你的首页提供了方便(起码不用在找你的WEB目录在那个磁盘了) 4.可能被利用一些其它的CGI的漏洞查找到Web目录下的文件如XX.html" class="wordstyle">ASP、XX.html" class="wordstyle">JSP、XX.html" class="wordstyle">PHP等
html" class="wordstyle">JSP安全问题主要有哪几方面?
本节重点在于对html" class="wordstyle">jsp安全问题进行分类阐述和提出解决的建议,所以每种类型的安全问题只采用了一个例子,对于其它各种漏洞的具体细节如涉及到何种软件版本何种操作系统等就不一一进行阐述了,有兴趣的读者可以到html" class="wordstyle">jsp爱好者(html" class="wordstyle">jspbbs.yeah.net>http://html" class="wordstyle">jspbbs.yeah.net)或者国外的安全站点(http://www.securityfocus.com)进行查看和参考。
根据目前已经发现的html" class="wordstyle">jsp安全问题,不妨将它们分为以下几类,源代码暴露类、远程程序执行类和其他类别, 下面来看看具体的东西吧。
一、源代码暴露类
源代码暴露类别主要指的是程序源代码会以明文的方式返回给访问者。 我们知道不管是html" class="wordstyle">jsp还是html" class="wordstyle">asp、html" class="wordstyle">php等动态程序都是在服务器端执行的,执行后只会返回给访问者标准的html 等代码。这是理论上的东西,实际运行起来由于服务器内部机制的问题就有可能引起源代码暴露的漏洞,简单的例子只要在程序文件名后加几个简单的字符就可能获得程序代码,如常见微软html" class="wordstyle">asp 的global.asa+.htr、XXXX.html" class="wordstyle">asp%81等等漏洞。
1.添加特殊后缀引起html" class="wordstyle">jsp源代码暴露
在html" class="wordstyle">jsp中也存在着和html" class="wordstyle">asp这些漏洞类似的问题,如IBM Websphere Application Server 3.0.21、BEA Systems Weblogic 4.5.1、Tomcat3.1等html" class="wordstyle">jsp文件后缀大写漏洞;html" class="wordstyle">jsp 文件后加特殊字符如Resin1.2的%82、../漏洞;ServletExec的%2E、+漏洞等等。
例子:举个老一点的html" class="wordstyle">JSP大写例子,Tomcat3.1下在浏览器中本来是html" class="wordstyle">jsp>http://localhost:8080/inde.html" class="wordstyle">jsp,可以正常解释执行,但是如果将inde.html" class="wordstyle">jsp改为inde.html" class="wordstyle">JSP或者inde.html" class="wordstyle">Jsp等等试试看,你会发现浏览器会提示你下载这个文件,下载后源代码可以看个一干二净。
原因:html" class="wordstyle">jsp是大小写敏感的,Tomcat只会将小写的html" class="wordstyle">jsp后缀的文件当作是正常的html" class="wordstyle">jsp文件来执行,如果大写了就会引起Tomcat将index.html" class="wordstyle">JSP当作是一个可以下载的文件让客户下载。老版本的WebLogic、WebShpere等都存在这个问题,现在这些公司或者发布了新版本或者发布了补丁解决了这问题。
解决办法:一是在服务器软件的网站上下载补丁;因为作者以前用过html" class="wordstyle">asp 一段时间,接触了很多IIS的漏洞,它的有效解决方法是去掉不必要的映射如htr、htx等,在html" class="wordstyle">jsp 中我们同样可以参考IIS的解决方法,不同的是不是去掉而是添加映射,方法为在服务器设置中添加一些映射如.html" class="wordstyle">JSP 、.html" class="wordstyle">Jsp、.html" class="wordstyle">jsp%2E等,将他们映射到一个自己写的servlet,这个Servlet的唯一功能就是将请求导向一个自定义的类似404 not found的出错页面,不同的服务器设置的地方也不同,请参考相应的文档。第二种解决方法可以在没有补丁的时候采用。
2.插入特殊字符串引起html" class="wordstyle">jsp源代码暴露
还有一种是插入特殊字符串引起的漏洞,BEA WebLogic Enterprise 5.1文件路径开头为 "/file/" 的漏洞、IBM WebSphere 3.0.2的"/servlet/file/"文件开头漏洞等等。
例子:如IBM WebSphere 3.0.2中,如果一个请求文件的 URL为"login.html" class="wordstyle">jsp":websphere/login.html" class="wordstyle">jsp>http://site.running.websphere/login.html" class="wordstyle">jsp,那么访问websphere/servlet/file/login.html" class="wordstyle">jsp>http://site.running.websphere/servlet/file/login.html" class="wordstyle">jsp将看到这个文件的源代码。
原因:因为IBM WebSphere 3.0.2是调用不同的 servlets 对不同的页面进行处理,如果一个请求的文件是未进行注册管理的,WebSphere 会使用一个默认的 servlet 调用。如果文件路径以"/servlet/file/"作开头这个默认的 servlet 会被调用这个请求的文件会未被分析或编译就显示出来。
解决方法:在服务器软件的网站下载最新的补丁。
3.路径权限引起的文件html" class="wordstyle">jsp源代码暴露
我们知道,大部分的html" class="wordstyle">jsp应用程序在当前目录下都会有一个WEB-INF目录,这个目录通常存放的是JavaBeans编译后的class 文件,如果不给这个目录设置正常的权限,所有的class就会曝光。
例子:如果采用的是Apache1.3.12加上第三方html" class="wordstyle">jsp软件形式的WEB服务器,因为Apache1.3.12默认的设置是可以读取目录的,如果程序在websphere/login.html" class="wordstyle">jsp>http://site.running.websphere/login.html" class="wordstyle">jsp,只要修改一下websphere/WEB-INF/>http://site.running.websphere/WEB-INF/所有这个目录下以及这个目录下的子目录 |
|