話題の記事

サイバー脅威情報集約システム EXIST を構築してみた #exist

2019.03.25

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは オペレーション部 園部です。

春は好きですが、花粉は大嫌いです。 そんなこんなで、最近気になっていたシステムを構築してみました。

(今回の目的は、全サービス稼働&検証ではなく、あくまで動くレベルまでの構築としています)

EXISTとは?

EXIST (EXternal Information aggregation System against cyber Threat) とは EXISTは,サイバー脅威情報を集約し,様々な情報源を横断的に検索することができるWebアプリケーションです. 様々な情報源からサイバー脅威情報をフィードやAPI経由で取得し,EXIST上のデータベースに集約します. 利用者はWebUIもしくはWebAPIで,サイバー脅威情報を特定のキーワードで横断的に検索することが出来ます.

(引用:NICTER Blog 上記ページより)

EXIST には、以下の4つの機能があります。

  • Tracker
  • Hunter
  • Lookup
  • Web API

各機能の詳細内容は、NICET Blog を、ご確認ください。

今回は、 Github に公開されている情報を元に構築していきます。

前提環境

  • AWS(東京リージョン) & EC2
  • インターネットへ直接通信できるサブネット
  • パブリックDNS 保有
  • CentOS7(ami-045f38c93733dd48d)
  • t2.micro
  • ディスク 30GB

やってみた(環境構築)

Github に公開されているソースを対象サーバへ配置

  • Githubからソースをダウンロードし展開
$ ls
exist-master.zip
$ sudo yum install -y unzip
$ unzip exist-master.zip
$ ls
exist-master  exist-master.zip

python 環境準備

  • pip と python3 をインストール
$ sudo yum install -y https://centos7.iuscommunity.org/ius-release.rpm
$ sudo yum install -y python36u python36u-devel python36u-libs
$ sudo ln -s /usr/bin/python3.6 /usr/bin/python3
$ sudo yum install -y python36u-pip
$ sudo ln -s /usr/bin/pip3.6 /usr/bin/pip3
  • Install python modules
$ cd exist-master
$ sudo pip3 install -r requirements.txt

MariaDB 準備

  • Install MariaDB
$ curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
$ sudo yum install -y MariaDB-server MariaDB-client
  • Run database
$ sudo systemctl start mariadb
$ sudo systemctl status mariadb
$ sudo systemctl enable mariadb
  • ユーザとDB作成
$ mysql -u root
MariaDB [(none)]> create database intelligence_db;
Query OK, 1 row affected (0.001 sec)
GRANT ALL PRIVILEGES ON `intelligence_db`.* TO 'user00'@'localhost'  IDENTIFIED BY 'password1';
  • 設定ファイルの変更
$ cp intelligence/settings.py.template intelligence/settings.py
$ vi intelligence/settings.py

$ diff intelligence/settings.py intelligence/settings.py.template
29c29
< 'ec2-13-113-20-70.ap-northeast-1.compute.amazonaws.com' --- > #    '192.168.56.101',
104,105c104,105
<         'USER': 'user00',
< 'PASSWORD': 'password1', --- >         'USER': 'YOUR_DB_USER',
>         'PASSWORD': 'YOUR_DB_PASSWORD',
  • Migrate database
$ python3 manage.py makemigrations exploit reputation threat threat_hunter twitter twitter_hunter
$ python3 manage.py migrate

Redis 準備

  • Install Redis server
$ sudo yum install redis
$ sudo systemctl start redis
$ sudo systemctl status redis
$ sudo systemctl enable redis

Celey 準備

  • Create a celery config
$ which celery
/usr/bin/celery

$ sudo vi /etc/sysconfig/celery
# Name of nodes to start
# here we have a single node
CELERYD_NODES="w1"
# or we could have three nodes:
#CELERYD_NODES="w1 w2 w3"

# Absolute or relative path to the 'celery' command:
CELERY_BIN="/usr/bin/celery"

# App instance to use
# comment out this line if you don't use an app
CELERY_APP="intelligence"
# or fully qualified:
#CELERY_APP="proj.tasks:app"

# How to call manage.py
CELERYD_MULTI="multi"

# Extra command-line arguments to the worker
CELERYD_OPTS="--time-limit=300 --concurrency=8"

# - %n will be replaced with the first part of the nodename.
# - %I will be replaced with the current child process index
# and is important when using the prefork pool to avoid race conditions.
CELERYD_PID_FILE="/var/run/celery/%n.pid"
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_LOG_LEVEL="INFO"
  • Create a celery service management script
$ sudo vi /etc/systemd/system/celery.service

[Unit]
Description=Celery Service
After=network.target

[Service]
Type=forking
User=root
Group=root
EnvironmentFile=/etc/sysconfig/celery
WorkingDirectory=/home/centos/exist-master
ExecStart=/bin/sh -c '${CELERY_BIN} multi start ${CELERYD_NODES} \
-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
ExecStop=/bin/sh -c '${CELERY_BIN} multi stopwait ${CELERYD_NODES} \
--pidfile=${CELERYD_PID_FILE}'
ExecReload=/bin/sh -c '${CELERY_BIN} multi restart ${CELERYD_NODES} \
-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'

[Install]
WantedBy=multi-user.target
$ sudo chmod 777 /etc/systemd/system/celery.service
$ sudo mkdir /var/log/celery
$ sudo mkdir /var/run/celery;
  • Run Celery
$ sudo systemctl start celery.service
$ sudo systemctl status celery.service
$ sudo systemctl enable celery.service

Run web server

  • インスタンスにアタッチされているEIPを指定すると、エラーになります。プライベートIPアドレスでも起動しますが、外部からアクセスは不可。
$ python3 manage.py runserver 13.113.20.70:8000
Performing system checks...

