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

Feature/str exact match#79 #100

Merged
merged 14 commits into from
May 28, 2021
Merged

Feature/str exact match#79 #100

merged 14 commits into from
May 28, 2021

Conversation

itiB
Copy link
Collaborator

@itiB itiB commented May 12, 2021

StartsWithとEndsWith、Containsの実装を行い正規表現以外の一致ルールを作成する。

close #79

@itiB itiB self-assigned this May 12, 2021
@hach1yon
Copy link
Collaborator

ちょっと、気になる部分があって、parse_selection_recursively()という関数に引数を追加している部分ですね。
できれば、ルールを追加するときに変更するのはSelectionNodeトレイトをimplementしたクラスか、LeafMatcherトレイトをimplementしたクラスだけにしたいです。
ルールを追加する度にparse_selection_recursively()に引数を増やしていると、引数がすごく多くなってしまうので、できれば避けたいなという気持ちがあります。

@hach1yon
Copy link
Collaborator

あと、テストケースを書いてほしいです。
メインブランチにrule.rsのテストケースを追加したものをマージしているので、その辺を参考にしていただければと思います。

@itiB itiB force-pushed the feature/str_exact_match#79 branch from c26a9fd to 02154bb Compare May 23, 2021 13:33
@itiB itiB changed the title WIP: Feature/str exact match#79 Feature/str exact match#79 May 23, 2021
@itiB itiB requested review from hitenkoku and hach1yon May 23, 2021 16:29
@hach1yon
Copy link
Collaborator

@itiB
プルリクありがとうございます。
今仕事が立て込んでいるので、すぐ確認できないのですが、なるべく次のミーティング迄にレビューできるようにしようと思います。

@hach1yon
Copy link
Collaborator

hach1yon commented May 27, 2021

@itiB
正常系のパターンは正しく動いていて、良さそうです。さすがです。テストケースも良さそうです。

ちょっと、気になったのは以下の部分です。

ハイプに間違ったキーワードを指定した場合のエラー出力をしたい。

  • 例えば、今の実装だと、"contains"と書くべきところを"contain"と書いた場合、書き間違いに気づけないという問題があるかなと思います。
  • SelectionNodeトレイトを実装した構造体にはinit()という関数があって、この戻り値にResult::Errを返すと、detection.rsのparse_rule_filesでルールファイルのパースエラーを出力するような感じになっています。
  • パイプ(|)で指定できるのは、startsWithとendsWithとcontainsの3つだけだったと思うので、それ以外の文字列がハイプに指定されていた場合、init関数でエラー出力されるようにしてほしいです。

new()関数に実装している内容をinit()関数に移動したい。

  • LeafSelectionNode::new()関数で、StartsWithMatcher等の生成をしていますが、LeafSelectionNode::new()関数は前のままの内容にしておいて、init()関数にStartsWithMatcher等の生成を移動したいです。
  • SelectionNodeトレイトの設計方針として、ルールファイルのパースやパースエラーはinit()関数で実装するようになっていて、new()関数だとエラーは返せません。ハイプに間違ったキーワードを指定した場合のエラー出力する処理はinit()関数に書くので、StartsWithMatcher等の生成処理もinit関数にまとめた方が書きやすいような気がします。

Copy link
Collaborator

@hitenkoku hitenkoku left a comment

Choose a reason for hiding this comment

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

@ichiichi11 さんのレビューコメントを追加しておきました。とりあえずCommentで出しておきます

let mut fixed_key_list = Vec::new();
for key in &key_list {
if key.contains('|') {
let v: Vec<&str> = key.split('|').collect();
Copy link
Collaborator

@hitenkoku hitenkoku May 27, 2021

Choose a reason for hiding this comment

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

@ichiichi11 さんの記載に関連するところをコードと紐づけてレビューに入れておきました。(レビュー内容とコメントでのやり取りを容易にするため)

ハイプに間違ったキーワードを指定した場合のエラー出力をしたい。
例えば、今の実装だと、"contains"と書くべきところを"contain"と書いた場合、書き間違いに気づけないという問題があるかなと思います。
SelectionNodeトレイトを実装した構造体にはinit()という関数があって、この戻り値にResult::Errを返すと、detection.rsのparse_rule_filesでルールファイルのパースエラーを出力するような感じになっています。
パイプ(|)で指定できるのは、startsWithとendsWithとcontainsの3つだけだったと思うので、それ以外の文字列がハイプに指定されていた場合、init関数でエラー出力されるようにしてほしいです。あと、現状パイプが複数あることもないと思うので、その場合もエラーにしてほしいです。

Copy link
Collaborator

Choose a reason for hiding this comment

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

@itiB 私の方でも確認しました。問題ないと思います。 @ichiichi11 さんが記載いただいているとところとして

こちらですが、現状のSIGMAルールの内容を確認したところ、パイプ(|)の後につながるものとしてallとかがあります(参照)。今回の作成範囲ではないので切り分けとして、init関数で想定していないルールのパイプが出てきたらエラー出力させるようにするのは賛成です。

https://github.com/SigmaHQ/sigma/blob/fb07b204b4f0284ebf6e684d5e55513c26dc932d/rules/windows/builtin/win_cobaltstrike_service_installs.yml

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

パイプでつなげられたものを含めてエラーが出るように変更しました、
また下のほうにエラーが出ることを確認するテストケースを追加しました。

こうやって new()init() を使い分けるのですね....いままであんまり考えずに書いていました😥
指摘ありがとうございます!

Copy link
Collaborator

Choose a reason for hiding this comment

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

@itiB
いい感じなので、マージしました。

new() と init() を使い分けについては、今回は自分がそういう意図で設計していたので、指摘させてもらいました。こういうファイルをパースするような時の実装方法・設計方針は色々あると思うので、必ずしもこの方法が良いという感じではないです。

最初にSelectionNodeとかLeafMatcherとかのトレイト作ったのは私で、自分以外の人に設計意図が伝わらないソースを書いてしまったという私の問題かなーと思いました。もうちょっと、コメントを書くようにします。

src/detections/rule.rs Outdated Show resolved Hide resolved
@hitenkoku
Copy link
Collaborator

hitenkoku commented May 27, 2021

@itiB さん 私の方でも確認致しました。動作として問題ないと思います。 @ichiichi11 さんのコメントはやり取りをConversationで管理したほうが良いと思いますので私のレビューのほうに入れておきました。

@hach1yon hach1yon merged commit b22051e into main May 28, 2021
@hach1yon hach1yon deleted the feature/str_exact_match#79 branch May 28, 2021 14:32
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.

[SIGMAルール] contains,startsWith,endsWith対応
3 participants