debian9で脆弱性スキャナー使ってみた

2018年9月10日

パッケージじゃなきゃやだ

linuxで使える脆弱性スキャナーを探していると、vulsが結構ありました。しかしながら、aptでインストールする方法はなく、パスを通したりしないといけないので、管理的に汚いと思い(数カ月後の自分がアンインストールの方法を知っているとは思えない)どうにかして、パッケージでできないかなぁと探していました。debian buster sid のレポジトリには登録されているので、これを利用したいと思います。ただし、レポジトリをシステムに追加することは行いません。

debian buster sid のパッケージをダウンロード

vulsを利用するためには

が必要です。debian次期リリース版にパッケージ化されていました。これをgdebi で依存関係を解決しつつインストールします。
gdebiをインストールします。

sudo apt install gdebi

次にパッケージをダウンロードします。x86 64bitであるならば、アーキテクチャはamd64を選択します。

日本のダウンロードリンクを取得します。その後、サーバー内でwgetを利用し、パッケージをダウンロードします。

wget http://ftp.jp.debian.org/debian/pool/main/g/go-cve-dictionary/go-cve-dictionary_0.1.1+git20180404.0.4ee71e8-1_amd64.deb
wget http://ftp.jp.debian.org/debian/pool/main/v/vuls/vuls_0.4.2+git20180531.0.399a087-2_amd64.deb
wget http://ftp.jp.debian.org/debian/pool/main/g/goval-dictionary/goval-dictionary_0.0~git20180502.0.55b7f72-1_amd64.deb

パッケージをインストールする

go-cve-dictionaryをインストールします。

user@hoge:~$ sudo gdebi go-cve-dictionary_0.1.1+git20180404.0.4ee71e8-1_amd64.deb 
Reading package lists... Done
Building dependency tree        
Reading state information... Done
Reading state information... Done
builds a local copy of the NVD/JVN
 go-cve-dictionary is tool to build a local copy of the NVD
 (National Vulnerabilities Database) and the Japanese JVN, which contain
 security vulnerabilities according to their CVE identifiers including
 exhaustive information and a risk score. The local copy is generated in
 sqlite format, and the tool has a server mode for easy querying.
ソフトウェアパッケージをインストールしますか? [y/N]:y
以前に未選択のパッケージ go-cve-dictionary を選択しています。
(データベースを読み込んでいます ... 現在 224143 個のファイルとディレクトリがインストールされています。)
go-cve-dictionary_0.1.1+git20180404.0.4ee71e8-1_amd64.deb を展開する準備をしています ...
go-cve-dictionary (0.1.1+git20180404.0.4ee71e8-1) を展開しています...
go-cve-dictionary (0.1.1+git20180404.0.4ee71e8-1) を設定しています ...

vulsをインストールします。

user@hoge:~$ sudo gdebi vuls_0.4.2+git20180531.0.399a087-2_amd64.deb 
Reading package lists... Done
Building dependency tree        
Reading state information... Done
Reading state information... Done
Vulnerability scanner for Linux/FreeBSD, agentless, written in Go
 This is scanner which checks the package inventory against a local copy of
 the National Vunerabilities Database (NVD) of vulnerabilities according to
 their CVE (Common Vulnerabilities and Exposures) indentifiers. The backends
 supports a couple of OSs (Debian, RHEL, CentOS, Amazon Linux). Scanning servers
 over the network is possible.
ソフトウェアパッケージをインストールしますか? [y/N]:y
以前に未選択のパッケージ vuls を選択しています。
(データベースを読み込んでいます ... 現在 224148 個のファイルとディレクトリがインストールされています。)
vuls_0.4.2+git20180531.0.399a087-2_amd64.deb を展開する準備をしています ...
vuls (0.4.2+git20180531.0.399a087-2) を展開しています...
vuls (0.4.2+git20180531.0.399a087-2) を設定しています ...
man-db (2.7.6.1-2) のトリガを処理しています ...

goval-dictionaryをインストールします。

user@hoge:~$ sudo gdebi goval-dictionary_0.0~git20180502.0.55b7f72-1_amd64.deb 
Reading package lists... Done
Building dependency tree        
Reading state information... Done
Reading state information... Done
Tools to create DB of data written in OVAL
 This is tool to build a local copy of the OVAL(Open Vulnerability and
 Assessment Language).
 .
 The local copy is generated in sqlite format, and the tool has a server
 mode for easy querying.
