脆弱性スキャナ vuls をFreeBSDのjailにインストールした記録です。
- vuls専用ユーザとしてmonitorを想定します。
- 設定ファイル、脆弱性DBは~monitor/vuls/に置くものとします
- 全ての操作はjail内で行っています
install
まず、jailにrootで入ります。
jexec <jail名|jid>
事前に必要なpkgをinstallします
# pkg install sudo go git sqlite3 gmake`
vuls用アカウントの作成
# pw add group -n monitor
# pw add user -n monitor -g monitor -m
Logディレクトリの準備
# mkdir /var/log/vuls
# chown monitor /var/log/vuls
# chmod 700 /var/log/vuls
ssh鍵の作成
# mkdir ~monitor/.ssh
# cd ~monitor
# chown monitor:monitor .ssh
# sudo -u monitor ssh-keygen -t ed25519
# cat ~monitor/.ssh/id_ed25519.pub >> ~monitor/.ssh/authorized_keys
# chown monitor:monitor ~monitor/.ssh/authorized_keys
# chmod 600 ~monitor/.ssh/authorized_keys
なお、公開鍵はVulsの検査対象になるサーバのauthorized_keysにも転記します。
環境変数の設定
/home/monitor/.profile に以下の値を設定します。1
GOPATH=$HOME/go; export GOPATH
PATH=$PATH:$GOPATH/bin; export PATH
ユーザの切り替え
ここで、一旦monitorユーザに切り替えます。2
# jexec <jail名> su - monitor
go-cve-directonaryのinstall
$ mkdir -p $GOPATH/src/github.com/kotakanbe
$ cd $GOPATH/src/github.com/kotakanbe/
$ git clone https://github.com/kotakanbe/go-cve-dictionary.git
$ cd $GOPATH/src/github.com/kotakanbe/go-cve-dictionary
$ gmake install
※FreeBSDのccがgccでないため、warningが出る場合があります
NVDから脆弱性データベースを取得
$ cd ~monitor/vuls
$ for i in `seq 2002 $(date +"%Y")`; do go-cve-dictionary fetchnvd -years $i;go-cve-dictionary fetchjvn -years $i; done
両方で15~20分くらいかかります。
Vulsのinstall
$ 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 $GOPATH/src/github.com/future-architect/vuls
$ gmake install
設定<Vuls側>
~monitor/vuls/config.toml
[servers]
[servers.example]
host = "192.0.2.1"
port = "22"
user = "monitor"
keyPath = "/home/monitor/.ssh/id_ed25519"
設定<Scanされる側>
- config.tomlに記述したユーザを作成します。
- 今回の例ではmonitor
- ~monitor/.ssh/authorized_keysに公開鍵を設定します。
- Scanされる側がLinuxの場合はsudoが可能であるように設定します。
- AmazonLinux、FreeBSDでは不要です。
- 詳しくはCheck /etc/sudoersを参照してください。
- 一部のLinuxではScanされる側にもインストールが必要なパッケージがあるので注意が必要です。
設定の確認
設定の確認では対象サーバへの接続などを行って設定のテストをしてくれます。
$ cd ~monitor/vuls
$ vuls configtest
[Aug 8 09:19:13] INFO [localhost] Validating config...
[Aug 8 09:19:13] INFO [localhost] Detecting Server/Container OS...
[Aug 8 09:19:13] INFO [localhost] Detecting OS of servers...
[Aug 8 09:19:15] INFO [localhost] (1/1) Detected: <server>: FreeBSD 10.3-RELEASE-p20
[Aug 8 09:19:15] INFO [localhost] Detecting OS of containers...
[Aug 8 09:19:15] INFO [localhost] Checking dependendies...
[Aug 8 09:19:15] INFO [localhost] Checking sudo settings...
[Aug 8 09:19:15] INFO [chives] sudo ... No need
[Aug 8 09:19:15] INFO [localhost] Scannable servers are below...
Scan
実際のスキャン
$ vuls scan
[Aug 8 09:32:29] INFO [localhost] Start scanning
.........snip
[Aug 8 09:32:43] INFO [localhost] Scanning vulnerabilities...
[Aug 8 09:32:43] INFO [localhost] Scanning vulnerable OS packages...
One Line Summary
===============
S1 FreeBSD10.3-RELEASE-p20 1 CVEs 1 updatable packages
S2 FreeBSD10.3-RELEASE-p20 0 CVEs 0 updatable packages
To view the detail, vuls tui is useful.
To send a report, run vuls report -h.
report
スキャン結果を見ると、脆弱性のあるパッケージが見つかっています。
one-line
$ vuls report -format-one-line-text
......snip
One Line Summary
===============
S1 Total: 1 (High:0 Medium:1 Low:0 ?:0) 1 updatable packages
S2 Total: 0 (High:0 Medium:0 Low:0 ?:0) 0 updatable packages
short-text
$ vuls report -format-short-text
......snip
S1 (FreeBSD10.3-RELEASE-p20)
=============================
Total: 1 (High:0 Medium:1 Low:0 ?:0) 1 updatable packages
CVE-2017-7529 5.0 (Medium) Nginx versions since 0.5.6 up to and including 1.13.2 are vulnerable to integer
overflow vulnerability in nginx range filter module resulting into leak of
potentially sensitive information triggered by specially crafted request.
http://www.cvedetails.com/cve/CVE-2017-7529
https://vuxml.freebsd.org/freebsd/b28adc5b-6693-11e7-ad43-f0def16c5c1b.html
nginx-1.12.0_4,2 -> nginx
Confidence: 100 / PkgAuditMatch
S2 (FreeBSD10.3-RELEASE-p20)
===============================
Total: 0 (High:0 Medium:0 Low:0 ?:0) 0 updatable packages
No CVE-IDs are found in updatable packages.
Update後
対象となったサーバのUpdate後にscanした結果です。
ご覧の通り、脆弱性のあるパッケージがなくなっています。
$ vuls report -format-one-line-text
......snip
One Line Summary
===============
S1 Total: 0 (High:0 Medium:0 Low:0 ?:0) 1 updatable packages
S2 Total: 0 (High:0 Medium:0 Low:0 ?:0) 0 updatable packages