Aug 28, 2008
[AS] Apache Tomcat Directory Traversal Vulnerability を再現してみる。
Apache Tomcat の Directory Traversal 脆弱性が報告されている。 報告だけではイマイチ分かりにくいので再現実験を行ってみた。
- SecurityForcus - Apache Tomcat Directory Traversal Vulnerability
- http://www.securityfocus.com/archive/1/archive/1/495318/100/0/threaded
- CVE-2008-2938
- http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-2938
脆弱性の内容
SecurityForcus によると、
As Apache Security Team, this problem occurs because of JAVA side. If your context.xml or server.xml allows 'allowLinking'and 'URIencoding' as 'UTF-8', an attacker can obtain your important system files.(e.g. /etc/passwd)とのこと。allowLinking が true で且つ URIEncoding が UTF-8 に設定されている Apache Tomcat(〜6.0.16) で再現するそうだ。
Exploit
If your webroot directory has three depth(e.g /usr/local/wwwroot), An attacker can access arbitrary files as below. (Proof-of-concept)
http://www.target.com/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/foo/bar
allowLinking と URIEncoding
allowLinking と URIEncoding は、Apache Tomcat のドキュメントによると
- Apache Tomcat Configuration Reference - The HTTP Connector
- http://tomcat.apache.org/tomcat-6.0-doc/config/http.html
URIEncoding
This specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, ISO-8859-1 will be used.
- Apache Tomcat Configuration Reference - The Context Container
- http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
allowLinkingというものだそうだ。
If the value of this flag is true, symlinks will be allowed inside the web application, pointing to resources outside the web application base path. If not specified, the default value of the flag is false.
NOTE: This flag MUST NOT be set to true on the Windows platform (or any other OS which does not have a case sensitive filesystem), as it will disable case sensitivity checks, allowing JSP source code disclosure, among other security problems.
脆弱性の再現
Apache Tomcat 6.0.16 を使用して脆弱性の再現実験を行った。 手順は以下の通り。
- Apache Tomcat 6.0.16 をインストール
- $CATALINA_HOME/conf/server.xml を編集
- $CATALINA_HOME/conf/context.xml を編集
- Apache Tomcat 6.0.16 を起動
- Web ブラウザより Apache Tomcat 6.0.16 にアクセスし、脆弱性を再現
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8" />
</Service>
</Server>
context.xml はこんな感じ
Web ブラウザで http://localhost:8080/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd にアクセスしたところ、脆弱性が再現できた。$CATALINA_HOME/conf/context.xml <?xml version='1.0' encoding='utf-8'?> <Context allowLinking="true"> </Context>
もう少し調べてみる
allowLinking, URIEncodign がそれぞれ設定されていない場合はどうなるか試してみた。
![[URIEncodingを設定しない場合]](/blog/entries/AS/20080828_01/no-uriencoding.png)
どちらも脆弱性は再現できなかった。
URIEncoding を UTF-16 にした場合はどうなるか試してみた。
![[URIEncodingをUTF-16にした場合]](/blog/entries/AS/20080828_01/utf-16.png)
脆弱性は再現できなかった。
%c0%ae って何?
脆弱性が再現できたところで一つ気になるのは、%c0%ae が何者なのか、ということ。
System.out.println("" + URLDecoder.decode("%c0%ae", "UTF-8"));
.
まぁ想像通りの結果。
要するに、http://localhost:8080/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd は Apache Tomcat 内部で http://localhost:8080/../../../../etc/passwd と解釈されるわけだ。
で、何らかの原因で(「Java 側の問題」と書いてあるが、何だろう?)パスがチェックをすり抜けてファイルアクセスに使用されてしまう、ということだろう。
結論
とにかく Apache Tomcat を脆弱性が修正されている 6.0.18 以上にバージョンアップする必要がある。 急げ。急げ。
Aug 25, 2008
[Maven] Maven2 で Apache Tomcat の context.xml を WAR に追加する方法
Maven2 で Apache Tomcat の context.xml を WAR に追加する方法をメモ。
何故メモするかというと、現時点(2008/08/25)では普通に設定するだけでは動作しないから。
想定された通りの挙動であれば、pom.xml に
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<containerConfigXML>src/main/webapp/META-INF/context.xml</containerConfigXML>
</configuration>
</plugin>
</plugins>
</build>
</project>
と設定すれば src/main/webapp/META-INF/context.xml が WAR の META-INF/context.xml として格納される。
ところが、この containerConfigXML というオプション、maven-war-plugin のバグにより現時点では動作しない。
- Option containerConfigXML doesn't work
- http://jira.codehaus.org/browse/MWAR-120?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-alpha-2</version>
<configuration>
<containerConfigXML>src/main/webapp/META-INF/context.xml</containerConfigXML>
</configuration>
</plugin>
</plugins>
</build>
</project>
maven-war-plugin 2.1-alpha-2 のリリースノートはこちら。
- [ANN] Maven War Plugin 2.1-alpha-2 Released
- http://mail-archives.apache.org/mod_mbox/maven-announce/200808.mbox/%3Cadba96190808140822t6d87b6c2k9fa0d9ee444d5a9c@mail.gmail.com%3E
Aug 24, 2008
[Maven] Maven2 で Test*.java をテストケースとして認識させない方法
Maven2 ではビルドの際に **/Test*.java、**/*Test.java、**/*TestCase.java をテストケースとして認識する。 Test*.java はテストケースとして使用したくないので、設定を変更してみた。
設定の変更方法
pom.xml に以下を追加する。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Aug 19, 2008
[Misc] HP System Management Homepage を CentOS 5.2 にインストールしてみた。
- HP System Management Homepage: Installation Guide
- http://docs.hp.com/en/438862-009/index.html
- HP System Management Homepage for Linux (x86)
- http://h20000.www2.hp.com/bizsupport/TechSupport/SoftwareDescription.jsp?lang=en&cc=us&prodTypeId=15351&prodSeriesId=1121486&prodNameId=3288144&swEnvOID=4006&swLang=8&mode=2&taskId=135&swItem=MTX-1b359c812b2e419ba234be0117
- System Management Homepageによるハードウェア障害監視
- http://www.thinkit.co.jp/free/article/0611/13/2/
HP SMH のインストール
HP のサイトから System Management Homepage for Linux (hpsmh-2.1.12-200.i386.rpm) をダウンロードする。 その後、RPM を使用して普通にインストール。 ・・・するが、やはり駄目。
# rpm --checksig ./hpsmh-2.1.12-200.i386.rpm ./hpsmh-2.1.12-200.i386.rpm: sha1 md5 OK # rpm -i --test ./hpsmh-2.1.12-200.i386.rpm # rpm -ivh ./hpsmh-2.1.12-200.i386.rpm Preparing... ########################################### [100%] This Red Hat Linux distribution is not supported. error: %pre(hpsmh-2.1.12-200.i386) scriptlet failed, exit status 1 error: install: %pre scriptlet failed (2), skipping hpsmh-2.1.12-200 #
ディストリビューションがサポートされていないということなので、ディストリビューションを詐称してみる。 今度は上手くいった。
# cp /etc/redhat-release /etc/redhat-release.original # vi /etc/redhat-release # diff /etc/redhat-release.original /etc/redhat-release 1c1 < CentOS release 5.2 (Final) --- > Red Hat Enterprise Linux AS release 5 # rpm -ivh ./hpsmh-2.1.12-200.i386.rpm Preparing... ########################################### [100%] Creating hpsmh user and group... 1:hpsmh ########################################### [100%] ********************************************************** * System Management Homepage installed successfully with * * default configuration values. To change the default * * configuration values, type the following command at * * the root prompt: * * * * perl /usr/local/hp/hpSMHSetup.pl * * * ********************************************************** Stopping hpsmhd: Starting hpsmhd: hpsmhd: Could not determine the server's fully qualified domain name, using 10.1.31.33 for ServerName [ OK ] # rm /etc/redhat-release rm: remove regular file `/etc/redhat-release'? yes # mv /etc/redhat-release.original /etc/redhat-release
HP SMH の設定
HP SMH の設定はインストール時に表示された通り以下のスクリプトで行う。
# perl /usr/local/hp/hpSMHSetup.pl
HP SMH にアクセス
Web ブラウザで http://localhost:2381/ にアクセスする。



