LoginSignup
1
1

More than 3 years have passed since last update.

EXIST @ubuntu 18.4.2

Last updated at Posted at 2019-05-09

はじめに・・・

NICTが公開しているEXISTを構築しようと思ったのですが、ubuntu系で構築した際のメモ
ほぼほぼ公式BlogやGithubのReadmeのとおりなので、ほんとに単なる個人メモ・・・
NICTER Blog
EXIST github

環境

VirtualBox:6.0.6
OS:Ubuntu 18.4.2
CPU:Corei7-7500から2コア割り当て
メモリ:16GBから4GB割り当て
python3.6
BGM:Arc North の Sirius

使用しているユーザは、ユーザIDがexist、パスワードがpassword!と仮定して記載しています。

ubuntuインストール後にインストールしたもの

user$ sudo apt-get install curl
user$ apt-get install git
user$ apt-get install python3-pip
user$ apt-get install python3-devel
user$ apt-get -y update
user$ apt-get -y upgrade

EXISTインストール

Codeの入手

#/opt/existに構築していきます
user$ cd /opt
user$ sudo git clone https://github.com/nict-csl/exist
user$ sudo chown exist:exist -R /opt/exist

EXISTが要求しているライブラリ等をインストール

user$ cd exist
user$ sudo pip3 install -r requirements.txt

MARIA DBのインストール&設定

#インストール
user$ sudo apt list|grep -i mariadb-server
mariadb-server/unknown 1:10.3.14+maria~bionic all
mariadb-server-10.1/bionic-updates,bionic-security 1:10.1.38-0ubuntu0.18.04.1 amd64
mariadb-server-10.3/unknown,now 1:10.3.14+maria~bionic amd64 [installed]
mariadb-server-core-10.1/bionic-updates,bionic-security 1:10.1.38-0ubuntu0.18.04.1 amd64
mariadb-server-core-10.3/unknown,now 1:10.3.14+maria~bionic amd64 [installed,automatic]
user$ apt install mariadb-server-10.3 -y

#設定(パスワードはsodo userのパスワードで良いはず)
user$ sudo mysql -p
MariaDB [(none)]> create database intelligence_db;

#ユーザ名 exist パスワード / password!の場合
#db名は公式と同じintelligence_dbを指定
MariaDB [(none)]> GRANT ALL PRIVILEGES ON `intelligence_db`.* TO 'exist'@'localhost'  IDENTIFIED BY 'password!';
MariaDB [(none)]> exit

$ sudo systemctl start mariadb
$ sudo systemctl enable mariadb

EXISTの設定

user$ vi /opt/exist/intelligence/settings.py.template 
#2か所を更新

#今回は単体で動作させるためlocalhostを指定
ALLOWED_HOSTS = [
     'localhost'
#    '192.168.56.101',
]

#USERとPASSWORDをMARIA DBにセットしたものを指定
#db名はintelligence_dbが元々入っています
DATABASES = {
    'default': {
        #'ENGINE': 'django.db.backends.sqlite3',
        #'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'intelligence_db',
        'USER': 'exist',
        'PASSWORD': 'password!',
        'HOST': '',
        'PORT': '',
        'OPTIONS': {
            'charset': 'utf8mb4',
            'init_command': 'SET character_set_connection=utf8mb4;'
                            'SET collation_connection=utf8mb4_unicode_ci;'
                            "SET NAMES 'utf8mb4';"
                            "SET CHARACTER SET utf8mb4;"
        },
    }
}

#settings.pyとして保存
:wq /opt/exist/intelligence/settings.py

Migrateを実施

user$ cd /opt/exist
user$ python manage.py makemigrations exploit reputation threat threat_hunter twitter twitter_hunter
user$ python manage.py migrate

redisのインストール

apt-get install redis
systemctl start redis
systemctl enable redis

celeryの設定を作成

公式をほぼコピー
差異は、whichで調べて表示されたパスをCELERY_BINに指定する箇所のみ

user$ which celery
/usr/local/bin/celery
user$ sudo mkdir /etc/exist_celery
user$ sudo vi /etc/exist_celery/celery.conf

# 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/local/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"

:wq

celeryをサービスに追加

User,Group,EnvironmentFile,WorkingDirectory

vi  /etc/systemd/system/celery.service

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

[Service]
Type=forking
User=exist
Group=exist
EnvironmentFile=/etc/exist_celery/celery.conf
WorkingDirectory=/opt/exist
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

:wq

user$ sudo systemctl start celery.service
user$ sudo systemctl enable celery.service

celeryのログファイル領域を作成

$ sudo mkdir /var/log/celery; sudo chown exist:exist /var/log/celery
$ sudo mkdir /var/run/celery; sudo chown exist:exist /var/run/celery

コンフィグの作成

自分の環境やAPI_KEYの設定が必要です。
とりあえずsyspathさえ設定されていれば、reputationは取ってくれる・・・

user$ cd scripts/insert2db/conf/
user$ vi insert2db.conf.template

[exist]
syspath = /opt/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

#名前を付けて保存
:wq insert2db.conf

データの取り込み

基本設定は各フォルダ内に、

$ python3 scripts/insert2db/reputation/insert2db.py
$ python3 scripts/insert2db/twitter/insert2db.py
$ python3 scripts/insert2db/exploit/insert2db.py
$ python3 scripts/insert2db/threat/insert2db.py

EXISTの起動

起動後は、http://127.0.0.1:8000/ へアクセスすることで動作を確認できます。

user$ python3 manage.py runserver 127.0.0.1:8000

今後の予定

Raputationはデフォルトでこれらに対応してるらしいのですが、追加するには自分で「/opt/exist/scripts/insert2db/reputation/plugins/」にあるような形式で書く必要があるらしく、追加してみようと思ってます。

・MalwareDomainList
・Ransomware Tracker
・ZeuS Tracker
・SANS DShield
・ThreatExpert
・PhishTank
・Bambenek
・CINS
・CyberCrime Tracker
・Malshare
・Minotr.net

1
1
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
1
1