rabbit-slide-kenhys-tokyodebian-modsecurity-20200220 2021.02.20.1 → 2021.02.20.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99637b5bf5d6d483261383aa71c042ba9ff28dcbc2207863f9c4b426fdc4f1b4
4
- data.tar.gz: a67ff2c672a11beadbe3934dc915f6fcba7e366d23b09a9c8b2d13f0b157dd20
3
+ metadata.gz: e48164abf31aa0fad1a2e77645fb5f4b4164ac78bcbf94337b9acd5c471e64e0
4
+ data.tar.gz: 401992fbd99b2bc1f5177bd09b3a4a065a07575fe210ae0e8d48f9968f8879a1
5
5
  SHA512:
6
- metadata.gz: 0fd156f9de544bc11851884095b7441485772303fea312744f80de0dac3cec227d7e91ceafe23a0d3317f21629c6453cf9112df1611acfb42a116e57fcf614f1
7
- data.tar.gz: 98cf16200b1b9a6c53474ac873ca74b303bfbb112b8c4762f48696626edab884cf32982fdb5f1aa55125fc21c9da0e60f1e96a110488128f37bb968ff294aae6
6
+ metadata.gz: 542b96ca8e92b2694d6ad4228d5900c05bea2c9c54faf05838fbfcca51f78916e0325058de72776be5bf603782ab6296656c9b1a0b520ea48264d197fbceb57a
7
+ data.tar.gz: 925c88f87dbbe7fa5b66d092125ea898fab1532d747753ba93482f9f39921bae07c15e079e2fe74fce0fb76b98fc42ef8fcd5e248548a0602ebd10669f6dfd4e
data/config.yaml CHANGED
@@ -8,7 +8,7 @@ presentation_date: 2021-02-20
8
8
  presentation_start_time:
9
9
  presentation_end_time:
10
10
  slideshare_id:
11
- version: 2021.02.20.1
11
+ version: 2021.02.20.2
12
12
  licenses:
13
13
  - CC-BY-SA-4.0
14
14
  slideshare_id: kenhys
@@ -1,7 +1,7 @@
1
1
  # DebianでWAF
2
2
 
3
3
  subtitle
4
- : ModSecurity-nginx 3.0.4による\\nWeb Application Firewall
4
+ : ModSecurity-nginx 1.0.1による\\nWeb Application Firewall
5
5
 
6
6
  author
7
7
  : Kentaro Hayashi
@@ -21,7 +21,7 @@ theme
21
21
  # スライドは公開済みです
22
22
 
23
23
  * この資料はRabbit Slide Showで公開済み
24
- * DebianでWAF - ModSecurity-nginx 3.0.4による\\nWeb Application Firewall
24
+ * DebianでWAF - ModSecurity-nginx 1.0.1による\\nWeb Application Firewall
25
25
  * <https://slide.rabbit-shocker.org/authors/kenhys/tokyodebian-modsecurity-20210220/>
26
26
 
27
27
 
@@ -41,6 +41,8 @@ theme
41
41
  * 自由なWAF
42
42
  * ModSecurityを試すには
43
43
 
44
+ * **注:誤りについては指摘してもらえると助かります**
45
+
44
46
  # WAFとは
45
47
 
46
48
  * Web Application Firewall
@@ -63,12 +65,12 @@ theme
63
65
 
64
66
  # 自由なWAF
65
67
 
66
- * Shadow Daemon
67
- * <https://shadowd.zecure.org/>
68
+ * Shadow Daemon - GPL-2.0 or later
69
+ * <https://shadowd.zecure.org/>
68
70
  * 言語ごとのconnectorをインストールする
69
- * NAXSI(Nginx)
71
+ * NAXSI(Nginx) - GPL-3.0
70
72
  * <https://github.com/nbs-system/naxsi>
71
- * **ModSecurity(Apache/Nginx)**
73
+ * **ModSecurity(Apache/Nginx)** Apache-2.0
72
74
  * <https://modsecurity.org/>
73
75
 
74
76
  # ModSecurity in Debian
@@ -80,19 +82,19 @@ theme
80
82
  * For Nginx
81
83
  * パッケージはない
82
84
  * <https://github.com/SpiderLabs/ModSecurity-nginx>
83
- * 最新版は3.0.4
85
+ * 最新版は1.0.1 (ModSecurity 3.0.3以降)
84
86
 
85
87
  # ModSecurity For Apache
86
88
 
87
89
  ```sh
88
- sudo apt install apache2 modsecurity-crs \
90
+ $ sudo apt install apache2 modsecurity-crs \
89
91
  libapache2-mod-security2
90
- sudo a2enmod security2
91
- sudo cp /etc/modsecurity/modsecurity.conf-recommended \
92
+ $ sudo a2enmod security2
93
+ $ sudo cp /etc/modsecurity/modsecurity.conf-recommended \
92
94
  /etc/modsecurity/modsecurity.conf
93
- sudo systemctl restart apache2
95
+ $ sudo systemctl restart apache2
94
96
  ```
