Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regist vulnrichment2tc.py #350

Merged
merged 3 commits into from
Sep 13, 2024
Merged

regist vulnrichment2tc.py #350

merged 3 commits into from
Sep 13, 2024

Conversation

dejima-shikou
Copy link
Collaborator

@dejima-shikou dejima-shikou commented Sep 13, 2024

PR の目的

  • 機能概要

    • vulnrichmentから各CVEのデータのcve_id、exploitation、automatableを取得し、cve_idがTCで登録済Topicに紐づくMispTag.tag_nameと一致するTopicのexploitation、automatableを更新する。
  • 実行手順

  1. https://github.com/cisagov/vulnrichment
    をクローンする。
  2. threatconnectome/scripts/vulnrichment2tc.py
    を実行する。
  • 引数
    url: ThreatconnectomeのAPI BASE URL
    -v: vulnrichmentルートディレクトリのパス
    -t: Threatconnectome APIのrefresh token
    ※-tオプションの代わりに環境変数THREATCONNECTOME_REFRESHTOKENでも指定可能
  • 出力
    正常実行時、1件のTopic更新毎に下記のようなデータを出力する。
    出力件数が多いため、出力結果をファイル出力することを推奨する。
    Success put topic. topic_id:d227c61c-bf82-42a1-b57b-b9735ce8550c cve_id:CVE-2020-5245 data: {'exploitation': 'public_poc', 'automatable': 'no'}

実行例)
cd ~/work/threatconnectome/scripts
pipenv shell
pipenv sync --dev
export THREATCONNECTOME_REFRESHTOKEN=<実際のrefresh tokenを指定>
python3 vulnrichment2tc.py -v ~/work/vulnrichment "http://localhost/api" > ../../log.txt

経緯・意図・意思決定

Topicが40524件、HITするCVEデータが3996件のローカル環境で実行時間が約24分かかった。
処理時間を分析した結果、1件あたりの処理時間は小さく件数が多いのが原因であり、大きく改善するのは困難と判断した。

  • vulnrichmentから全CVEファイルを読み込みメモリに保持する処理
    約2秒

  • TC API get /topics/search
    CVEデータ 28383件
    1件 0.04秒
    →約16分

  • TC API put /topics/{topic_id}
    CVEデータがTopicとHITした件数 3996件
    1件 0.08秒
    →約5分

@dejima-shikou dejima-shikou marked this pull request as ready for review September 13, 2024 07:56
Copy link
Collaborator

@mshim03 mshim03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mshim03 mshim03 merged commit 8f75020 into main Sep 13, 2024
4 checks passed
@mshim03 mshim03 deleted the topic/vulnrichment2tc branch September 13, 2024 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants