LoginSignup
2

More than 1 year has passed since last update.

posted at

updated at

Splunkにaudit.logを取り込んでSplunk初回起動時の挙動を調べる

はじめに

Splunk Enterpriseをはじめて起動すると画面に色んな処理メッセージが出力されます。

初回起動メッセージ例(クリックすると展開します)
# /opt/splunk/bin/splunk start --accept-license --seed-passwd password

This appears to be your first time running this version of Splunk.
Copying '/opt/splunk/etc/openldap/ldap.conf.default' to '/opt/splunk/etc/openldap/ldap.conf'.
Generating RSA private key, 2048 bit long modulus
.................................+++++
...........................+++++
e is 65537 (0x10001)
writing RSA key

Generating RSA private key, 2048 bit long modulus
.............................................................................+++++
.................................................................+++++
e is 65537 (0x10001)
writing RSA key

Moving '/opt/splunk/share/splunk/search_mrsparkle/modules.new' to '/opt/splunk/share/splunk/search_mrsparkle/modules'.

Splunk> See your world.  Maybe wish you hadn't.

Checking prerequisites...
    Checking http port [8000]: open
    Checking mgmt port [8089]: open
    Checking appserver port [127.0.0.1:8065]: open
    Checking kvstore port [8191]: open
    Checking configuration... Done.
        Creating: /opt/splunk/var/lib/splunk
        Creating: /opt/splunk/var/run/splunk
        Creating: /opt/splunk/var/run/splunk/appserver/i18n
        Creating: /opt/splunk/var/run/splunk/appserver/modules/static/css
        Creating: /opt/splunk/var/run/splunk/upload
        Creating: /opt/splunk/var/run/splunk/search_telemetry
        Creating: /opt/splunk/var/spool/splunk
        Creating: /opt/splunk/var/spool/dirmoncache
        Creating: /opt/splunk/var/lib/splunk/authDb
        Creating: /opt/splunk/var/lib/splunk/hashDb
New certs have been generated in '/opt/splunk/etc/auth'.
    Checking critical directories...    Done
    Checking indexes...
        Validated: _audit _internal _introspection _metrics _telemetry _thefishbucket history main summary
    Done
    Checking filesystem compatibility...  Done
    Checking conf files for problems...
    Done
    Checking default conf files for edits...
    Validating installed files against hashes from '/opt/splunk/splunk-8.0.2.1-f002026bad55-linux-2.6-x86_64-manifest'
    All installed files intact.
    Done
All preliminary checks passed.

Starting splunk server daemon (splunkd)...  
Generating a RSA private key
...............................................+++++
...............+++++
writing new private key to 'privKeySecure.pem'
-----
Signature ok
subject=/CN=aio/O=SplunkUser
Getting CA Private Key
writing RSA key
Done
 [  OK  ]

Waiting for web server at http://127.0.0.1:8000 to be available.... Done


If you get stuck, we're here to help.  
Look for answers here: http://docs.splunk.com

The Splunk web interface is at http://aio:8000


メッセージ内容から察するに、何かファイルを作成しているようです。
そこで、今回は初回起動時に何が作成されるか?ということをSplunkで調査してみました。

※本調査ではOSの監査設定変更を行います。ディストリビューションにより設定方法やログフォーマットに差異がある可能性がありますのでご注意ください。

調査時の環境

OS: Amazon Linux 2 (4.14.171-136.231.amzn2.x86_64)
Splunkバージョン: 8.0.2.1
Splunkインストールパス($SPLUNK_HOME): /opt/splunk

1.Splunk Enterpriseインストール

Splunkをインストールします。詳細手順は省略させていただきますが、今回はtgzファイルでインストールします。

SplunkEnterpriseを/opt/ディレクトリにインストールする
tar fvxz /tmp/splunk-8.0.2.1-f002026bad55-Linux-x86_64.tgz -C /opt/

2.監査ログ出力設定

Splunkの設定ディレクトリの変更情報を監査ログに出力させるため、OSの設定変更を行います。