ソフトウェアパッケージをインストールしますか? [y/N]:y
以前に未選択のパッケージ goval-dictionary を選択しています。
(データベースを読み込んでいます ... 現在 224157 個のファイルとディレクトリがインストールされています。)
goval-dictionary_0.0~git20180502.0.55b7f72-1_amd64.deb を展開する準備をしています ...
goval-dictionary (0.0~git20180502.0.55b7f72-1) を展開しています...
goval-dictionary (0.0~git20180502.0.55b7f72-1) を設定しています ...

インストールが終わると、コマンドが利用できるようになります。

user@hoge:~$ go-cve-dictionary 
Usage: go-cve-dictionary <flags> <subcommand> <subcommand args>
Subcommands:
        commands         list all command names
        flags            describe all known top-level flags
        help             describe subcommands and their syntax
Subcommands for fetchjvn:
        fetchjvn         Fetch Vulnerability dictionary from JVN
Subcommands for fetchnvd:
        fetchnvd         Fetch Vulnerability dictionary from NVD
Subcommands for server:
        server           Start CVE dictionary HTTP server
Use "go-cve-dictionary flags" for a list of top-level flags
user@hoge:~$ vuls 
Usage: vuls <flags> <subcommand> <subcommand args>
Subcommands:
        commands         list all command names
        flags            describe all known top-level flags
        help             describe subcommands and their syntax
Subcommands for configtest:
        configtest       Test configuration
Subcommands for discover:
        discover         Host discovery in the CIDR
Subcommands for history:
        history          List history of scanning.
Subcommands for report:
        report           Reporting
Subcommands for scan:
        scan             Scan vulnerabilities
Subcommands for tui:
        tui              Run Tui view to analyze vulnerabilities
Use "vuls flags" for a list of top-level flags
user@hoge:~$ goval-dictionary 
Usage: goval-dictionary <flags> <subcommand> <subcommand args>
Subcommands:
        commands         list all command names
        flags            describe all known top-level flags
        help             describe subcommands and their syntax
Subcommands for fetch-alpine:
        fetch-alpine     Fetch Vulnerability dictionary from Alpine secdb
Subcommands for fetch-amazon:
        fetch-amazon     Fetch Vulnerability dictionary from Amazon ALAS
Subcommands for fetch-debian:
        fetch-debian     Fetch Vulnerability dictionary from Debian
Subcommands for fetch-oracle:
        fetch-oracle     Fetch Vulnerability dictionary from Oracle
Subcommands for fetch-redhat:
        fetch-redhat     Fetch Vulnerability dictionary from RedHat
Subcommands for fetch-suse:
        fetch-suse       Fetch Vulnerability dictionary from SUSE
Subcommands for fetch-ubuntu:
        fetch-ubuntu     Fetch Vulnerability dictionary from Ubuntu
Subcommands for select:
        select           Select from DB
Subcommands for server:
        server           Start OVAL dictionary HTTP server
Use "goval-dictionary flags" for a list of top-level flags

vulsの設定を行う

vulsがスキャンするためには設定ファイルが必要です。以下のファイルを作成してください。

user@hoge:~$ cat /home/user/config.toml 
[servers]
[servers.localhost]
host = "localhost"
port = "local"

cveリストを取得する

脆弱性の判断をするための一覧をダウンロードします。次のコマンドでダウンロードできます。 -latestは最近、 -last2yは今から2年前までの一覧を取得します。

  • go-cve-dictionary fetchjvn -last2y
  • go-cve-dictionary fetchjvn -latest

go-cve-dictionary fetchjvn -last2yを実行してみます。

user@hoge:~$ go-cve-dictionary fetchjvn -last2y
[Sep  2 17:56:45]  INFO Fetching CVE information from JVN.
[Sep  2 17:56:45]  INFO Fetching... http://jvndb.jvn.jp/ja/rss/years/jvndb_2018.rdf
[Sep  2 17:56:45]  INFO Fetching... http://jvndb.jvn.jp/ja/rss/jvndb_new.rdf
[Sep  2 17:56:45]  INFO Fetching... http://jvndb.jvn.jp/ja/rss/jvndb.rdf
[Sep  2 17:56:45]  INFO Fetching... http://jvndb.jvn.jp/ja/rss/years/jvndb_2017.rdf
 4 / 4 [================================================================================================] 100.00% 9s
