rabbit-slide-kenhys-tokyodebian-modsecurity-20210220 2021.02.20.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rabbit +1 -0
- data/README.md +14 -0
- data/Rakefile +17 -0
- data/config.yaml +24 -0
- data/images/profile.png +0 -0
- data/pdf/tokyodebian-modsecurity-20210220-tokyodebian-modsecurity.pdf +0 -0
- data/theme.rb +5 -0
- data/tokyodebian-modsecurity.md +332 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9524d579d45d9525d42f0a9de11510781461616150ae0c3c7855dc04f87b7c8d
|
4
|
+
data.tar.gz: 629f9484b534f9f99f4b81fe2ac0ed53c45fc5f44a0c54c06644b6ea77e72ebf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 784e70c936f9723d2756781d035dcd8ae428e056465943a80b08a6431204e4ac8c4b71a57b570aec5878d902e7860ebb21b3aa5b85432d435088f156d824a4da
|
7
|
+
data.tar.gz: dd5d973ff21fafb0248a51405dcc54dc6b2778be839ae4efdcf7631352f22d54beb87582443541520ab69ec1f0c80656c47eadf021e76d50f809184539c8802e
|
data/.rabbit
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--size=1024,768 tokyodebian-modsecurity.md
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rabbit/task/slide"
|
2
|
+
|
3
|
+
# Edit ./config.yaml to customize meta data
|
4
|
+
|
5
|
+
spec = nil
|
6
|
+
Rabbit::Task::Slide.new do |task|
|
7
|
+
spec = task.spec
|
8
|
+
# spec.files += Dir.glob("doc/**/*.*")
|
9
|
+
# spec.files -= Dir.glob("private/**/*.*")
|
10
|
+
# spec.add_runtime_dependency("rabbit-theme-YOUR-THEME")
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Tag #{spec.version}"
|
14
|
+
task :tag do
|
15
|
+
sh("git", "tag", "-a", spec.version.to_s, "-m", "Publish #{spec.version}")
|
16
|
+
sh("git", "push", "--tags")
|
17
|
+
end
|
data/config.yaml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
---
|
2
|
+
id: tokyodebian-modsecurity-20210220
|
3
|
+
base_name: tokyodebian-modsecurity
|
4
|
+
tags:
|
5
|
+
- rabbit
|
6
|
+
- modsecurity
|
7
|
+
presentation_date: 2021-02-20
|
8
|
+
presentation_start_time:
|
9
|
+
presentation_end_time:
|
10
|
+
slideshare_id:
|
11
|
+
version: 2021.02.20.3
|
12
|
+
licenses:
|
13
|
+
- CC-BY-SA-4.0
|
14
|
+
slideshare_id: kenhys
|
15
|
+
speaker_deck_id:
|
16
|
+
vimeo_id:
|
17
|
+
youtube_id:
|
18
|
+
author:
|
19
|
+
markup_language: :md
|
20
|
+
name: Kentaro Hayashi
|
21
|
+
email: kenhys@gmail.com
|
22
|
+
rubygems_user: kenhys
|
23
|
+
slideshare_user:
|
24
|
+
speaker_deck_user:
|
data/images/profile.png
ADDED
Binary file
|
Binary file
|
data/theme.rb
ADDED
@@ -0,0 +1,332 @@
|
|
1
|
+
# DebianでWAF
|
2
|
+
|
3
|
+
subtitle
|
4
|
+
: ModSecurity-nginx 1.0.1による\\nWeb Application Firewall
|
5
|
+
|
6
|
+
author
|
7
|
+
: Kentaro Hayashi
|
8
|
+
|
9
|
+
institution
|
10
|
+
: ClearCode Inc.
|
11
|
+
|
12
|
+
content-source
|
13
|
+
: 2021年2月 東京エリア・関西合同Debian勉強会
|
14
|
+
|
15
|
+
allotted-time
|
16
|
+
: 20m
|
17
|
+
|
18
|
+
theme
|
19
|
+
: .
|
20
|
+
|
21
|
+
# スライドは公開済みです
|
22
|
+
|
23
|
+
* この資料はRabbit Slide Showで公開済み
|
24
|
+
* DebianでWAF - ModSecurity-nginx 1.0.1による\\nWeb Application Firewall
|
25
|
+
* <https://slide.rabbit-shocker.org/authors/kenhys/tokyodebian-modsecurity-20210220/>
|
26
|
+
|
27
|
+
|
28
|
+
# プロフィール
|
29
|
+
|
30
|
+
![](images/profile.png){:relative-height="60" align="right"}
|
31
|
+
|
32
|
+
* ひよこDebian Developer
|
33
|
+
* 2020/09になったばかり
|
34
|
+
* twitter: @kenhys
|
35
|
+
* トラックポイント(ソフトドーム派)
|
36
|
+
* わさビーフ(わさっち派)
|
37
|
+
|
38
|
+
# 本日の内容
|
39
|
+
|
40
|
+
* WAFとは
|
41
|
+
* 自由なWAF
|
42
|
+
* ModSecurityを試すには
|
43
|
+
|
44
|
+
* **注:誤りについては指摘してもらえると助かります**
|
45
|
+
|
46
|
+
# WAFとは
|
47
|
+
|
48
|
+
* Web Application Firewall
|
49
|
+
* Webサイトへの攻撃の影響を低減するためのもの
|
50
|
+
* 攻撃と判断した通信を遮断する
|
51
|
+
|
52
|
+
# WAFの提供形態
|
53
|
+
|
54
|
+
* アプライアンス型(専用機器設置)
|
55
|
+
* サービス型(外部提供のWAFサービスを利用)
|
56
|
+
* **ソフトウェア型** (今回はコレ!)
|
57
|
+
|
58
|
+
# WAFへの理解を深めるには
|
59
|
+
|
60
|
+
* 「Web Application Firewallの導入に向けた検討項目」
|
61
|
+
* <https://www.ipa.go.jp/files/000072484.pdf>
|
62
|
+
|
63
|
+
* 「Web Application Firewall 読本」
|
64
|
+
* <https://www.ipa.go.jp/files/000017312.pdf>
|
65
|
+
|
66
|
+
# 自由なWAF
|
67
|
+
|
68
|
+
* Shadow Daemon - GPL-2.0 or later
|
69
|
+
* <https://shadowd.zecure.org/>
|
70
|
+
* 言語ごとのconnectorをインストールする
|
71
|
+
* NAXSI(Nginx) - GPL-3.0
|
72
|
+
* <https://github.com/nbs-system/naxsi>
|
73
|
+
* **ModSecurity(Apache/Nginx)** Apache-2.0
|
74
|
+
* <https://modsecurity.org/>
|
75
|
+
|
76
|
+
# ModSecurity in Debian
|
77
|
+
|
78
|
+
* For Apache
|
79
|
+
* libapache2-mod-security2
|
80
|
+
* ModSecurity 2.x
|
81
|
+
|
82
|
+
* For Nginx
|
83
|
+
* パッケージはない
|
84
|
+
* <https://github.com/SpiderLabs/ModSecurity-nginx>
|
85
|
+
* 最新版は1.0.1 (ModSecurity 3.0.3以降)
|
86
|
+
|
87
|
+
# ModSecurity For Apache
|
88
|
+
|
89
|
+
```sh
|
90
|
+
$ sudo apt install apache2 modsecurity-crs \
|
91
|
+
libapache2-mod-security2
|
92
|
+
$ sudo a2enmod security2
|
93
|
+
$ sudo cp /etc/modsecurity/modsecurity.conf-recommended \
|
94
|
+
/etc/modsecurity/modsecurity.conf
|
95
|
+
$ sudo systemctl restart apache2
|
96
|
+
```
|
97
|
+
* DetectionOnlyで有効になる
|
98
|
+
* /var/log/apache2/modsec_audit.log にログ
|
99
|
+
|
100
|
+
# ModSecurity For Nginx
|
101
|
+
|
102
|
+
* モジュールをビルドする
|
103
|
+
* ビルドしたモジュールを配置する
|
104
|
+
* Nginxの設定ファイルを書く
|
105
|
+
|
106
|
+
# モジュールをビルドする準備(unstable)
|
107
|
+
|
108
|
+
```sh
|
109
|
+
$ sudo apt build-dep nginx
|
110
|
+
$ apt source nginx
|
111
|
+
$ git clone https://github.com/SpiderLabs/ModSecurity-nginx.git
|
112
|
+
$ vi nginx-1.18.0/debian/rules
|
113
|
+
```
|
114
|
+
|
115
|
+
* xxx_configure_flagsにオプション追加する
|
116
|
+
* `--add-dynamic-module=$(CURDIR)/../ModSecurity-nginx`
|
117
|
+
|
118
|
+
# モジュールをビルド
|
119
|
+
|
120
|
+
```sh
|
121
|
+
$ cd nginx-1.18.0
|
122
|
+
$ debuild -us -uc
|
123
|
+
$ find nginx-1.18.0 -name '*security*.so'
|
124
|
+
nginx-1.18.0/debian/build-xxx/objs/ngx_http_modsecurity_module.so
|
125
|
+
|
126
|
+
```
|
127
|
+
|
128
|
+
* xxxはcoreやlight、extrasのパッケージに対応
|
129
|
+
* nginx-core
|
130
|
+
* nginx-light
|
131
|
+
* nginx-extras
|
132
|
+
|
133
|
+
# モジュールをコピー
|
134
|
+
|
135
|
+
* ngx_http_modsecurity_module.so
|
136
|
+
* コピー先は/usr/lib/nginx/modules
|
137
|
+
|
138
|
+
# Nginxで有効にするには(nginx.conf)
|
139
|
+
|
140
|
+
```sh
|
141
|
+
load_module "modules/ngx_http_modsecurity_module.so";
|
142
|
+
|
143
|
+
modsecurity on;
|
144
|
+
modsecurity_rules_file /etc/nginx/modsecurity.conf;
|
145
|
+
```
|
146
|
+
|
147
|
+
* モジュールを読み込む
|
148
|
+
* ModSecurityを有効にする
|
149
|
+
* 3.x向けの記述方法
|
150
|
+
* ModSecurityEnabled onは2.x向けの記述
|
151
|
+
|
152
|
+
# Firewallのルールを指定する
|
153
|
+
|
154
|
+
* ModSecurityはFirewallの枠組み
|
155
|
+
* ルールは追加で指定する必要がある
|
156
|
+
* ModSecurity Core Rule Set
|
157
|
+
|
158
|
+
# modsecurity-crs
|
159
|
+
|
160
|
+
* OWASP ModSecurity Core Rule Set
|
161
|
+
* <https://github.com/coreruleset/coreruleset>
|
162
|
+
* コミュニティベースでメンテナンス(になった)
|
163
|
+
* ApacheとNginxとで共通で使えることになっている
|
164
|
+
* /usr/share/modsecurity-crs/rules/*.conf
|
165
|
+
|
166
|
+
# 設定の注意 for Nginx
|
167
|
+
|
168
|
+
* /etc/modsecurity/modsecurity.conf-recommended
|
169
|
+
* libapache2-mod-security2向け
|
170
|
+
* SecRequestBodyInMemoryLimit は3.xでは使えないやつ
|
171
|
+
* ログを別に出力する設定をおすすめ
|
172
|
+
* SecAuditLog /var/log/nginx/modsec_audit.log
|
173
|
+
|
174
|
+
# ブロックさせるサンプル
|
175
|
+
|
176
|
+
```sh
|
177
|
+
SecRuleEngine On
|
178
|
+
Include owasp-modsecurity-crs/crs-setup.conf
|
179
|
+
Include owasp-modsecurity-crs/rules/REQUEST-901-INITIALIZATION.conf
|
180
|
+
Include owasp-modsecurity-crs/rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf
|
181
|
+
Include owasp-modsecurity-crs/rules/REQUEST-949-BLOCKING-EVALUATION.conf
|
182
|
+
```
|
183
|
+
|
184
|
+
* /etc/nginx/modsecurity.conf(パスは任意)に記述する
|
185
|
+
* curl http://localhost/?union+select が403になる
|
186
|
+
|
187
|
+
# まるっと適用するなら
|
188
|
+
|
189
|
+
```sh
|
190
|
+
SecRuleEngine On
|
191
|
+
Include /etc/modsecurity/crs/crs-setup.conf
|
192
|
+
Include /etc/modsecurity/crs/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf
|
193
|
+
Include /usr/share/modsecurity-crs/rules/*.conf
|
194
|
+
Include /etc/modsecurity/crs/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf
|
195
|
+
```
|
196
|
+
|
197
|
+
* /etc/nginx/modsecurity.conf(パスは任意)に記述する
|
198
|
+
|
199
|
+
# 有効・無効の切り替え
|
200
|
+
|
201
|
+
* SecRuleEngine
|
202
|
+
* On: ModSecurityを有効にする
|
203
|
+
* Off: ModSecurityを無効にする
|
204
|
+
* DetectionOnly: 検知のみ行う
|
205
|
+
|
206
|
+
# 既定の挙動を設定
|
207
|
+
|
208
|
+
```sh
|
209
|
+
#SecAction \
|
210
|
+
# "id:900000,\
|
211
|
+
# phase:1,\
|
212
|
+
# nolog,\
|
213
|
+
# pass,\
|
214
|
+
# t:none,\
|
215
|
+
# setvar:tx.paranoia_level=1"
|
216
|
+
```
|
217
|
+
|
218
|
+
* crs-setup.conf
|
219
|
+
* SecActionで挙動に影響する変数を設定
|
220
|
+
|
221
|
+
# リクエストに関する設定
|
222
|
+
|
223
|
+
* REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf
|
224
|
+
* 既定では全部コメントアウト
|
225
|
+
* preフィルタ的感じでつかう
|
226
|
+
* ctl:ruleEngine
|
227
|
+
* ctl:ruleRemoveByXXX
|
228
|
+
* ctl:ruleRemoveTargetByXXX
|
229
|
+
|
230
|
+
# レスポンスに関する設定
|
231
|
+
|
232
|
+
* RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf
|
233
|
+
* 既定では全部コメントアウト
|
234
|
+
* postフィルタ的感じでつかう
|
235
|
+
* SecRuleRemoveByXXX
|
236
|
+
* SecRuleUpdateActionByXXX
|
237
|
+
* SecRuleUpdateTargetByXXX
|
238
|
+
|
239
|
+
# どんなルールセットがあるか?
|
240
|
+
|
241
|
+
* REQUEST-903.*
|
242
|
+
* Drupal
|
243
|
+
* Wordpress
|
244
|
+
* NextCloud
|
245
|
+
* DokuWiki
|
246
|
+
* CPanel
|
247
|
+
* Xenford
|
248
|
+
|
249
|
+
# ルールが読み込めているか?
|
250
|
+
|
251
|
+
* /var/log/nginx/error.log参照
|
252
|
+
* ルールをリモートから取得もできる
|
253
|
+
|
254
|
+
```sh
|
255
|
+
[notice] 16026#16026: ModSecurity-nginx v1.0.1 \
|
256
|
+
(rules loaded inline/local/remote: 0/911/0)
|
257
|
+
```
|
258
|
+
|
259
|
+
# ルールがどのように適用されたか?
|
260
|
+
|
261
|
+
* /var/log/nginx/modsec_audit.log を参照
|
262
|
+
* Hセクションをみるべし
|
263
|
+
|
264
|
+
```sh
|
265
|
+
--622ca252-H--
|
266
|
+
Message: Access denied with code 403 (phase 1). \
|
267
|
+
Pattern match "/phpmyadmin" at REQUEST_FILENAME. \
|
268
|
+
[file "/etc/httpd/conf.d/mod_security.conf"] \
|
269
|
+
[line "94"] \
|
270
|
+
[id "10000"] \
|
271
|
+
[msg "Blocking access to /phpmyadmin/index.php."] \
|
272
|
+
[tag "Blacklist Rules"]
|
273
|
+
```
|
274
|
+
|
275
|
+
# ひっかかったのを検出するには
|
276
|
+
|
277
|
+
<https://github.com/molu8bits/modsecurity-parser>
|
278
|
+
|
279
|
+
* ModSecurity 2.xと3.xのログに対応している
|
280
|
+
* png,json,xlsxでレポートを生成
|
281
|
+
|
282
|
+
```sh
|
283
|
+
$ python modsecurity-parser.py --version3 \
|
284
|
+
-f modsec_audit.log
|
285
|
+
```
|
286
|
+
|
287
|
+
# ここまで話をしたけれど
|
288
|
+
|
289
|
+
* 本物のウェブアクセスログを使用した、機械学習による異常検知(全データ/ソースコード公開)
|
290
|
+
* <https://www.scutum.jp/information/waf_tech_blog/2021/01/waf-blog-077.html>
|
291
|
+
* Javaのサンプルあり(バッチ処理)
|
292
|
+
|
293
|
+
# ざっくりいうと
|
294
|
+
|
295
|
+
* アクセスログを1行ごとに特徴ベクトルにする
|
296
|
+
* クエリーの特定の記号の出現回数とか
|
297
|
+
* Isolation Forestでモデルを構築する
|
298
|
+
* モデルを使って評価したスコアの外れ値をはじく
|
299
|
+
|
300
|
+
# ModSecurity + Isolation Forestで遊ぶには(Ruby編)
|
301
|
+
|
302
|
+
* <https://github.com/david-cortes/isotree>
|
303
|
+
* Isolation Forestを実装したライブラリー
|
304
|
+
* <https://github.com/ankane/isotree> (Ruby)
|
305
|
+
* 最近リクエストしてモデルのエクスポートに対応してもらった
|
306
|
+
|
307
|
+
# ModSecurity + Isolation Forestで遊ぶには
|
308
|
+
|
309
|
+
* <https://github.com/matsumotory/ngx_mruby>
|
310
|
+
* ngx_mrubyからリクエストを渡して評価
|
311
|
+
|
312
|
+
```sh
|
313
|
+
location / {
|
314
|
+
mruby_set_code $backend '
|
315
|
+
r = Nginx::Request.new
|
316
|
+
...ここでIsolationForestのモデルでr.uriのスコアを評価
|
317
|
+
return score > 0.9 ? "" : "http://127.0.0.1:3000/"
|
318
|
+
';
|
319
|
+
if ($backend = "") {
|
320
|
+
return 403;
|
321
|
+
}
|
322
|
+
proxy_pass $backend;
|
323
|
+
}
|
324
|
+
```
|
325
|
+
|
326
|
+
# まとめ
|
327
|
+
|
328
|
+
* 自由なWAFはいくつかある
|
329
|
+
* DebianでModSecurity-nginxを使うには自分でビルドする必要がある
|
330
|
+
* とっかかりにはmodsecurity-crsのルールセットを使うとよい
|
331
|
+
* まずは検知モードで動かしてみるのがおすすめ
|
332
|
+
* さらなる強化は別の手法の併用を考えるとよいかも
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rabbit-slide-kenhys-tokyodebian-modsecurity-20210220
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2021.02.20.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kentaro Hayashi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-02-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rabbit
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.2
|
27
|
+
description: ''
|
28
|
+
email:
|
29
|
+
- kenhys@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".rabbit"
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- config.yaml
|
38
|
+
- images/profile.png
|
39
|
+
- pdf/tokyodebian-modsecurity-20210220-tokyodebian-modsecurity.pdf
|
40
|
+
- theme.rb
|
41
|
+
- tokyodebian-modsecurity.md
|
42
|
+
homepage: https://slide.rabbit-shocker.org/authors/kenhys/tokyodebian-modsecurity-20210220/
|
43
|
+
licenses:
|
44
|
+
- CC-BY-SA-4.0
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubygems_version: 3.2.3
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Tokyo Debian ModSecurity 2021
|
65
|
+
test_files: []
|