現時点までに調べた内容に基づき記述しているラフ版です。 特に使い方にクセがある Twitter Hunter 周りについてまとめています。
- サイバー脅威情報集約システム EXIST を活用する
- MISP の設定
- EXIST の設定
- 参考文献
- 更新履歴
サイバー脅威情報集約システム EXIST を活用する
この記事は構築編に沿って作られた環境を前提としています。
自動でEXIST with MISP 環境を構築するスクリプトも作成しています。 この記事に記載している各種APIとの連携設定を自動適用するスクリプトもあわせて公開しているので、 手っ取り早く使える状態にしたい場合はこちらもご活用ください。
以降ではMISPとの連携のほか、特に使い方にクセがある Twitter Hunter 周りなど、 EXISTを活用する際に気づいた内容についてまとめています。
MISP の設定
MISP のフィード設定
外部のフィードから MISP に情報を収集するよう設定をします。
- [Sync Actions ]>[List Feeds]
- 「CIRCL OSINT Feed 」「The Botvrij.eu Data」の2つにチェックをいれます
- [Enable selected] ボタンを押します
- 確認ダイアログが表示されるので [Yes] を選びます
- [Fetch and store all feed data] ボタンを押します
- 「Pull queued for background execution.」と表示されれば OK です
[HOME] からメインページに戻るとデータが取り込まれているはずです。 取り込みには時間がかかるのでしばらく放っておくと順次追加されていきます。
EXIST の設定
前提作業
ここから先の作業はすべて root + Python仮想環境であることを前提にすすめます。
sudo su -
source /opt/exist/venv-exist/bin/activate
各種APIとの連携設定
基本設定:
cd /opt/exist/ cp scripts/insert2db/conf/insert2db.conf.template scripts/insert2db/conf/insert2db.conf ## Set EXIST Path sed -i -e "s/path\/to\/your\/exist/opt\/exist/g" scripts/insert2db/conf/insert2db.conf
MISP 以外の API 連携については、それぞれのサービスで取得する必要があります。 Malshare API は登録するだけで取得でき、Twitter API については少し手間がかかりますが、 Twitter API があると色々と楽しいので取得することをおすすめします。
API key を取得している場合は、以下のスクリプトの xxxxxxxxxx 部分をそれぞれ取得した API key に修正してから実行してください。
なお、API key の設定がされていない場合はそれらのサイトからの情報は取得されませんが、 API key 不要なサイトからも情報を収取しているので必ず必要なわけではありません。
## MISP API (Authkey) ## http://localhost/users/view/me MISP_API_KEY=xxxxxxxxxx sed -i -e "s/YOUR_MISP_URL/localhost\//g" -e "s/YOUR_MISP_API_KEY/${MISP_API_KEY}/g" scripts/insert2db/conf/insert2db.conf ## Malshare API(API Key) ## https://malshare.com/register.php MALSHARE_API_KEY=xxxxxxxxxx sed -i -e "s/YOUR_API_KEY/${MALSHARE_API_KEY}/g" scripts/insert2db/conf/insert2db.conf ## Twitter API(Consumer API keys, Access token) ## https://developer.twitter.com ## CK = Consumer API keys ## CS = Consumer API secret key ## AT = Access token ## AS = Access token secret TWITTER_CK=xxxxxxxxxx TWITTER_CS=xxxxxxxxxx TWITTER_AT=xxxxxxxxxx TWITTER_AS=xxxxxxxxxx sed -i -e "s/YOUR_CK/${TWITTER_CK}/g" -e "s/YOUR_CS/${TWITTER_CS}/g" -e "s/YOUR_AT/${TWITTER_AT}/g" -e "s/YOUR_AS/${TWITTER_AS}/g" scripts/insert2db/conf/insert2db.conf
API 連携処理の実行コマンドについて
以下のコマンドを実行することで各種情報を収取できます。 手打ちするのではなく cron に設定することが推奨されています。
- reputation/insert2db.py:外部サイトから脅威情報を収集します
- twitter/insert2db.py:Twitter からタイムラインを収取します
- exploit/insert2db.py:外部サイトから Exploit を収取します
- threat/insert2db.py:MISP から脅威情報を収集します
cd /opt/exist/
python3 scripts/insert2db/reputation/insert2db.py
python3 scripts/insert2db/twitter/insert2db.py
python3 scripts/insert2db/exploit/insert2db.py
python3 scripts/insert2db/threat/insert2db.py
API 連携処理の実行コマンドの cron 設定について
情報収取スクリプトを cron に設定します。 なお、MISP との連携処理はCPUパワーを食うようだったので1日1回としています。 取得間隔は必要に応じて調整してください。
crontab -e
MAILTO = '' LANG=ja_JP.UTF-8 ## EXIST */20 * * * * cd /opt/exist/; source venv-exist/bin/activate; bash -l -c 'python3 scripts/insert2db/reputation/insert2db.py' */03 * * * * cd /opt/exist/; source venv-exist/bin/activate; bash -l -c 'python3 scripts/insert2db/twitter/insert2db.py' */40 * * * * cd /opt/exist/; source venv-exist/bin/activate; bash -l -c 'python3 scripts/insert2db/exploit/insert2db.py' 00 05 * * * cd /opt/exist/; source venv-exist/bin/activate; bash -l -c 'python3 scripts/insert2db/threat/insert2db.py'
API 連携処理の実行コマンドについての補足説明
各スクリプトについてどんなことをしているのか確認してみました。
reputation/insert2db.py
以下から取得している。すべてフィードに準ずるもののようだった。 それほど更新頻度は高くないので、負荷を与えない範囲でcrontabに設定するといい。
- osint.bambenekconsulting.com (ドメイン名)
- osint.bambenekconsulting.com (IPアドレス)
- cinsscore.com (IPアドレス)
- cybercrime-tracker.net (URL, IPアドレス)
- www.dshield.org (ドメイン名)
- www.malshare.com (URL)※要APIkey
- www.malwaredomainlist.com (URL)
- inotr.net ※サイト閉鎖っぽい
- data.phishtank.com (URL)
- ransomwaretracker.abuse.ch (URL, IPアドレス, ドメイン名)
- www.networksec.org ※サイト閉鎖っぽい
- zeustracker.abuse.ch ※サイト閉鎖っぽい
twitter/insert2db.py
Twitter のタイムラインを取得している。 count パラメータで取得件数を変更できるらしいが、 スクリプトを見た感じ特にそういったクエリは投げていないようなのでデフォルトである20件を取得する様子。 Twitter API 側で 15回/15分 という制限があるので、それを超えないようにcrontabに設定するといい。
- GET statuses/home_timeline — Twitter Developers
https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-home_timeline
exploit/insert2db.py
cxsecurity.com と Exploit-DB.com のフィードから情報を取得している。 それほど更新頻度は高くないので、負荷を与えない範囲でcrontabに設定するといい。
threat/insert2db.py
MISP から情報を取得する。ローカルでのやりとりなのであまり制限は考えなくて良さそう。 ただ、やたらとCPUパワーを食う。 MISPの更新頻度がそれほど高くないこともあり1日1回程度で設定してみた。
Hunter用設定
特定のキーワードに基づいて情報を収集する機能。 Twitter と Threat の2種類があある。
基本設定:
cd /opt/exist/ cp scripts/hunter/conf/hunter.conf.template scripts/hunter/conf/hunter.conf ## Set EXIST Path sed -i -e "s/path\/to\/your\/exist/opt\/exist/g" scripts/hunter/conf/hunter.conf
結果を Slack に投げ込む場合の設定。
## Slack ## https://api.slack.com/apps sed -i -e "s/YOUR_TOKEN/xxxxxxxxxxxxx/g" scripts/hunter/conf/hunter.conf
Twitter Hunter について
Twitter API の設定ファイルは [auth-hunter00]~[auth-hunter18] まで19個の API key を設定できるようになっており、 それらのために 19個 のアプリを作成することが推奨されています。
[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 (snip)
複数のキーワードを収取する際に単独の API では制限にかかるためのようですが、Twitter API については以下のような注意事項があります。
- 10個以上の API key は取得できない
- 10個作った時点で「これ以上作るには別のアプリを削除してください」とメッセージが表示されてしまい、それ以上作成することができませんでした。10個以上取得するためには何か条件があるのかもしれません。
- 24時間以内に作成できる API key の個数は限られている
- Twitter アプリは24時間以内に作成できる数に制限があるようで、5個程度作った時点で「24時間待ってね」と表示がされ、待つ必要がありました。
とりあえず00~04の5個を登録しました。
ただし、Hunter の取得スクリプトは API key がすべて揃っている前提で動く作りになっているため、 以下の通りコマンドでスクリプトを修正する必要があります。
sed -i -e "s/randint(0,18)/randint(0,4)/g" scripts/hunter/twitter/tw_hunter.py
なお、API key を重複して登録すると高頻度でツイートの取得に失敗するので避けたほうが無難です。 取得が失敗しているのか空振りに終わっているのかはログファイル(/opt/exist/scripts/hunter/twitter/logs/hunter.log)を見れば確認できます。「再取得: Expecting value: line 1 column 1 (char 0)」とあるのが空振りです。
Twitter Hunter のキーワード設定について
キーワードを以下のように設定してみました。 Malware と EK の単語は脅威情報が拾えそうなワードを Twitter を眺めて見つけた順に選んでいます。
- CVE
cve 2019,cve 2018,cve 2017,cve 2016,cve 2015,cve 2014,cve 2013,cve 2012,cve 2011,cve 2010
- Malware
#Emotet,#TrickBot,#Ramnit,#Ursnif,#AgentTesla,#LokiBot,#NanoCore,#AZORult,#Netwire,#njRAT
- EK
#RIGEK,#FalloutEK,#PurpleFox,#RadioEK,#LewdEK,#SpelevoEK,#UnderminerEK,#GrandsoftEK
- PoC
poc pastebin com,poc github com,poc exploit-db com
なお、Twitter Hunter には Twitter API の制約などにより以下のような注意事項があります。
- 注意事項:
- 除外検索はできません(-RT など)
- 括弧"()"は機能しません
- 各種フィルタは使えません(-filter:retweet など)
- スペースによるAND検索とカンマによるOR検索が可能です
- 大文字と小文字は区別されません
- ドメイン名を検索したい場合はドットをスペースに置き換えて設定することが推奨されています(example.com -> example com)
- リツイートされたツイートは重複して拾われます
- スペース区切りではない言語には非対応です(日本語キーワードはスペースで区切られてツイートされている場合のみ検索可能です)
- ツイートが長い場合は後半部分が省略された状態で取得されます
その他の注意事項は以下を参照。
- Standard stream parameters — Twitter Developers
https://developer.twitter.com/en/docs/tweets/filter-realtime/guides/basic-stream-parameters
Hunter の処理実行
Hunter を実行するには以下のスクリプトを実行させます。
cd /opt/exist
python3 scripts/hunter/twitter/tw_watchhunter.py
python3 scripts/hunter/threat/th_watchhunter.py
一度実行させると Hunter が自動的にツイートを取得し続けてくれます(概ね20秒間隔)。 ただし、設定変更などによって Hunter が止まってしまう場合もあるようです 公式の説明によると cron で毎分実行することが推奨されています。
crontab -e
*/1 * * * * cd /opt/exist/; source venv-exist/bin/activate; bash -l -c 'python3 scripts/hunter/twitter/tw_watchhunter.py' */1 * * * * cd /opt/exist/; source venv-exist/bin/activate; bash -l -c 'python3 scripts/hunter/threat/th_watchhunter.py'
その他の API key について
VirusTotal の API key を入力することでハッシュ値などで検索した際に VirusTotal から関連情報を取得できます。 なお、EXIST には Behavior など詳細情報の表示タブもありますが、 これらは企業向けの有料 API でのみ取得可能で、個人向けの無料 APIでは取得できません。
## VirusTotal cp conf/vt.conf.template conf/vt.conf sed -i -e "s/YOUR_KEY/xxxxxxxxxxxxxxx/g" conf/vt.conf
geoip の設定項目もありますが、どこに効いているのか未確認です。
## GeoLite2 wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz gzip -d GeoLite2-City.mmdb.gz cp conf/geoip.conf.template conf/geoip.conf sed -i -e "s/path\/to\/your\/exist/opt\/exist/g" conf/geoip.conf
サイトスクリーンショットの過去ファイル削除
以下のように cron に設定しておきます。
crontab -e
00 05 * * * cd /opt/exist/; bash -l -c 'scripts/url/delete_webdata.sh' 00 05 * * * cd /opt/exist/; bash -l -c 'scripts/url/delete_oldtaskresult.sh'
MISP フィードの定期取得
以下のように cron に設定しておきます。
crontab -e
0 */2 * * * curl --header "Authorization: ${MISP_AUTHKEY}" --header "Accept: application/json" --header "Content-Type: application/json" http://localhost//feeds/fetchFromAllFeeds
参考文献
- サイバー脅威情報集約システム EXIST を構築する - setodaNote
https://soji256.hatenablog.jp/entry/2019/10/23/002216
自動化スクリプト作成周り
Automation and MISP API · User guide of MISP Malware Information Sharing Platform, a Threat Sharing Platform.
https://www.circl.lu/doc/misp/automation/curlコマンドでPOSTする - Qiita
https://qiita.com/sensuikan1973/items/b2085a9cdc6d1e97e8f8Bashで一時ファイルを作る方法
https://tex2e.github.io/blog/shell/tmpfile-best-practicemorituriのブログ : sed cコマンドの動作 (指定文字列で行を置き換え) 【Linuxコマンド】
http://blog.livedoor.jp/morituri/archives/52018209.html
更新履歴
- 2019/10/23 新規作成(ラフ版)
- 2019/10/24 cron の記述ミスを修正。
- 2019/10/24 参考文献を追記。
- 2019/10/24 API連携設定の自動化スクリプトについての記載を追記。
- 2019/10/24 Hunter に関する説明が誤っていたため修正(取得は自動実行ではなく cron に登録が必要でした)。
- 2019/11/12 サイトスクリーンショットの過去ファイル削除、MISPフィードの定期取得を追記。GeoLite2 の展開コマンドが誤っていたのを修正。