95
- * DetectOnlyで有効になる
97
+ * DetectionOnlyで有効になる
96
98
  * /var/log/apache2/modsec_audit.log にログ
97
99
 
98
100
  # ModSecurity For Nginx
@@ -133,7 +135,7 @@ nginx-1.18.0/debian/build-xxx/objs/ngx_http_modsecurity_module.so
133
135
  * ngx_http_modsecurity_module.so
134
136
  * コピー先は/usr/lib/nginx/modules
135
137
 
136
- # Nginxで有効にするには
138
+ # Nginxで有効にするには(nginx.conf)
137
139
 
138
140
  ```sh
139
141
  load_module "modules/ngx_http_modsecurity_module.so";
@@ -163,11 +165,12 @@ modsecurity_rules_file /etc/nginx/modsecurity.conf;
163
165
 
164
166
  # 設定の注意 for Nginx
165
167
 
166
- * /usr/share/modsecurity-crs/owasp-crs.load
167
168
  * /etc/modsecurity/modsecurity.conf-recommended
168
169
  * libapache2-mod-security2向け
169
170
  * SecRequestBodyInMemoryLimit は3.xでは使えないやつ
170
-
171
+ * ログを別に出力する設定をおすすめ
172
+ * SecAuditLog /var/log/nginx/modsec_audit.log
173
+ * 既定だとエラーログに吐かれる
171
174
 
172
175
  # ブロックさせるサンプル
173
176
 
@@ -179,6 +182,7 @@ Include owasp-modsecurity-crs/rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf
179
182
  Include owasp-modsecurity-crs/rules/REQUEST-949-BLOCKING-EVALUATION.conf
180
183
  ```
181
184
 
185
+ * /etc/nginx/modsecurity.conf(パスは任意)に記述する
182
186
  * curl http://localhost/?union+select が403になる
183
187
 
184
188
  # まるっと適用するなら
@@ -243,7 +247,7 @@ Include /etc/modsecurity/crs/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf
243
247
  * CPanel
244
248
  * Xenford
245
249
 
246
- # ルールが適用できているか?
250
+ # ルールが読み込めているか?
247
251
 
248
252
  * /var/log/nginx/error.log参照
249
253
  * ルールをリモートから取得もできる
@@ -277,13 +281,53 @@ Pattern match "/phpmyadmin" at REQUEST_FILENAME. \
277
281
  * png,json,xlsxでレポートを生成
278
282
 
279
283
  ```sh
280
- python modsecurity-parser.py --version3 \
284
+ $ python modsecurity-parser.py --version3 \
281
285
  -f modsec_audit.log
282
286
  ```
283
287
 
288
+ # ここまで話をしたけれど
289
+
290
+ * 本物のウェブアクセスログを使用した、機械学習による異常検知(全データ/ソースコード公開)
291
+ * <https://www.scutum.jp/information/waf_tech_blog/2021/01/waf-blog-077.html>
292
+ * Javaのサンプルあり(バッチ処理)
293
+
294
+ # ざっくりいうと
295
+
296
+ * アクセスログを1行ごとに特徴ベクトルにする
297
+ * クエリーの特定の記号の出現回数とか
298
+ * Isolation Forestでモデルを構築する
299
+ * モデルを使って評価したスコアの外れ値をはじく
300
+
301
+ # ModSecurity + Isolation Forestで遊ぶには(Ruby編)
302
+
303
+ * <https://github.com/david-cortes/isotree>
304
+ * Isolation Forestを実装したライブラリー
305
+ * <https://github.com/ankane/isotree> (Ruby)
306
+ * 最近リクエストしてモデルのエクスポートに対応してもらった
307
+
308
+ # ModSecurity + Isolation Forestで遊ぶには
309
+
310
+ * <https://github.com/matsumotory/ngx_mruby>
311
+ * ngx_mrubyからリクエストを渡して評価
312
+
313
+ ```sh
314
+ location / {
315
+ mruby_set_code $backend '
316
+ r = Nginx::Request.new
317
+ ...ここでIsolationForestのモデルでr.uriのスコアを評価
318
+ return score > 0.9 ? "" : "http://127.0.0.1:3000/"
319
+ ';
320
+ if ($backend = "") {
321
+ return 403;
322
+ }
323
+ proxy_pass $backend;
324
+ }
325
+ ```
326
+
284
327
  # まとめ
285
328
 
286
329
  * 自由なWAFはいくつかある
287
330
  * DebianでModSecurity-nginxを使うには自分でビルドする必要がある
288
331
  * とっかかりにはmodsecurity-crsのルールセットを使うとよい
289
332
  * まずは検知モードで動かしてみるのがおすすめ
333
+ * さらなる強化は別の手法の併用を考えるとよいかも
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabbit-slide-kenhys-tokyodebian-modsecurity-20200220
3
3
  version: !ruby/object:Gem::Version
4
- version: 2021.02.20.1
4
+ version: 2021.02.20.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kentaro Hayashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-28 00:00:00.000000000 Z
11
+ date: 2021-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rabbit