LoginSignup
2
2

More than 5 years have passed since last update.

vuls×EC2の公式日本語チュートリアルで詰まったので備忘録

Last updated at Posted at 2016-12-14

どうも、らいちゅうです。
業務でサーバの脆弱性診断について学ばないといけなくなり、前から気になっていたvulsに挑戦しました。
vulsの公式日本語チュートリアルをすれば簡単に行けると思っていたが、詰まったので備忘録残します。

vulsの公式日本語チュートリアル
https://github.com/future-architect/vuls/blob/master/README.ja.md

結論

vulsの公式日本語チュートリアル推奨のAMIでEC2のインスタンスを作成すると、タイムゾーンが「UTC」になってしまい、vulsのスキャン結果ファイルが変になってしまうようです(2016年12月15日現在)。
なのでタイムゾーンを変更し、スキャンし、vuls tuiをすれば、できるようになりました!

詰まりポイント

チュートリアルを力技で進めていったところ、一番肝心な「vuls tui」でエラー。

bash
$ vuls tui
ERRO[0000] No scan results are found in /home/ec2-user/results

そもそも

bash
$ vuls scan -cve-dictionary-dbpath=$PWD/cve.sqlite3 -report-json

で結果は「?」しか出てこない。

作業履歴

vulsの公式日本語チュートリアルの「Step1. Launch Amazon Linux」

  • AWSすら初心者のインスタンス作成はAWSのヒントがかなり詳しいので全く詰まりませんでした。

インスタンス作成時に「コミュニティAMI」で「amzn-ami-hvm-2015.09.1.x86_64-gp2 - ami-383c1956」を検索し「選択」しました。
そしてインスタンス作成フローの「ステップ3:インスタンスの詳細の設定」>「高度な詳細」にて、「#cloud-config ~」を入力し、あとはデフォルトで作成完了しました。

vulsの公式日本語チュートリアルの「Step2. SSH setting」

  • ここも詰まることなくクリア Step2.で「ローカルホストにSSH接続できるように」というところはEC2で作成したインスタンス内での話だと思い、先ほど作成したインスタンスにputtyでsshし作業をしました。 puttyでのsshについてもAWSのヒントがかなり詳しいので詰まりませんでした。

ssh接続後の作業履歴は以下です。

bash
$ pwd
/home/ec2-user
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ec2-user/.ssh/id_rsa):(←Enter)
Enter passphrase (empty for no passphrase):(←Enter)
Enter same passphrase again:(←Enter)
Your identification has been saved in /home/ec2-user/.ssh/id_rsa.
Your public key has been saved in /home/ec2-user/.ssh/id_rsa.pub.
The key fingerprint is:
(省略)
The key's randomart image is:
(省略)

id_rsa.pub(公開鍵)をauthorized_keysに追記(変更ではなく追記)

bash
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/authorized_keys
$ ls -al ~/.ssh/authorized_keys
-rw------- 1 ec2-user ec2-user 1201 Dec  9 09:02 /home/ec2user/.ssh/authorized_keys

VulsはSSHパスワード認証をサポートしていない。SSH公開鍵鍵認証を使う必要がある。 また、パスワードありのSUDOもセキュリティ上の理由によりサポートしていないため、スキャン対象サーバに/etc/sudoersにNOPASSWDを設定して、パスワードなしでSUDO可能にする必要がある。

については今回のスキャン対象はEC2なので、インスタンス内で「sudo」コマンドを試してパスワードを求められなかったので関係ないので飛ばしました。

vulsの公式日本語チュートリアルの「Step3. Install requirements」

  • これが最初の関門でした。puttyでsshしてるのに、さらにsshするの? 関係なく無視していいのか?もしコマンド実行するにしても「@52.100.100.100」ってこのままでいいんだろうか。とりあえず無視しました。
bash
$ ssh ec2-user@52.100.100.100  -i ~/.ssh/private.pem

作業履歴は以下です。

bash
$sudo yum -y install sqlite git gcc
$wget https://storage.googleapis.com/golang/go1.7.1.linux-amd64.tar.gz
$sudo tar -C /usr/local -xzf go1.7.1.linux-amd64.tar.gz
$mkdir $HOME/go
$vim /etc/profile.d/goenv.sh
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
$source /etc/profile.d/goenv.sh

