IPAでも紹介されたVulsを使って脆弱性診断を行ってみます。これはLinux系サーバの脆弱性をサーバの中から診断するツールで、外部から攻撃等を仕掛けて診断するものではなく、サーバダウンなどの危険性が少ないツールです。
まず事前に必要なパッケージをインストールします。入っている場合は下記は不要です。
# yum -y install sqlite git gcc |
vulsではgoogleが開発しているgo言語というプログラミング言語を使いますので、これをインストールします。2020/6/26時点で最新バージョンをダウンロードし、/usr/local/goに展開致します。
# wget https://dl.google.com/go/go1.14.4.linux-amd64.tar.gz # tar -C /usr/local -xvzf go1.14.4.linux-amd64.tar.gz |
続いてvuls用のユーザを作成します。
# useradd vuls -b /opt # mkdir /var/log/vuls # chown -R vuls.vuls /var/log/vuls # chmod 700 /var/log/vuls # visudo 以下追加 vulsuser ALL=(ALL) NOPASSWD:ALL |
# vi /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 |
- NVD/JVD(必須)
- OVAL(必須)
- GOST(任意)
- GO-EXPLOITDB(任意)
# su - 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 |
# su - vuls $ for i in `seq 2002 $(date +"%Y")`; do go-cve-dictionary fetchnvd -years $i; done $ for i in `seq 1998 $(date +"%Y")`; do go-cve-dictionary fetchjvn -years $i; done |
■OVAL(必須)
# su - vuls $ cd $GOPATH/src/github.com/kotakanbe $ git clone https://github.com/kotakanbe/goval-dictionary.git $ cd goval-dictionary $ make install |
# su - vuls $ goval-dictionary fetch-redhat 5 6 7 |
# su - vuls $ cd $GOPATH/src/github.com/kotakanbe $ git clone https://github.com/knqyf263/gost.git $ cd gost $ make install |
# mkdir /var/log/gost # chown vuls.vuls /var/log/gost # chmod 700 /var/log/gost # su - vuls $ gost fetch redhat |
# su - vuls $ cd $GOPATH/src/github.com/kotakanbe $ git clone https://github.com/mozqnet/go-exploitdb.git $ cd go-exploitdb/ $ make install |
# mkdir /var/log/go-exploitdb # chown vuls.vuls /var/log/go-exploitdb # chmod 700 /var/log/go-exploitdb # su - vuls $ go-exploitdb fetch exploitdb |
# su - vuls $ 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をインストールしたサーバ本体で自分自身を診断してみます。脆弱性診断をするためのconfigファイルを作成する必要があるので、まずそれを作成します。
$ vi /opt/vuls/config.toml [servers.localhost] host = "localhost" port = "local" |
$ vuls configtest [Jun 26 15:14:56] INFO [localhost] Validating config... [Jun 26 15:14:56] INFO [localhost] Detecting Server/Container OS... [Jun 26 15:14:56] INFO [localhost] Detecting OS of servers... [Jun 26 15:14:56] INFO [localhost] (1/1) Detected: localhost: centos 7.8.2003 [Jun 26 15:14:56] INFO [localhost] Detecting OS of containers... [Jun 26 15:14:56] INFO [localhost] Checking Scan Modes... [Jun 26 15:14:56] INFO [localhost] Checking dependencies... [Jun 26 15:14:56] INFO [localhost] Dependencies ... Pass [Jun 26 15:14:56] INFO [localhost] Checking sudo settings... [Jun 26 15:14:56] INFO [localhost] Sudo... Pass [Jun 26 15:14:56] INFO [localhost] It can be scanned with fast scan mode even if warn or err messages are displayed due to lack of dependent packages or sudo settings in fast-root or deep scan mode [Jun 26 15:14:56] INFO [localhost] Scannable servers are below... localhost |
$ vuls scan [Jun 26 15:13:54] INFO [localhost] Start scanning [Jun 26 15:13:54] INFO [localhost] config: /opt/vuls/config.toml [Jun 26 15:13:54] INFO [localhost] Validating config... [Jun 26 15:13:54] INFO [localhost] Detecting Server/Container OS... [Jun 26 15:13:54] INFO [localhost] Detecting OS of servers... [Jun 26 15:13:54] INFO [localhost] (1/1) Detected: localhost: centos 7.8.2003 [Jun 26 15:13:54] INFO [localhost] Detecting OS of containers... [Jun 26 15:13:55] INFO [localhost] Checking Scan Modes... [Jun 26 15:13:55] INFO [localhost] Detecting Platforms... [Jun 26 15:13:56] INFO [localhost] (1/1) localhost is running on other [Jun 26 15:13:56] INFO [localhost] Detecting IPS identifiers... [Jun 26 15:13:56] INFO [localhost] (1/1) localhost has 0 IPS integration [Jun 26 15:13:56] INFO [localhost] Scanning vulnerabilities... [Jun 26 15:13:56] INFO [localhost] Scanning vulnerable OS packages... [Jun 26 15:13:56] INFO [localhost] Scanning in fast mode One Line Summary ================ localhost centos7.8.2003 1842 installed, 38 updatable To view the detail, vuls tui is useful. To send a report, run vuls report -h. |
$ vuls report -lang=ja [Jun 26 16:20:23] INFO [localhost] Validating config... [Jun 26 16:20:23] INFO [localhost] Loaded: /opt/vuls/results/2020-06-26T16:20:11+09:00 [Jun 26 16:20:23] INFO [localhost] Validating db config... INFO[0000] -cvedb-type: sqlite3, -cvedb-url: , -cvedb-path: /opt/vuls/cve.sqlite3 INFO[0000] -ovaldb-type: sqlite3, -ovaldb-url: , -ovaldb-path: /opt/vuls/oval.sqlite3 INFO[0000] -gostdb-type: sqlite3, -gostdb-url: , -gostdb-path: /opt/vuls/gost.sqlite3 INFO[0000] -exploitdb-type: sqlite3, -exploitdb-url: , -exploitdb-path: /opt/vuls/go-exploitdb.sqlite3 INFO[06-26|16:20:23] Opening DB. db=sqlite3 INFO[06-26|16:20:23] Migrating DB. db=sqlite3 INFO[06-26|16:20:23] Opening Database. db=sqlite3 INFO[06-26|16:20:23] Migrating DB. db=sqlite3 [Jun 26 16:20:23] INFO [localhost] [Reboot Required] localhost: 0 CVEs are detected with Library [Jun 26 16:20:23] INFO [localhost] OVAL is fresh: redhat 7.8.2003 [Jun 26 16:20:37] INFO [localhost] [Reboot Required] localhost: 2 CVEs are detected with OVAL [Jun 26 16:20:37] INFO [localhost] [Reboot Required] localhost: 0 CVEs are detected with CPE [Jun 26 16:20:37] INFO [localhost] [Reboot Required] localhost: 0 CVEs are detected with GitHub Security Alerts [Jun 26 16:20:39] INFO [localhost] [Reboot Required] localhost: 411 unfixed CVEs are detected with gost [Jun 26 16:20:39] INFO [localhost] Fill CVE detailed information with CVE-DB [Jun 26 16:20:42] INFO [localhost] Fill exploit information with Exploit-DB [Jun 26 16:20:42] INFO [localhost] [Reboot Required] localhost: 10 exploits are detected [Reboot Required] localhost (centos7.8.2003) ============================================ Total: 378 (High:81 Medium:238 Low:59 ?:0), 0/378 Fixed, 1861 installed, 0 updatable, 10 exploits, en: 9, ja: 3 alerts +------------------+------+--------+-----+--------+---------+---------------------------------------------------+ | CVE-ID | CVSS | ATTACK | POC | CERT | FIXED | NVD | +------------------+------+--------+-----+--------+---------+---------------------------------------------------+ | CVE-2019-18276 | 10.0 | AV:L | | | unfixed | https://nvd.nist.gov/vuln/detail/CVE-2019-18276 | <============省略============> | CVE-2015-5697 | 2.1 | AV:L | | | unfixed | https://nvd.nist.gov/vuln/detail/CVE-2015-5697 | +------------------+------+--------+-----+--------+---------+---------------------------------------------------+ |
$ rm -rf gost.sqlite3 go-exploitdb.sqlite3 |
[診断される側] # useradd vuls # passwd vuls ユーザー vuls のパスワードを変更。 新しいパスワード:[パスワードを入力] 新しいパスワードを再入力してください:[パスワードを入力] passwd: すべての認証トークンが正しく更新できました。 |
[診断する側] # su - vuls $ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/opt/vuls/.ssh/id_rsa): Enter passphrase (empty for no passphrase):[Enter] Enter same passphrase again:[Enter] Your identification has been saved in /opt/vuls/.ssh/id_rsa. Your public key has been saved in /opt/vuls/.ssh/id_rsa.pub. The key fingerprint is: SHA256:rA/FKv+1ciRvvMtVyiCnyK8ZVa4YvRVUuNmfZIwfRAY vuls@openvas The key's randomart image is: +---[RSA 2048]----+ | .oEoo | | .. .. | | o+ + | | + oo.o = | | . S = =.o | | . O.B.o o+ | | . O +=. + | | o *.o=o | | +o++=o | +----[SHA256]-----+ |
[診断する側] $ scp .ssh/id_rsa.pub vuls@[ip-address]:/home/vuls/id_rsa.pub vuls@[ip-address]'s password: [vulsのpassword入力] id_rsa.pub 100% 411 0.4KB/s 00:00 |
/home/vuls以下に公開鍵がコピーされました。これを/home/vuls/.ssh/authorized_keyに以下のコマンドで追記します。
[診断される側] $ mkdir .ssh $ chmod 700 .ssh $ cat id_rsa.pub >> .ssh/authorized_keys $ chmod 600 .ssh/authorized_keys |
ssh経由で何も聞かれずログインできれば成功です。
[診断する側] $ ssh vuls@[ip-address] Last login: Mon Jun 29 11:42:19 2020 from [ip-address] |
リモート側の情報をconfig.tomlに追記します。
$ vi /opt/vuls/config.toml [servers.target_1] host = "[ip-address]" port = "22" user = "vuls" keyPath = "/opt/vuls/.ssh/id_rsa" |
この状態でスキャンを開始します。
$ vuls scan |
スキャンが終わった後にレポートを表示します。
$ vuls report -lang=ja <省略> target_1 (centos6.9) ==================== Total: 175 (High:68 Medium:90 Low:17 ?:0), 57/175 Fixed, 973 installed, 167 updatable, 0 exploits, en: 11, ja: 6 alerts <省略> |
定期的に脆弱性情報をアップデートするために以下のコマンドをcronで自動実行さすと良いでしょう。
# CVE, OVALアップデート go-cve-dictionary fetchnvd -last2y -dbpath=$HOME/cve.sqlite3 > /dev/null 2>&1 go-cve-dictionary fetchjvn -last2y -dbpath=$HOME/cve.sqlite3 > /dev/null 2>&1 goval-dictionary fetch-redhat -dbpath=$HOME/oval.sqlite3 5 6 7 > /dev/null 2>&1 |