LoginSignup
3
1

More than 3 years have passed since last update.

Splunk BOSS of the SOCを可視化(Sankey diagram)

Last updated at Posted at 2019-10-05

.conf 2017 Splunk Championの中村さんの話を聞く機会があって、刺激を受けたのでやってみる。
中村さんの.conf 2017の資料も参考に。

最初はGOJASのSlackに上がっていたUsing data & Splunk ML Toolkit to predict crime
google翻訳をやろうとして断念
.conf 2018の資料はここ

Sankey Diagram

ダウンロードはここ、使い方はここ

qiita1.png

SPL
index=botsv1 sourcetype=iis c_ip=40.80.148.42 sc_status=200
| stats count dc(cs_uri_stem) as uri by cs_method,cs_uri_stem

これも綺麗だけど、URLの構成ごとに分けてみる。

qiita2.png

SPL
index=botsv1 (sourcetype=iis c_ip=40.80.148.42 sc_status=200) OR (src_ip=40.80.148.42 sourcetype=suricata eventtype=suricata_eve_http http.status=200)
| eval method=coalesce(cs_method,http_method)
| eval url=coalesce(cs_uri_stem,'http.url')
| eval url="/".method.url
| rex field=url max_match=6 "(?<uri>/[^/]+)"
| fields uri
| table _time,uri
| eval second_tmp=mvindex(uri,1,6)
| mvexpand uri
| streamstats count by _time
| eval second_uri=mvindex(second_tmp,count-1)
| eval uri=replace(uri,"/([A-Z]+)","\1")
| eval second_uri=replace(second_uri,"\?.+","")
| stats count  by uri,second_uri

解説

... | stats <stats_function>(<size_field>) [<stats_function>(<color_field>)] by <source_category_field> <target_category_field>

Sankey Diagramの構成は上記のとおり。
今回は

始め 終わり 大きさ
uri second_uri count なし

でフィールドを作った。

urlを要素に分けるまでは簡単だったけど、交互にするのがよくわからずハマった。

何とかなった方法として
| eval second_tmp=mvindex(uri,1,6)
でマルチバリューなURLを一つずらしてつくった。例として

uri second_uri
/POST
/joomla
/index.php
/joomla
/index.php

mvexpand uriすると

uri second_uri
/POST /joomla
index.php
/joomla /joomla
index.php
index.php

となる。
それをstreamstatsでつくったカウンターでsecond_uriの値を取り出していく。
mvindexのカウンターが0から始まるので-1

methodは正規表現で取り出すために/をつけていたのを外して、
IDSのログにはクエリーがたくさん出ていたので、それをreplaceで消してあげた。
本来ならこれをよく調べなきゃいけないけど、今回は無視。

最後にstatsでまとめて、表を作ってVisualization

まとめ

Sankey Diagramはstatsで作らなくても表を作ればいい。

始め 終わり
A B
B C
C

の表を作るのが大変なので、appendcolsappendで作ってもよかったと思う。

:sweat:大きさがcountであればなおさらですね。
実際、順序関係はSplunk側でやってもらえるので大きさのところをしっかりやれば

始め 終わり
B C
A B
C

みたいなバラバラでもきちんと表示してくれる。

:cry: 簡単に作れるようになりたい。

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