監査ログを設定する(一時変更)
# 監査対象ディレクトリを追加する
auditctl -w /opt/splunk/etc/ -p wa -k etc_changes
# 設定が追加されたことを確認する
auditctl -l
# コマンド結果が出力されればOK。"No rules"と表示される場合は設定が正しいかご確認ください。

3.Splunk Enterprise起動

Splunk Enterpriseを起動します。
※以下のコマンド例は、管理者パスワードをpasswordにしているためあまりセキュアではありません。必要に応じて任意のパスワードをご指定下さい。

SplunkEnterpriseを起動する
/opt/splunk/bin/splunk start --accept-license --seed-passwd password

4.監査ログ出力確認

手順2で設定した監査対象ディレクトリの変更情報がログに出力されているか確認します。

監査対象ディレクトリの変更情報がログに出力されているか確認する
grep /opt/splunk/etc/ /var/log/audit/audit.log | tail
# ログが1件以上出力されていればOKです。

5.監査ログ取り込み

監査ログをSplunkに永続的に取り込むよう設定します。
※調査目的のためmainインデックスに取り込む設定にしています。別インデックスに取り込みたい場合は引数に-index <index名>を指定します。
※CLIで取り込み設定を行っているため、設定情報は/opt/splunk/etc/apps/search/local/inputs.confに記録されます。

監査ログを永続的に取り込むよう設定する
/opt/splunk/bin/splunk add monitor /var/log/audit/audit.log -auth admin:password

6.取り込み結果の確認

以上の設定が完了しましたら、Splunkに監査ログが取り込まれているはずですので、Splunk Enterpriseにログインし、サーチ文で取り込み結果を確認します。

監査ログをサーチする
sourcetype="linux_audit" type="PATH" nametype!="PARENT"
| rex field=name "^(?<directory>.*\/)?(?<file>.*)"
| eval directory=if(len(mode)==6,directory+file,directory),file=if(len(mode)==6,"",file)
| table _time,msg,nametype,mode,directory,file
| sort msg

サーチ文の解説

1行目・・・監査ログのうち、typeフィールドがPATHかつnametypeフィールドがPARENT ではないイベントをサーチしています。
2~3行目・・・nameフィールドに記録されているパス情報からディレクトリ名とファイル名をそれぞれ新規フィールド(directory,file)フィールドに設定しています。
4行目・・・サーチ結果から可視化に必要なフィールドだけを整形して表示しています。
5行目・・・msgフィールドにタイムスタンプとID情報が記録されているため、msgフィールド順に並べ替えて表示しています。

7.結果

今回の環境でサーチした結果を一部抜粋して掲載いたします。

クリックすると展開して表示します。
image.png
image.png
image.png
image.png

8.分析

サーチ結果を分析したところ、Splunkは初回起動時に/opt/splunk/etc/ディレクトリにおいて以下の順番でファイル/ディレクトリの作成処理が動作していることが判りました。
※処理過程で何度か更新されるファイルもあるようですが、更新処理については割愛させていただきます。

