# Tracking & managing unstructured IoCs with MISP [InQuest](https://inquest.net/)の[ThreatIngestor](https://github.com/InQuest/ThreatIngestor)を使うと、構造化されていないIoC(e.g blogやtweetなど)を取集することができます。 - Supported IoC: - IP address, domain, URL, hash(MD5, SHA1, SHA256, SHA512), YARA rule - Input: - Beanstalk work queues, Git repositories, GitHub repository search, RSS feeds, Amazon SQS queues, Twitter, Generic web pages - Output: - Beanstalk work queues, CSV files, MISP, MySQL table, SQLite database, Amazon SQS queues, ThreatKB, Twitter しかし、ThreatIngestorには、最新版の[MISP](https://www.misp-project.org/)には対応していないという問題があります。 これを修正するためのPRを送ってみましたが、InQuestに対応してもらえていないので、ThreatIngestorをフォークしてMISPとうまく連携するツールを作成しました。 - [iocingestor](https://github.com/ninoseki/iocingestor) MISPとの連携を可能にすると共に、"not for me"ないくつかの機能は削除してしまっています。 - Supported IoC: - IP address, domain, URL, hash(MD5, SHA1, SHA256, SHA512), ~~YARA rule~~ - Input: - ~~Beanstalk work queues~~, ~~Git repositories~~, GitHub repository search, RSS feeds, ~~Amazon SQS queues~~, Twitter, Generic web pages - Output: - ~~Beanstalk work queues~~, CSV files, MISP, ~~MySQL table~~, SQLite database, ~~Amazon SQS queues, ThreatKB, Twitter~~ ## インストール ```sh pip install iocingestor ``` ## 使い方 ここでは、 "構造化されてないIoC"の例としてTwitterを取り上げます。 ![](https://i.imgur.com/em74ibm.png) こういったIoCが含まれているtweetから、iocingestorを使ってIoCを抽出してみましょう。 iocingestorの設定はYAMLファイルで行われます。 ```yaml # config.yml general: daemon: true sleep: 900 state_path: /tmp/state.db credentials: - name: twitter-auth api_key: foo api_secret_key: bar access_token: foo access_token_secret: bar - name: misp-auth url: htts://mymisp key: foo ssl: False sources: - name: twitter-inquest-c2-list module: twitter credentials: twitter-auth owner_screen_name: InQuest slug: IOC-feed - name: twitter-papa-san module: twitter credentials: twitter-auth q: "from:@papa_anniekey OR to:@papa_anniekey" operators: - name: sqlite-db module: sqlite filename: /tmp/artifacts.db - name: misp-instance module: misp credentials: misp-auth ``` Note: `credentials`の`twitter-auth`と`misp-auth`には、ご自身の認証情報を入れてください。 - https://developer.twitter.com/en/docs/basics/authentication/oauth-1-0a/obtaining-user-access-tokens - https://www.circl.lu/doc/misp/automation/#general なお、MISPを使っていない方の場合、`credentials`と`operators`からMISPの設定を削除してください。 この設定ファイルを使ってiocingestorを動かしてみましょう。 ```sh $ iocingestor config.yml 2020-04-13 21:47:13.893 | DEBUG | iocingestor:__init__:27 - Reading config from 'tmp/config.yml' 2020-04-13 21:47:13.905 | DEBUG | iocingestor:__init__:38 - Log handler reconfigured 2020-04-13 21:47:13.908 | DEBUG | iocingestor:__init__:50 - Opening state database '/tmp/state.db' 2020-04-13 21:47:13.912 | DEBUG | iocingestor:__init__:59 - Initializing sources 2020-04-13 21:47:13.912 | DEBUG | iocingestor.config:sources:106 - Found source 'twitter-inquest-c2-list' 2020-04-13 21:47:14.558 | DEBUG | iocingestor.config:sources:106 - Found source 'twitter-papa-san' 2020-04-13 21:47:14.558 | DEBUG | iocingestor.config:sources:111 - Found 2 total sources 2020-04-13 21:47:14.558 | DEBUG | iocingestor:__init__:64 - Initializing operators 2020-04-13 21:47:14.558 | DEBUG | iocingestor.config:operators:158 - Found operator 'sqlite-db' 2020-04-13 21:47:14.560 | DEBUG | iocingestor.config:operators:158 - Found operator 'misp-instance' 2020-04-13 21:47:14.796 | DEBUG | iocingestor.config:operators:167 - Found 2 total operators 2020-04-13 21:47:14.878 | DEBUG | iocingestor:__init__:76 - Load whitelists 2020-04-13 21:47:14.879 | DEBUG | iocingestor:run:93 - Running forever, in a loop 2020-04-13 21:47:14.879 | DEBUG | iocingestor:run_once:107 - Running source 'twitter-inquest-c2-list' 2020-04-13 21:47:14.879 | DEBUG | iocingestor.state:get_state:37 - Getting state for 'twitter-inquest-c2-list' 2020-04-13 21:47:15.402 | DEBUG | iocingestor.sources:process_element:125 - Processing in source 'twitter-inquest-c2-list' 2020-04-13 21:47:15.581 | DEBUG | iocingestor.sources:process_element:234 - Found 1 total artifacts 2020-04-13 21:47:15.582 | DEBUG | iocingestor.sources:process_element:235 - Type breakdown: {'domain': 0, 'hash': 0, 'ipaddress': 0, 'task': 1, 'url': 0} ... 2020-04-13 21:47:22.366 | NOTIFY | iocingestor:run_once:153 - New artifacts: {'task': 34, 'hash': 2, 'url': 2, 'domain': 5, 'ipaddress': 2} 2020-04-13 21:47:22.366 | DEBUG | iocingestor:run_forever:161 - Sleeping for 900 seconds ``` 何個か新しいIoCを取得することができました。 MISPで取得したIoCを確認してみます。 ![](https://i.imgur.com/ufBGF9w.png) ![](https://i.imgur.com/cmIjAvG.png) MISPを使っていない方の場合、hugを使ってSQLiteを確認してみるといいでしょう。 ```sh cd /tmp hug -m iocingestor.extras.webapp # => localhost:8000 ``` ![](https://i.imgur.com/rGbKUxj.png) デフォルトでは、iocingestorは900秒ごとに更新を行います。 バックグラウンドで動かしたままにしておくためには、下記のような内容でSystemdのサービスとして登録しておくと便利でしょう。 ```service [Unit] Description=iocingestor After=network.target [Service] Type=simple User=foo WorkingDirectory=/opt/iocingestor ExecStart=/usr/local/bin/iocingestor config.yml Restart=always [Install] WantedBy=multi-user.target ``` ## 最後に 今回はTwitterを例にiocingestorの使い方を説明しましたが、Twitterだけではなく、WebサイトやRSSフィードからIoCを取得することもできます。 よろしければ使ってみてください。