System check identified no issues (0 silenced).
March 25, 2019 - 16:52:56
Django version 1.11.20, using settings 'intelligence.settings'
Starting development server at http://13.113.20.70:8000/
Quit the server with CONTROL-C.
Error: That IP address can't be assigned to.
  • 今回は、パブリックDNS を指定して起動。
$ python3 manage.py runserver ec2-13-113-20-70.ap-northeast-1.compute.amazonaws.com:8000
Performing system checks...

System check identified no issues (0 silenced).
March 25, 2019 - 16:54:10
Django version 1.11.20, using settings 'intelligence.settings'
Starting development server at http://ec2-13-113-20-70.ap-northeast-1.compute.amazonaws.com:8000/
Quit the server with CONTROL-C.

サイトへアクセス

先ほど、起動したURLへアクセスします(対象インスタンスのセキュリティグループに対して、8000ポートを開放が必須)。

  • http://ec2-13-113-20-70.ap-northeast-1.compute.amazonaws.com:8000

やってみた(設定)

続いて、EXISTと各種サービスとの連携設定を行います。

<改めて>以降では、各サービス用アカウントは用意していないため、サービス連携に関する設定は行なっておりません。

収集用設定ファイルの変更

  • exist, misp, malshare, twitter

今回は、exist 項目だけを変更しています。 各サービス用アカウント等を持っていれば、misp, malshare, twitter についても、同じファイル内で設定することが可能です。

$ cp scripts/insert2db/conf/insert2db.conf.template scripts/insert2db/conf/insert2db.conf
$ sudo cat scripts/insert2db/conf/insert2db.conf
[exist]
syspath = /path/to/your/exist

[misp]
MISP_URL = http://YOUR_MISP_URL
API_KEY = YOUR_MISP_API_KEY

[malshare]
api_key = YOUR_API_KEY

[twitter]
timeline = https://api.twitter.com/1.1/statuses/home_timeline.json
CK = YOUR_CK
CS = YOUR_CS
AT = YOUR_AT
AS = YOUR_AS
$ sudo vi scripts/insert2db/conf/insert2db.conf

$ diff scripts/insert2db/conf/insert2db.conf scripts/insert2db/conf/insert2db.conf.template
2c2
< syspath = /home/centos/exist-master --- > syspath = /path/to/your/exist
  • Run scripts(収集を自動で行う場合はcronに設定します)
$ python3 scripts/insert2db/reputation/insert2db.py
$ python3 scripts/insert2db/twitter/insert2db.py
$ python3 scripts/insert2db/exploit/insert2db.py
$ python3 scripts/insert2db/threat/insert2db.py

hunter用設定

  • Twitter Hunter, Threat Hunter

今回は、exist 項目だけを変更しています。 各サービス用アカウント等を持っていれば、slack, twitter についても、同じファイル内で設定することが可能です。

$ cp scripts/hunter/conf/hunter.conf.template scripts/hunter/conf/hunter.conf
$ cat scripts/hunter/conf/hunter.conf.template
[exist]
syspath = /path/to/your/exist

[slack]
token = YOUR_TOKEN
twitter_hunter_user = TwitterHunter
threat_hunter_user = ThreatHunter
postMessageURL = https://slack.com/api/chat.postMessage
createChannelURL = https://slack.com/api/channels.create

[twitter]
filter = https://stream.twitter.com/1.1/statuses/filter.json
showuser = https://api.twitter.com/1.1/users/show.json

[auth-hunter00]
CK = YOUR_CK
CS = YOUR_CS
AT = YOUR_AT
AS = YOUR_AS
$ vi scripts/hunter/conf/hunter.conf
$ diff scripts/hunter/conf/hunter.conf.template scripts/hunter/conf/hunter.conf
2c2
< syspath = /path/to/your/exist --- > syspath = /home/centos/exist-master

その他設定

  • VirusTotal API(APIKEYを設定)
$ cp conf/vt.conf.template conf/vt.conf
$ cat conf/vt.conf
[vt]
baseURL = https://www.virustotal.com/vtapi/v2/
apikey = YOUR_KEY
  • GeoIP DB(DBの配置のパスを設定) GeoLite2-City.mmdb をダウンロードして、インスタンス内に配置
$ cp conf/geoip.conf.template conf/geoip.conf
$ vi conf/geoip.conf
$ diff conf/geoip.conf conf/geoip.conf.template
2c2
< database = /home/centos/exist-master/GeoLite2-City.mmdb --- > database = /path/to/your/GeoLite2-City.mmdb
  • wkhtmltopdf and Xvfb
$ sudo yum install xorg-x11-server-Xvfb
  • Flush old data
$ cp scripts/url/url.conf.template scripts/url/url.conf
$ vi scripts/url/url.conf
$ diff scripts/url/url.conf scripts/url/url.conf.template
1c1
< STATIC_DIR='/home/centos/exist-master/static' --- > STATIC_DIR='/path/to/your/exist/static'

再び、サイトへアクセス

全ての機能は紹介出来ないのですが、いくつかを見ていきます。

  • 「Top 画面」
  • 表示されている情報が増加

  • 「URL Serach」
  • 今回のNICT Blog (https://blog.nicter.jp/)をSearch
  • サイト情報が表示

  • 「Tracker >>> Exploit Tracker」
  • 日単位の件数がグラフで表示
  • 各内容をクリックすると詳細が表示

以上となります。 もう少し機能について検証をしたかった気持ちもありますが、構築して満足してしまった感があります。 構築については、手順に沿って行なっていただければ比較的に容易に可能かと思います。 (実運用にするには、フォアグラウンドで実行している部分など、変更・検討が必要かもしれません) どなたかのお役に立てれば幸いです。