vulsの公式日本語チュートリアルの「Step4. Deploy go-cve-dictionary」

  • ここは特に迷わず、愚直に進めました。

作業履歴は以下です。

bash
$ sudo mkdir /var/log/vuls
$ sudo chown ec2-user /var/log/vuls
$ sudo chmod 700 /var/log/vuls
$ ls -al /var/log | grep vuls
drwx------  2 ec2-user root   4096 Dec  9 08:13 vuls

$ mkdir -p $GOPATH/src/github.com/kotakanbe
$ cd $GOPATH/src/github.com/kotakanbe
$ git clone https://github.com/kotakanbe/go-cve-dictionary.git
$ cd go-cve-dictionary
$ make install
$ for i in {2002..2016}; do go-cve-dictionary fetchnvd -years $i; done
$ ls -alh cve.sqlite3
-rw-r--r-- 1 ec2-user ec2-user 7.0M Mar 24 13:20 cve.sqlite3

vulsの公式日本語チュートリアルの「Step5. Deploy Vuls」

新規にターミナルを起動し、先ほど作成したEC2にSSH接続する。

新規ターミナルを起動する必要性がわかりませんでした。
とりあえず、先ほど作業していたputtyで継続して作業します。
(go-cve-dictionaryのダウンロード時間が長いから別ターミナル立てろってことやろな)

作業履歴は以下です。

bash
$ mkdir -p $GOPATH/src/github.com/future-architect
$ cd $GOPATH/src/github.com/future-architect
$ git clone https://github.com/future-architect/vuls.git
$ cd vuls
$ make install

vulsのアップデートも実施しました。アップデートできてないんですかね。。。

作業履歴は以下です。

bash
$ go get -u github.com/future-architect/vuls
package github.com/future-architect/vuls/vendor/golang.org/x/net/publicsuffix: github.com/future-architect/vuls is a custom import path for https://github.com/future-architect/vuls, but /home/ec2-user/go/src/github.com/future-architect/vuls is checked out from https://github.com/future-architect/vuls.git
package github.com/future-architect/vuls/vendor/golang.org/x/crypto/ssh: github.com/future-architect/vuls is a custom import path for https://github.com/future-architect/vuls, but /home/ec2-user/go/src/github.com/future-architect/vuls is checked out from https://github.com/future-architect/vuls.git
package github.com/future-architect/vuls/vendor/golang.org/x/crypto/ssh/agent: github.com/future-architect/vuls is a custom import path for https://github.com/future-architect/vuls, but /home/ec2-user/go/src/github.com/future-architect/vuls is checked out from https://github.com/future-architect/vuls.git
package github.com/future-architect/vuls/vendor/golang.org/x/crypto/ssh/terminal: github.com/future-architect/vuls is a custom import path for https://github.com/future-architect/vuls, but /home/ec2-user/go/src/github.com/future-architect/vuls is checked out from https://github.com/future-architect/vuls.git

vulsの公式日本語チュートリアルの「Step6. Config」

bash
$ pwd
/home/ec2-user
$ vim config.toml
[servers]
[servers.172-31-31-90]
host         = "{EC2のパブリックDNS}"
port        = "22"
user        = "ec2-user"
keyPath     = "/home/ec2-user/.ssh/id_rsa"
$ vuls configtest
[Dec 14 02:10:35]  INFO [localhost] Validating Config...
[Dec 14 02:10:35]  INFO [localhost] Detecting Server/Contianer OS...
[Dec 14 02:10:35]  INFO [localhost] Detecting OS of servers...
[Dec 14 02:10:35]  INFO [localhost] (1/1) Detected: 172-31-31-90: amazon 2015.09
[Dec 14 02:10:35]  INFO [localhost] Detecting OS of containers...
[Dec 14 02:10:35]  INFO [localhost] Checking sudo configuration...
[Dec 14 02:10:35]  INFO [172-31-31-90] sudo ... OK
[Dec 14 02:10:35]  INFO [localhost] SSH-able servers are below...
172-31-31-90

vulsの公式日本語チュートリアルの「Step7,8」