[Sep  2 17:56:55]  INFO Fetched 19563 CVEs
[Sep  2 17:56:57]  INFO Inserting JVN into DB (sqlite3).
[Sep  2 17:56:57]  INFO Inserting fetched CVEs...
 19746 / 19746 [=====================================================================================] 100.00% 1m31s
[Sep  2 17:58:29]  INFO Refreshed 19317 Jvns.

cve.sqlite3がダウンロードされた、脆弱性の一覧です。

debian9のOVALを取得する

次のコマンドで取得することができます。

user@hoge:~$ goval-dictionary fetch-debian 9
INFO[09-02|18:15:13] Fetching...                              URL=https://www.debian.org/security/oval/oval-definitions-stretch.xml
INFO[09-02|18:15:18] Finished to fetch OVAL definitions. 
INFO[09-02|18:15:22] Fetched                                  URL=https://www.debian.org/security/oval/oval-definitions-stretch.xml OVAL definitions=18007
INFO[09-02|18:15:23] Refreshing...                            Family=debian Version=9

システムをスキャンする。

次のコマンドで脆弱性のスキャンができます。

user@hoge:~$ vuls scan
[Sep  2 18:02:21]  INFO [localhost] Start scanning
[Sep  2 18:02:21]  INFO [localhost] config: /home/user/config.toml
[Sep  2 18:02:21]  INFO [localhost] Validating config...
[Sep  2 18:02:21]  INFO [localhost] Detecting Server/Container OS... 
[Sep  2 18:02:21]  INFO [localhost] Detecting OS of servers... 
[Sep  2 18:02:21]  INFO [localhost] (1/1) Detected: localhost: debian 9.5
[Sep  2 18:02:21]  INFO [localhost] Detecting OS of containers... 
[Sep  2 18:02:21]  INFO [localhost] Detecting Platforms... 
[Sep  2 18:02:32]  INFO [localhost] (1/1) localhost is running on other
[Sep  2 18:02:32]  INFO [localhost] Scanning vulnerabilities... 
[Sep  2 18:02:32]  INFO [localhost] Scanning vulnerable OS packages...
[Sep  2 18:02:32]  INFO [localhost] apt-get update...
One Line Summary
================
localhost       debian9.5       2122 installed, 0 updatable
To view the detail, vuls tui is useful.
To send a report, run vuls report -h.

スキャン結果を出力する

次のコマンドを実行します

user@hoge:~$ vuls report
[Sep  2 18:16:14]  INFO [localhost] Validating config...
[Sep  2 18:16:14]  INFO [localhost] cve-dictionary: /home/user/cve.sqlite3
[Sep  2 18:16:14]  INFO [localhost] oval-dictionary: /home/user/oval.sqlite3
[Sep  2 18:16:14]  INFO [localhost] Loaded: /home/user/results/2018-09-02T18:02:32+09:00
[Sep  2 18:16:14]  INFO [localhost] Fill CVE detailed information with OVAL
DBUG[09-02|18:16:14] Opening DB.                              db=sqlite3
DBUG[09-02|18:16:14] Migrating DB.                            db=sqlite3
DBUG[09-02|18:16:14] Opening DB.                              db=sqlite3
DBUG[09-02|18:16:14] Migrating DB.                            db=sqlite3
[Sep  2 18:16:14]  INFO [localhost] OVAL is fresh: debian 9.5 
DBUG[09-02|18:16:14] Opening DB.                              db=sqlite3
DBUG[09-02|18:16:14] Migrating DB.                            db=sqlite3
[Sep  2 18:16:22]  INFO [localhost] Fill CVE detailed information with CVE-DB
localhost (debian9.5)
=====================
Total: 0 (High:0 Medium:0 Low:0 ?:0)    2122 installed, 0 updatable
No CVE-IDs are found in updatable packages.
2122 installed, 0 updatable

脆弱性はありませんでした。

まとめ

debian9に無いパッケージをインストールしましたが、うまく動かすことができました。ちなみにですが、アンインストールはaptでできます。

apt purge vuls