Chapter 05無料公開

Webサーバのアクセスログからランブックを生成する

Ken’ichiro Oyama
Ken’ichiro Oyama
2023.01.16に更新

runnはNGINXやApacheが出力するアクセスログからもランブックを生成できます。

例として以下のようなアクセスログがあるとします。

$ cat access_log
183.87.255.54 - - [18/May/2019:05:37:09 +0200] "GET /?post=%3script%3ealert(1); HTTP/1.0" 200 42433
62.109.16.162 - - [18/May/2019:05:37:12 +0200] "GET /core/files/js/editor.js/?form=\xeb\x2a\x5e\x89\x76\x08\xc6\x46\x07\x00\xc7\x46\x0c\x00\x00\x00\x80\xe8\xdc\xff\xff\xff/bin/sh HTTP/1.0" 200 81956
87.251.81.179 - - [18/May/2019:05:37:13 +0200] "GET /login.php/?user=admin&amount=100000 HTTP/1.0" 400 4797
103.36.79.144 - - [18/May/2019:05:37:14 +0200] "GET /authorize.php/.well-known/assetlinks.json HTTP/1.0" 200 9436

runn new でアクセスログをランブック形式に変換する

cat access_log にそのままパイプでつないで | runn new を実行すると、アクセスログをランブック形式に変換して標準出力に出力します。

$ cat access_log | runn new
desc: Generated by `runn new`
runners:
  req: https://dummy.example.com
steps:
  - req:
      /?post=%3script%3ealert(1);:
        get:
          body: null
  - req:
      /core/files/js/editor.js/?form=xebx2ax5ex89x76x08xc6x46x07x00xc7x46x0cx00x00x00x80xe8xdcxffxffxff/bin/sh:
        get:
          body: null
  - req:
      /login.php/?user=admin&amount=100000:
        get:
          body: null
  - req:
      /authorize.php/.well-known/assetlinks.json:
        get:
          body: null
$

[コラム] アクセスログのパース

runnではアクセスログのパースに https://github.com/Songmu/axslogparser パッケージを使用しています。

https://github.com/Songmu/axslogparser パッケージは複数のアクセスログのフォーマットに対応しています。runnではaxslogparser.GuessParserを使用してフォーマットを特定しパースしています。