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

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 99637b5bf5d6d483261383aa71c042ba9ff28dcbc2207863f9c4b426fdc4f1b4
4
+ data.tar.gz: a67ff2c672a11beadbe3934dc915f6fcba7e366d23b09a9c8b2d13f0b157dd20
5
+ SHA512:
6
+ metadata.gz: 0fd156f9de544bc11851884095b7441485772303fea312744f80de0dac3cec227d7e91ceafe23a0d3317f21629c6453cf9112df1611acfb42a116e57fcf614f1
7
+ data.tar.gz: 98cf16200b1b9a6c53474ac873ca74b303bfbb112b8c4762f48696626edab884cf32982fdb5f1aa55125fc21c9da0e60f1e96a110488128f37bb968ff294aae6
data/.rabbit ADDED
@@ -0,0 +1 @@
1
+ --size=1024,768 tokyodebian-modsecurity.md
@@ -0,0 +1,14 @@
1
+ # Tokyo Debian ModSecurity 2021
2
+
3
+ ## How to show
4
+
5
+ % rabbit
6
+
7
+ ## How to install
8
+
9
+ % gem install rabbit-slide-kenhys-tokyodebian-modsecurity-2021
10
+
11
+ ## How to create PDF
12
+
13
+ % rake pdf
14
+
@@ -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
@@ -0,0 +1,24 @@
1
+ ---
2
+ id: tokyodebian-modsecurity-20200220
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.1
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:
Binary file
@@ -0,0 +1,5 @@
1
+ @default_font = "Ubuntu"
2
+ @monospace_font = "Ubuntu"
3
+ include_theme("debian")
4
+ @slide_show_span = 1300
5
+ @slide_show_loop = true
@@ -0,0 +1,289 @@
1
+ # DebianでWAF
2
+
3
+ subtitle
4
+ : ModSecurity-nginx 3.0.4による\\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 3.0.4による\\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
+ # WAFとは
45
+
46
+ * Web Application Firewall
47
+ * Webサイトへの攻撃の影響を低減するためのもの
48
+ * 攻撃と判断した通信を遮断する
49
+
50
+ # WAFの提供形態
51
+
52
+ * アプライアンス型(専用機器設置)
53
+ * サービス型(外部提供のWAFサービスを利用)
54
+ * **ソフトウェア型** (今回はコレ!)
55
+
56
+ # WAFへの理解を深めるには
57
+
58
+ * 「Web Application Firewallの導入に向けた検討項目」
59
+ * <https://www.ipa.go.jp/files/000072484.pdf>
60
+
61
+ * 「Web Application Firewall 読本」
62
+ * <https://www.ipa.go.jp/files/000017312.pdf>
63
+
64
+ # 自由なWAF
65
+
66
+ * Shadow Daemon
67
+ * <https://shadowd.zecure.org/>
68
+ * 言語ごとのconnectorをインストールする
69
+ * NAXSI(Nginx)
70
+ * <https://github.com/nbs-system/naxsi>
71
+ * **ModSecurity(Apache/Nginx)**
72
+ * <https://modsecurity.org/>
73
+
74
+ # ModSecurity in Debian
75
+
76
+ * For Apache
77
+ * libapache2-mod-security2
78
+ * ModSecurity 2.x
79
+
80
+ * For Nginx
81
+ * パッケージはない
82
+ * <https://github.com/SpiderLabs/ModSecurity-nginx>
83
+ * 最新版は3.0.4
84
+
85
+ # ModSecurity For Apache
86
+
87
+ ```sh
88
+ sudo apt install apache2 modsecurity-crs \
89
+ libapache2-mod-security2
90
+ sudo a2enmod security2
91
+ sudo cp /etc/modsecurity/modsecurity.conf-recommended \
92
+ /etc/modsecurity/modsecurity.conf
93
+ sudo systemctl restart apache2
94
+ ```
95
+ * DetectOnlyで有効になる
96
+ * /var/log/apache2/modsec_audit.log にログ
97
+
98
+ # ModSecurity For Nginx
99
+
100
+ * モジュールをビルドする
101
+ * ビルドしたモジュールを配置する
102
+ * Nginxの設定ファイルを書く
103
+
104
+ # モジュールをビルドする準備(unstable)
105
+
106
+ ```sh
107
+ $ sudo apt build-dep nginx
108
+ $ apt source nginx
109
+ $ git clone https://github.com/SpiderLabs/ModSecurity-nginx.git
110
+ $ vi nginx-1.18.0/debian/rules
111
+ ```
112
+
113
+ * xxx_configure_flagsにオプション追加する
114
+ * `--add-dynamic-module=$(CURDIR)/../ModSecurity-nginx`
115
+
116
+ # モジュールをビルド
117
+
118
+ ```sh
119
+ $ cd nginx-1.18.0
120
+ $ debuild -us -uc
121
+ $ find nginx-1.18.0 -name '*security*.so'
122
+ nginx-1.18.0/debian/build-xxx/objs/ngx_http_modsecurity_module.so
123
+
124
+ ```
125
+
126
+ * xxxはcoreやlight、extrasのパッケージに対応
127
+ * nginx-core
128
+ * nginx-light
129
+ * nginx-extras
130
+
131
+ # モジュールをコピー
132
+
133
+ * ngx_http_modsecurity_module.so
134
+ * コピー先は/usr/lib/nginx/modules
135
+
136
+ # Nginxで有効にするには
137
+
138
+ ```sh
139
+ load_module "modules/ngx_http_modsecurity_module.so";
140
+
141
+ modsecurity on;
142
+ modsecurity_rules_file /etc/nginx/modsecurity.conf;
143
+ ```
144
+
145
+ * モジュールを読み込む
146
+ * ModSecurityを有効にする
147
+ * 3.x向けの記述方法
148
+ * ModSecurityEnabled onは2.x向けの記述
149
+
150
+ # Firewallのルールを指定する
151
+
152
+ * ModSecurityはFirewallの枠組み
153
+ * ルールは追加で指定する必要がある
154
+ * ModSecurity Core Rule Set
155
+
156
+ # modsecurity-crs
157
+
158
+ * OWASP ModSecurity Core Rule Set
159
+ * <https://github.com/coreruleset/coreruleset>
160
+ * コミュニティベースでメンテナンス(になった)
161
+ * ApacheとNginxとで共通で使えることになっている
162
+ * /usr/share/modsecurity-crs/rules/*.conf
163
+
164
+ # 設定の注意 for Nginx
165
+
166
+ * /usr/share/modsecurity-crs/owasp-crs.load
167
+ * /etc/modsecurity/modsecurity.conf-recommended
168
+ * libapache2-mod-security2向け
169
+ * SecRequestBodyInMemoryLimit は3.xでは使えないやつ
170
+
171
+
172
+ # ブロックさせるサンプル
173
+
174
+ ```sh
175
+ SecRuleEngine On
176
+ Include owasp-modsecurity-crs/crs-setup.conf
177
+ Include owasp-modsecurity-crs/rules/REQUEST-901-INITIALIZATION.conf
178
+ Include owasp-modsecurity-crs/rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf
179
+ Include owasp-modsecurity-crs/rules/REQUEST-949-BLOCKING-EVALUATION.conf
180
+ ```
181
+
182
+ * curl http://localhost/?union+select が403になる
183
+
184
+ # まるっと適用するなら
185
+
186
+ ```sh
187
+ SecRuleEngine On
188
+ Include /etc/modsecurity/crs/crs-setup.conf
189
+ Include /etc/modsecurity/crs/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf
190
+ Include /usr/share/modsecurity-crs/rules/*.conf
191
+ Include /etc/modsecurity/crs/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf
192
+ ```
193
+
194
+ * /etc/nginx/modsecurity.conf(パスは任意)に記述する
195
+
196
+ # 有効・無効の切り替え
197
+
198
+ * SecRuleEngine
199
+ * On: ModSecurityを有効にする
200
+ * Off: ModSecurityを無効にする
201
+ * DetectionOnly: 検知のみ行う
202
+
203
+ # 既定の挙動を設定
204
+
205
+ ```sh
206
+ #SecAction \
207
+ # "id:900000,\
208
+ # phase:1,\
209
+ # nolog,\
210
+ # pass,\
211
+ # t:none,\
212
+ # setvar:tx.paranoia_level=1"
213
+ ```
214
+
215
+ * crs-setup.conf
216
+ * SecActionで挙動に影響する変数を設定
217
+
218
+ # リクエストに関する設定
219
+
220
+ * REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf
221
+ * 既定では全部コメントアウト
222
+ * preフィルタ的感じでつかう
223
+ * ctl:ruleEngine
224
+ * ctl:ruleRemoveByXXX
225
+ * ctl:ruleRemoveTargetByXXX
226
+
227
+ # レスポンスに関する設定
228
+
229
+ * RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf
230
+ * 既定では全部コメントアウト
231
+ * postフィルタ的感じでつかう
232
+ * SecRuleRemoveByXXX
233
+ * SecRuleUpdateActionByXXX
234
+ * SecRuleUpdateTargetByXXX
235
+
236
+ # どんなルールセットがあるか?
237
+
238
+ * REQUEST-903.*
239
+ * Drupal
240
+ * Wordpress
241
+ * NextCloud
242
+ * DokuWiki
243
+ * CPanel
244
+ * Xenford
245
+
246
+ # ルールが適用できているか?
247
+
248
+ * /var/log/nginx/error.log参照
249
+ * ルールをリモートから取得もできる
250
+
251
+ ```sh
252
+ [notice] 16026#16026: ModSecurity-nginx v1.0.1 \
253
+ (rules loaded inline/local/remote: 0/911/0)
254
+ ```
255
+
256
+ # ルールがどのように適用されたか?
257
+
258
+ * /var/log/nginx/modsec_audit.log を参照
259
+ * Hセクションをみるべし
260
+
261
+ ```sh
262
+ --622ca252-H--
263
+ Message: Access denied with code 403 (phase 1). \
264
+ Pattern match "/phpmyadmin" at REQUEST_FILENAME. \
265
+ [file "/etc/httpd/conf.d/mod_security.conf"] \
266
+ [line "94"] \
267
+ [id "10000"] \
268
+ [msg "Blocking access to /phpmyadmin/index.php."] \
269
+ [tag "Blacklist Rules"]
270
+ ```
271
+
272
+ # ひっかかったのを検出するには
273
+
274
+ <https://github.com/molu8bits/modsecurity-parser>
275
+
276
+ * ModSecurity 2.xと3.xのログに対応している
277
+ * png,json,xlsxでレポートを生成
278
+
279
+ ```sh
280
+ python modsecurity-parser.py --version3 \
281
+ -f modsec_audit.log
282
+ ```
283
+
284
+ # まとめ
285
+
286
+ * 自由なWAFはいくつかある
287
+ * DebianでModSecurity-nginxを使うには自分でビルドする必要がある
288
+ * とっかかりにはmodsecurity-crsのルールセットを使うとよい
289
+ * まずは検知モードで動かしてみるのがおすすめ
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rabbit-slide-kenhys-tokyodebian-modsecurity-20200220
3
+ version: !ruby/object:Gem::Version
4
+ version: 2021.02.20.1
5
+ platform: ruby
6
+ authors:
7
+ - Kentaro Hayashi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-01-28 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-20200220-tokyodebian-modsecurity.pdf
40
+ - theme.rb
41
+ - tokyodebian-modsecurity.md
42
+ homepage: https://slide.rabbit-shocker.org/authors/kenhys/tokyodebian-modsecurity-20200220/
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: []