Seq ファイル 備考
1 /opt/splunk/etc/splunk-launch.conf splunk-lanch.conf.defaultからコピーして作成される。
2 /opt/splunk/etc/licenses/download-trial/enttrial.lic 試用版ライセンスファイル。/opt/splunk/splunk-enttrial.licからコピーして作成される。
3 /opt/splunk/etc/auth/splunk.secret Splunkの設定ファイルに保存されている機密情報(パスワードなど)の暗号化/複合化で使用するキーファイル。
4 /opt/splunk/etc/system/local/user-seed.conf 初期管理ユーザーとパスワードの設定ファイル(バージョン7.1以降)後続処理で/opt/splunk/etc/passwdが作成されたら削除される。
5 /opt/splunk/etc/system/local/inputs.conf データ取り込み設定でhostフィールドを指定しなかった場合のデフォルト値が設定される。
6 /opt/splunk/etc/system/local/server.conf
7 /opt/splunk/etc/system/local/migration.conf
8 /opt/splunk/etc/openldap/ldap.conf ldap.conf.defaultからコピーして作成される。
9 /opt/splunk/etc/auth/audit/private.pem
10 /opt/splunk/etc/auth/audit/public.pem
11 /opt/splunk/etc/auth/distServerKeys/private.pem 分散サーチの通信で使う秘密鍵。
12 /opt/splunk/etc/auth/distServerKeys/trusted.pem 分散サーチの通信で使う公開鍵。
13 /opt/splunk/etc/auth/ca.pem ルートCA証明書。ca.pem.defaultからコピーして作成。
14 /opt/splunk/etc/auth/cacert.pem ルートCA証明書。cacert.pem.defaultからコピーして作成される。証明書の内容はca.pemと同じだが、ファイル内にパスフレーズつき秘密鍵が追記されている。
15 /opt/splunk/etc/myinstall/splunkd.xml
16 /opt/splunk/etc/users/users.ini
17 /opt/splunk/etc/auth/serverkey.pem Splunkの内部通信の暗号化で使うサーバー証明書作成に必要な秘密鍵。初回起動処理中に削除される。
18 /opt/splunk/etc/auth/serverreq.pem Splunkの内部通信の暗号化で使うサーバー証明書作成をルートCAに依頼するCSR。初回起動処理中に削除される。
19 /opt/splunk/etc/auth/servercert.pem Splunkの内部通信の暗号化で使うサーバー証明書。Splunk自身が持つルートCAが発行する。初回起動処理中に削除される。
20 /opt/splunk/etc/auth/server.pem Splunkの内部通信の暗号化で使うサーバー証明書。このサーバー証明書の有効期限は初回起動から3年で、CNは常にSplunkServerDefaultCertが設定される。 このファイルにはサーバー証明書の他にサーバーの秘密鍵とルートCA証明書情報が追記されている。
21 privKeySecure.pem SplunkのWeb画面の暗号化通信(https)で使うサーバー証明書作成に必要な秘密鍵。初回起動処理中に削除される。
22 req.pem SplunkのWeb画面の暗号化通信(https)で使うサーバー証明書作成をCAに依頼するCSR。初回起動処理中に削除される。
23 /opt/splunk/etc/auth/splunkweb/cert.pem SplunkのWeb画面の暗号化通信(https)で使うサーバー証明書。Splunk自身が持つルートCAが発行する。このサーバー証明書の有効期限は初回起動から3年で、CNはサーバーのホスト名が設定される。
24 ca.srl ルートCAが発行したサーバー証明書のシリアル番号が記録されたファイル。
25 /opt/splunk/etc/auth/splunkweb/privkey.pem SplunkのWeb画面の暗号化通信(https)で使うサーバー証明書の秘密鍵。
26 /opt/splunk/etc/instance.cfg Splunk固有ID(GUID)が記録されたファイル。
27 /opt/splunk/etc/passwd ユーザー情報。初回起動時は管理者ユーザーのみ記録されている。
28 /opt/splunk/etc/apps/learned/metadata/local.meta
29 /opt/splunk/etc/apps/learned/local/props.conf

余談

今回のきっかけは「Splunkの初回起動時に、Splunkの暗号化通信処理でデフォルトで使用されるサーバー証明書がどのように作成されるか」をみるためでしたが、結果的に他の設定ファイルの作成処理の流れも把握できました。デフォルトの証明書に関する調査はまた情報を整理して投稿したいと思います。

ここまで読んでいただき、誠にありがとうございました。

続編

続編を書きました。
Splunkにaudit.logを取り込んでSplunkweb初回ログイン時の挙動を調べる

参考

6.6.AUDITログファイルについて
Redhat公式のマニュアルですが、Auditログの仕様情報が記載されています。ただし、AmazonLinux2はRhel7ベースであるものの、若干ログのフォーマット(フィールド)がチューニングされているようです。

auditdでLinuxのファイル改竄検知を行う

What is the splunk.secret file, and is it possible to change it?
splunk.secretとはなんぞや?という疑問に関するSpunk公式コミュニティサイトのQAです。

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
What you can do with signing up
2