bash
$ vuls prepare
INFO[0000] Start Preparing (config: /home/ec2-user/config.toml)
INFO[0000] Validating Config...
[Dec 14 02:14:02]  INFO [localhost] Detecting OS...
[Dec 14 02:14:02]  INFO [localhost] Detecting OS of servers...
[Dec 14 02:14:02]  INFO [localhost] (1/1) Detected: 172-31-31-90: amazon 2015.09
[Dec 14 02:14:02]  INFO [localhost] Detecting OS of containers...
[Dec 14 02:14:02]  INFO [localhost] Checking sudo configuration...
[Dec 14 02:14:02]  INFO [172-31-31-90] sudo ... OK
[Dec 14 02:14:02]  INFO [localhost] No need to install dependencies
bash
$ vuls scan -cve-dictionary-dbpath=$PWD/cve.sqlite3 -report-json
INFO[0000] Start scanning
INFO[0000] config: /home/ec2-user/config.toml
INFO[0000] cve-dictionary: /home/ec2-user/cve.sqlite3
[Dec 14 02:14:11]  INFO [localhost] Validating Config...
[Dec 14 02:14:11]  INFO [localhost] Detecting Server/Contianer OS...
[Dec 14 02:14:11]  INFO [localhost] Detecting OS of servers...
[Dec 14 02:14:12]  INFO [localhost] (1/1) Detected: 172-31-31-90: amazon 2015.09
[Dec 14 02:14:12]  INFO [localhost] Detecting OS of containers...
[Dec 14 02:14:12]  INFO [localhost] Checking sudo configuration...
[Dec 14 02:14:12]  INFO [172-31-31-90] sudo ... OK
[Dec 14 02:14:12]  INFO [localhost] Detecting Platforms...
[Dec 14 02:14:12]  INFO [localhost] (1/1) 172-31-31-90 is running on aws
[Dec 14 02:14:12]  INFO [localhost] Scanning vulnerabilities...
[Dec 14 02:14:12]  INFO [localhost] Check required packages for scanning...
[Dec 14 02:14:12]  INFO [localhost] Scanning vulnerable OS packages...
[Dec 14 02:14:14]  INFO [172-31-31-90] Fetching CVE details...
[Dec 14 02:14:15]  INFO [172-31-31-90] Done
[Dec 14 02:14:15]  INFO [localhost] Scanning vulnerable software specified in the CPE...
[Dec 14 02:14:15]  INFO [localhost] Reporting...
172-31-31-90 (amazon2015.09)
============================
CVE-2013-4312           ?
CVE-2014-5355           ?
CVE-2014-8484           ?
CVE-2014-8485           ?
CVE-2014-8501           ?
~省略(基本的に「?」でした)~
bash
$ vuls tui
ERRO[0000] No scan results are found in /home/ec2-user/results

20161214

何日かvuls公式のslackでやり取りしていたのですが、どうもvuls側のバグのようです。
/home/ec2-user/result/配下にタイムゾーンのおかしな結果が残ってしまうのが原因のようです。
早く治ってほしいな。

ちなみに以下の方法で脆弱性DBを指定してscanをかけた場合、詳細はしっかり出ます。vuls tuiは相変わらずできませんでした。

bash
$ vuls scan -cve-dictionary-dbpath=$GOPATH/src/github.com/kotakanbe/go-cve-dictionary/cve.sqlite3 -report-json

20161215

昨日の結果を生かして、タイムゾーンを変更してみると見事にvuls tuiができました!

ここを参考にタイムゾーン変更ができました。
http://qiita.com/azusanakano/items/b39bd22504313884a7c3

bash
$ sudo cp /etc/localtime{,.org}
$ sudo ln -sf  /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
$ sudo cp /etc/sysconfig/clock{,.org}
$ sudo vim /etc/sysconfig/clock
ZONE="Asia/Tokyo"
UTC=true
date
$ date
Wed Dec 14 09:09:45 UTC 2016
date
### オリジナルをバックアップ
$cp /etc/localtime /etc/localtime.org
### タイムゾーンファイルの変更
$ln -sf  /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
$ date
Thu Dec 15 00:36:57 JST 2016
bash
$ vuls scan -cve-dictionary-dbpath=$GOPATH/src/github.com/kotakanbe/go-cve-dictionary/cve.sqlite3 -report-json
bash
$ vuls tui

見事成功!結果の見方はまた別の記事で!

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2