iOS_の画像

続・Metasploitable3のdockerコンテナ化 01_mysql

前回、コンテナにして動くことは確認できたので、各種サービスも同様に動作できることを確認していこうと思ってますが、まずはDBがちゃんと動かないといろいろ他にも動かないかと思うので、mysqlをVirtualBoxのVMの時と同様に動くようにしてみようと思います。環境も前回同様にMacでやっています。ちなみにRaspbianの起動をやった後に、Windows環境でやってほしいという要望をいただいたので、Windowsでの検証も後日UP予定です。

まずはコンテナ起動させます。前回作ったイメージを使います。webアプリからDB接続も確認しないとなので、本当はこの辺のネットワーク周りはもっとちゃんと組みたいんですが、MacとかWinだといろいろ面倒だし無理やり感が出てしまうので、また今度。

$ docker run -it --rm -d -p 10080:80 --name metasploitable3test r/metasploitable3 /bin/bash
$ docker exec -it metasploitable3test /bin/bash

rmとかdとか無くても問題無いですが、私はこうやったというだけなので、これ以降はコンテナに入っての操作ということで。とりあえず何も考えずにmysqlを立ち上げて接続してみます。

root@f3ba59b688c8:/# service mysql start
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
* /etc/init.d/mysql: WARNING: /etc/mysql/my.cnf cannot be read. See README.Debian.gz
* Starting MySQL database server mysqld                                                                                                                    [ OK ] 
* Checking for tables which need an upgrade, are corrupt or were 
not closed cleanly.
root@f3ba59b688c8:/# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.5.60-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

mysql> exit
Bye

mysqlは立ち上がってますが、明らかにDBが足りないみたいなので、Webアプリで使っている/var/www/html/payroll_app.phpの冒頭部分を見てみると以下のようになってます。

<?php

$conn = new mysqli('127.0.0.1', 'root', 'sploitme', 'payroll');
if ($conn->connect_error) {
   die("Connection failed: " . $conn->connect_error);
}
?>

rootユーザとそのパスワード、そんで「payroll」ってDBに接続に行ってるみたいなので、少なくともそのデータがどっかにあるはず。/var/libを見ると、mysqlフォルダとmysql-defaultフォルダがありますが、mysql-defaultの中にpayrollとかdrupalとかがあったので、どうやらこっちがDBの本体だっ!・・ってことで、設定変えたりしてこっち見るようにしてあげます。my.cnfでデータディレクトリ指定が一番いいかなと思いますが、コンテナ化の最初から言ってますがとりあえず動くのがわかれば良いので、今回はフォルダ名変更しちゃってこんな↓状態にしてみます。mysqlフォルダはグループ所有権がrootについてたので、chownでmysqlにしておきました。

root@f3ba59b688c8:~# ls -la /var/lib/mysql
total 36900
drwxr-x--- 6 mysql mysql     4096 Feb  9 12:27 .
drwxr-xr-x 1 root  root      4096 Feb  9 12:26 ..
drwx------ 2 mysql mysql     4096 Jul 29  2018 drupal
-rw-rw---- 1 mysql mysql     1398 Feb  9 12:27 f3ba59b688c8.err
-rw-rw---- 1 mysql mysql        5 Feb  9 12:27 f3ba59b688c8.pid
-rw-rw---- 1 mysql mysql  5242880 Feb  9 12:28 ib_logfile0
-rw-rw---- 1 mysql mysql  5242880 Jul 29  2018 ib_logfile1
-rw-rw---- 1 mysql mysql 27262976 Feb  9 12:28 ibdata1
drwx------ 2 mysql mysql     4096 Jul 29  2018 mysql
drwx------ 2 mysql mysql     4096 Jul 29  2018 payroll
drwx------ 2 mysql mysql     4096 Jul 29  2018 performance_schema

mysqlを再起動してみます。

oot@f3ba59b688c8:/var/lib/mysql# service mysql restart
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
* Stopping MySQL database server mysqld                                                                                                                    [ OK ] 
* /etc/init.d/mysql: WARNING: /etc/mysql/my.cnf cannot be read. See README.Debian.gz
* Starting MySQL database server mysqld                                                                                                                    [ OK ] 
* Checking for tables which need an upgrade, are corrupt or were 
not closed cleanly.

一応起動したみたいなので、DBを確認してみます。

root@f3ba59b688c8:/var/lib/mysql/mysql# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.60-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| drupal             |
| mysql              |
| payroll            |
| performance_schema |
+--------------------+
5 rows in set (0.00 sec)

mysql> exit
Bye

パスワードはpayroll_app.phpに書いてあったので接続してみて、DBが動いてるのが確認できました。apacheも立ち上げてみて、Webから確認してみようと思います。

# service apache2 start
* Starting web server apache2                                                                                                                                     AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.4. Set the 'ServerName' directive globally to suppress this message
* 

コンテナなのでホスト名のエラーが出ちゃってますが、起動はしてます。ので、ホスト(MacOS)側からアクセスしてみると・・・

スクリーンショット 2020-02-09 23.22.42

スクリーンショット 2020-02-09 23.23.14

スクリーンショット 2020-02-09 23.23.34

無事アクセスできました。phpやapache、そしてmysqlが無事動かせることはわかりました。ついでなので、ZAPで脆弱性検査とかやってみます。

スクリーンショット 2020-02-09 23.28.03

いい感じで脆弱性が出てきました。

スクリーンショット 2020-02-10 0.22.37

せっかくなので攻撃してみる。・・・あぶない台詞だな・・・。

スクリーンショット 2020-02-10 0.25.00

無事(?)SQLインジェクションが成功してUserとかSalaryとか見えちゃいました。・・・スターウォーズ?ですよね。一回も見たことありませんすいません・・・。

Dockerfileとか起動用スクリプト作るのであればmy.cfgをいじったほうが良さそうですが、動作検証としては十分かと思います。

この記事が気に入ったらサポートをしてみませんか?