perlsec >
5.10.0
との差分
perlsec 5.10.0 と 5.36.0 の差分
1 | 1 | |
2 | =encoding | |
2 | =encoding utf8 | |
3 | 3 | |
4 | 4 | =head1 NAME |
5 | 5 | |
6 | 6 | =begin original |
7 | 7 | |
8 | 8 | perlsec - Perl security |
9 | 9 | |
10 | 10 | =end original |
11 | 11 | |
12 | 12 | perlsec - Perl のセキュリティ |
13 | 13 | |
14 | 14 | =head1 DESCRIPTION |
15 | 15 | |
16 | 16 | =begin original |
17 | 17 | |
18 | 18 | Perl is designed to make it easy to program securely even when running |
19 | 19 | with extra privileges, like setuid or setgid programs. Unlike most |
20 | 20 | command line shells, which are based on multiple substitution passes on |
21 | 21 | each line of the script, Perl uses a more conventional evaluation scheme |
22 | 22 | with fewer hidden snags. Additionally, because the language has more |
23 | 23 | builtin functionality, it can rely less upon external (and possibly |
24 | 24 | untrustworthy) programs to accomplish its purposes. |
25 | 25 | |
26 | 26 | =end original |
27 | 27 | |
28 | ||
29 | Perl は、プログラムが setuid や setgid されるような特別な権限を付加されて | |
29 | 30 | 実行されたときでもセキュリティ保持が容易になるように設計されています。 |
30 | 31 | スクリプトの一行ごとの多重置換を行うことに基づいているような大部分の |
31 | 32 | コマンドラインシェルとは違って、Perl は隠れた障害が少ないような、 |
32 | 33 | より便利な評価手法を用いています。 |
33 | 34 | それに加えて Perl はより多くの組み込み関数を持っているので、 |
34 | 35 | ある目的を達成するために(信頼できないかもしれないような) |
35 | 36 | 外部プログラムを使うことが少なくてすむのです。 |
36 | 37 | |
38 | =head1 SECURITY VULNERABILITY CONTACT INFORMATION | |
39 | ||
40 | (セキュリティ脆弱性連絡窓口) | |
41 | ||
37 | 42 | =begin original |
38 | 43 | |
44 | If you believe you have found a security vulnerability in the Perl | |
45 | interpreter or modules maintained in the core Perl codebase, | |
46 | email the details to | |
47 | L<perl-security@perl.org|mailto:perl-security@perl.org>. | |
48 | This address is a closed membership mailing list monitored by the Perl | |
49 | security team. | |
50 | ||
51 | =end original | |
52 | ||
53 | Perl インタプリタや、コア Perl コードベースで管理しているモジュールの | |
54 | セキュリティ脆弱性を発見したと確信したときには、詳細を | |
55 | L<perl-security@perl.org|mailto:perl-security@perl.org> に | |
56 | メールしてください。 | |
57 | このアドレスは Perl セキュリティチームによって監視されている、 | |
58 | 閉じられたメンバーのメーリングリストです。 | |
59 | ||
60 | =begin original | |
61 | ||
62 | See L<perlsecpolicy> for additional information. | |
63 | ||
64 | =end original | |
65 | ||
66 | 追加の情報については L<perlsecpolicy> を参照してください。 | |
67 | ||
68 | =head1 SECURITY MECHANISMS AND CONCERNS | |
69 | ||
70 | =head2 Taint mode | |
71 | ||
72 | (汚染モード) | |
73 | ||
74 | =begin original | |
75 | ||
76 | By default, | |
39 | 77 | Perl automatically enables a set of special security checks, called I<taint |
40 | 78 | mode>, when it detects its program running with differing real and effective |
41 | 79 | user or group IDs. The setuid bit in Unix permissions is mode 04000, the |
42 | 80 | setgid bit mode 02000; either or both may be set. You can also enable taint |
43 | mode explicitly by using the B<-T> command line flag. This flag is | |
81 | mode explicitly by using the B<-T> command line flag. This flag is | |
44 | 82 | I<strongly> suggested for server programs and any program run on behalf of |
45 | someone else, such as a CGI script. Once taint mode is on, it's on for | |
83 | someone else, such as a CGI script. Once taint mode is on, it's on for | |
46 | 84 | the remainder of your script. |
47 | 85 | |
48 | 86 | =end original |
49 | 87 | |
50 | Perl は | |
88 | Perl はデフォルトでは、 | |
89 | そのプログラムが異なる実ユーザー ID、実効ユーザー ID、実グループ ID、 | |
51 | 90 | 実効グループ ID を使って実行されることを検出したときに、 |
52 | 91 | 自動的に I<汚染モード> (taint mode) と呼ばれる特別なセキュリティチェックの |
53 | 92 | セットを有効にします。 |
54 | 93 | UNIX パーミッションにおける setuid ビットはモード 04000 で、 |
55 | 94 | setgid ビットはモード 02000 です。 |
56 | 95 | これらは重複してセットすることもできます。 |
57 | 96 | 汚染モードは、コマンドラインフラグ B<-T> を使って陽に有効にすることもできます。 |
58 | 97 | このフラグはサーバープログラムであるとか、 |
59 | 98 | CGI スクリプトのような、他の誰かにすりかわって実行されるプログラムに |
60 | 99 | 使うことを B<強く> 勧めます。 |
61 | 100 | |
62 | 101 | =begin original |
63 | 102 | |
64 | 103 | While in this mode, Perl takes special precautions called I<taint |
65 | 104 | checks> to prevent both obvious and subtle traps. Some of these checks |
66 | 105 | are reasonably simple, such as verifying that path directories aren't |
67 | 106 | writable by others; careful programmers have always used checks like |
68 | 107 | these. Other checks, however, are best supported by the language itself, |
69 | 108 | and it is these checks especially that contribute to making a set-id Perl |
70 | 109 | program more secure than the corresponding C program. |
71 | 110 | |
72 | 111 | =end original |
73 | 112 | |
74 | 113 | このモードで動作しているとき、Perl は明白な罠と隠れた罠の両方に対処するために |
75 | 114 | I<汚染検査> (taint check) と呼ばれる特別な警戒を行います。 |
76 | これらのチェックの幾つかは、単純です | |
115 | これらのチェックの幾つかは、単純です; path ディレクトリが他から書き込み | |
77 | ||
116 | 可能でないことを検査するといったことがそうです; 注意深いプログラマーは常に | |
78 | ||
117 | これらのことはチェックしています。 | |
79 | このほかのチェックはしかしながら、言語自身によって最も良くサポートされます | |
118 | このほかのチェックはしかしながら、言語自身によって最も良くサポートされます; | |
80 | そして、これらのチェックは特に set-id された Perl プログラムを | |
119 | そして、これらのチェックは特に set-id された Perl プログラムを対応する | |
81 | ||
120 | C プログラムよりも安全にするのに貢献するのです。 | |
82 | 121 | |
83 | 122 | =begin original |
84 | 123 | |
85 | 124 | You may not use data derived from outside your program to affect |
86 | 125 | something else outside your program--at least, not by accident. All |
87 | 126 | command line arguments, environment variables, locale information (see |
88 | 127 | L<perllocale>), results of certain system calls (C<readdir()>, |
89 | 128 | C<readlink()>, the variable of C<shmread()>, the messages returned by |
90 | 129 | C<msgrcv()>, the password, gcos and shell fields returned by the |
91 | 130 | C<getpwxxx()> calls), and all file input are marked as "tainted". |
92 | 131 | Tainted data may not be used directly or indirectly in any command |
93 | 132 | that invokes a sub-shell, nor in any command that modifies files, |
94 | 133 | directories, or processes, B<with the following exceptions>: |
95 | 134 | |
96 | 135 | =end original |
97 | 136 | |
98 | 137 | 自分のプログラムの外側から来たデータをプログラムの外の何かに影響を |
99 | 138 | 及ぼすために使うことは、少なくともアクシデントででもなければ、できません。 |
100 | 139 | すべてのコマンドライン引数、環境変数、ロケール情報(L<perllocale> を参照)、 |
101 | 140 | 幾つかのシステムコールの結果(C<readdir()>, C<readlink()>, C<shmread()> の変数、 |
102 | 141 | C<msgrcv()> が返したメッセージ、パスワード、C<getpwxxx()> 呼び出しが返した |
103 | 142 | gecos フィールドとシェルフィールド)、すべてのファイル入力といったものは |
104 | 143 | “汚染された”(tainted) と目印が付けられます。 |
105 | 144 | 汚染されたデータは直接、間接を問わずサブシェルを起動するコマンドに使うことも、 |
106 | 145 | ファイルやディレクトリ、プロセスに変更を加えるようなコマンドに |
107 | 使うこともできません。 | |
146 | 使うこともできません; 但し B<以下の例外> があります。 | |
108 | 但し B<以下の例外> があります。 | |
109 | 147 | |
148 | =begin original | |
149 | ||
150 | Support for taint checks adds an overhead to all Perl programs, | |
151 | whether or not you're using the taint features. | |
152 | Perl 5.18 introduced C preprocessor symbols that can | |
153 | be used to disable the taint features. | |
154 | ||
155 | =end original | |
156 | ||
157 | 汚染チェック対応は、汚染チェック機能をを使うかどうかに関わらず、 | |
158 | 全ての Perl プログラムにオーバーヘッドを追加します。 | |
159 | Perl 5.18 では、汚染チェック機能を無効にするために使える | |
160 | C プリプロセッサシンボルが導入されました。 | |
161 | ||
110 | 162 | =over 4 |
111 | 163 | |
112 | 164 | =item * |
113 | 165 | |
114 | 166 | =begin original |
115 | 167 | |
116 | 168 | Arguments to C<print> and C<syswrite> are B<not> checked for taintedness. |
117 | 169 | |
118 | 170 | =end original |
119 | 171 | |
120 | 172 | C<print> と C<syswrite> の引数に対する汚染検査は B<行われません>。 |
121 | 173 | |
122 | 174 | =item * |
123 | 175 | |
124 | 176 | =begin original |
125 | 177 | |
126 | 178 | Symbolic methods |
127 | 179 | |
128 | 180 | =end original |
129 | 181 | |
130 | 182 | シンボリックメソッド |
131 | 183 | |
132 | 184 | $obj->$method(@args); |
133 | 185 | |
134 | 186 | =begin original |
135 | 187 | |
136 | 188 | and symbolic sub references |
137 | 189 | |
138 | 190 | =end original |
139 | 191 | |
140 | 192 | とシンボリックサブルーチンリファレンス |
141 | 193 | |
142 | 194 | &{$foo}(@args); |
143 | 195 | $foo->(@args); |
144 | 196 | |
145 | 197 | =begin original |
146 | 198 | |
147 | 199 | are not checked for taintedness. This requires extra carefulness |
148 | 200 | unless you want external data to affect your control flow. Unless |
149 | 201 | you carefully limit what these symbolic values are, people are able |
150 | 202 | to call functions B<outside> your Perl code, such as POSIX::system, |
151 | 203 | in which case they are able to run arbitrary external code. |
152 | 204 | |
153 | 205 | =end original |
154 | 206 | |
155 | 207 | は汚染性がチェックされません。 |
156 | 208 | これは、あなたの制御フローが外部データに影響されたいと思わないなら、 |
157 | 209 | さらなる慎重さを要求します。 |
158 | 210 | これらのシンボリックな値が何かを注意深く制限しないと、POSIX::system のような |
159 | 211 | あなたの Perl コードの B<外側> の関数を呼び出すことを可能にし、この場合 |
160 | 212 | 任意の外部コードを実行できるようになります。 |
161 | 213 | |
162 | 214 | =item * |
163 | 215 | |
164 | 216 | =begin original |
165 | 217 | |
166 | 218 | Hash keys are B<never> tainted. |
167 | 219 | |
168 | 220 | =end original |
169 | 221 | |
170 | 222 | ハッシュのキーは B<決して> 汚染されません。 |
171 | 223 | |
172 | 224 | =back |
173 | 225 | |
174 | 226 | =begin original |
175 | 227 | |
176 | 228 | For efficiency reasons, Perl takes a conservative view of |
177 | 229 | whether data is tainted. If an expression contains tainted data, |
178 | 230 | any subexpression may be considered tainted, even if the value |
179 | 231 | of the subexpression is not itself affected by the tainted data. |
180 | 232 | |
181 | 233 | =end original |
182 | 234 | |
183 | 235 | 効率上の理由から、Perl はデータが汚染されているかどうかについて保守的な |
184 | 236 | 見方をします。 |
185 | 237 | 汚染されているデータが式に含まれている場合、たとえ副式の値自身は汚染された |
186 | 238 | データに影響を受けない場合でも、全ての副式も汚染されたものとして |
187 | 239 | 扱います。 |
188 | 240 | |
189 | 241 | =begin original |
190 | 242 | |
191 | 243 | Because taintedness is associated with each scalar value, some |
192 | 244 | elements of an array or hash can be tainted and others not. |
193 | 245 | The keys of a hash are B<never> tainted. |
194 | 246 | |
195 | 247 | =end original |
196 | 248 | |
197 | 249 | 汚染は各スカラ値に結び付けられるので、配列の幾つかの要素が汚染されていて、 |
198 | 250 | そのほかの要素はそうではないということもありえます。 |
199 | 251 | ハッシュのキーは B<決して> 汚染されません。 |
200 | 252 | |
201 | 253 | =begin original |
202 | 254 | |
203 | 255 | For example: |
204 | 256 | |
205 | 257 | =end original |
206 | 258 | |
207 | 259 | 例を示します: |
208 | 260 | |
209 | 261 | =begin original |
210 | 262 | |
211 | 263 | $arg = shift; # $arg is tainted |
212 | $hid = $arg | |
264 | $hid = $arg . 'bar'; # $hid is also tainted | |
213 | 265 | $line = <>; # Tainted |
214 | 266 | $line = <STDIN>; # Also tainted |
215 | 267 | open FOO, "/home/me/bar" or die $!; |
216 | 268 | $line = <FOO>; # Still tainted |
217 | 269 | $path = $ENV{'PATH'}; # Tainted, but see below |
218 | 270 | $data = 'abc'; # Not tainted |
219 | 271 | |
220 | 272 | =end original |
221 | 273 | |
222 | 274 | $arg = shift; # $arg は汚染された |
223 | $hid = $arg | |
275 | $hid = $arg . 'bar'; # $hid も汚染された | |
224 | 276 | $line = <>; # 汚染された |
225 | 277 | $line = <STDIN>; # これも汚染された |
226 | 278 | open FOO, "/home/me/bar" or die $!; |
227 | 279 | $line = <FOO>; # まだ汚染されている |
228 | 280 | $path = $ENV{'PATH'}; # 汚染されているが、下記を参照のこと |
229 | 281 | $data = 'abc'; # 汚染されていない |
230 | 282 | |
231 | 283 | =begin original |
232 | 284 | |
233 | 285 | system "echo $arg"; # Insecure |
234 | 286 | system "/bin/echo", $arg; # Considered insecure |
235 | 287 | # (Perl doesn't know about /bin/echo) |
236 | 288 | system "echo $hid"; # Insecure |
237 | 289 | system "echo $data"; # Insecure until PATH set |
238 | 290 | |
239 | 291 | =end original |
240 | 292 | |
241 | 293 | system "echo $arg"; # 安全ではない |
242 | 294 | system "/bin/echo", $arg; # 安全ではないと考えられる |
243 | 295 | # (Perl は /bin/echo について知らない) |
244 | 296 | system "echo $hid"; # 安全ではない |
245 | 297 | system "echo $data"; # PATHを設定するまでは安全ではない |
246 | 298 | |
247 | 299 | =begin original |
248 | 300 | |
249 | 301 | $path = $ENV{'PATH'}; # $path now tainted |
250 | 302 | |
251 | 303 | =end original |
252 | 304 | |
253 | 305 | $path = $ENV{'PATH'}; # $path が汚染された |
254 | 306 | |
255 | 307 | $ENV{'PATH'} = '/bin:/usr/bin'; |
256 | 308 | delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; |
257 | 309 | |
258 | 310 | =begin original |
259 | 311 | |
260 | 312 | $path = $ENV{'PATH'}; # $path now NOT tainted |
261 | 313 | system "echo $data"; # Is secure now! |
262 | 314 | |
263 | 315 | =end original |
264 | 316 | |
265 | 317 | $path = $ENV{'PATH'}; # $path は汚染されていない |
266 | 318 | system "echo $data"; # これで安全! |
267 | 319 | |
268 | 320 | =begin original |
269 | 321 | |
270 | 322 | open(FOO, "< $arg"); # OK - read-only file |
271 | 323 | open(FOO, "> $arg"); # Not OK - trying to write |
272 | 324 | |
273 | 325 | =end original |
274 | 326 | |
275 | 327 | open(FOO, "< $arg"); # OK - 読み込みのみのファイル |
276 | 328 | open(FOO, "> $arg"); # Not OK - 書き込みしようとしている |
277 | 329 | |
278 | 330 | open(FOO,"echo $arg|"); # Not OK |
279 | 331 | open(FOO,"-|") |
280 | 332 | or exec 'echo', $arg; # Also not OK |
281 | 333 | |
282 | 334 | =begin original |
283 | 335 | |
284 | 336 | $shout = `echo $arg`; # Insecure, $shout now tainted |
285 | 337 | |
286 | 338 | =end original |
287 | 339 | |
288 | $shout = `echo $arg`; # 安全でない | |
340 | $shout = `echo $arg`; # 安全でない; $shoutは汚染された | |
289 | 341 | |
290 | 342 | =begin original |
291 | 343 | |
292 | 344 | unlink $data, $arg; # Insecure |
293 | 345 | umask $arg; # Insecure |
294 | 346 | |
295 | 347 | =end original |
296 | 348 | |
297 | 349 | unlink $data, $arg; # 安全でない |
298 | 350 | umask $arg; # 安全でない |
299 | 351 | |
300 | 352 | =begin original |
301 | 353 | |
302 | 354 | exec "echo $arg"; # Insecure |
303 | 355 | exec "echo", $arg; # Insecure |
304 | 356 | exec "sh", '-c', $arg; # Very insecure! |
305 | 357 | |
306 | 358 | =end original |
307 | 359 | |
308 | 360 | exec "echo $arg"; # 安全でない |
309 | 361 | exec "echo", $arg; # 安全でない |
310 | 362 | exec "sh", '-c', $arg; # とても安全ではない! |
311 | 363 | |
312 | 364 | =begin original |
313 | 365 | |
314 | 366 | @files = <*.c>; # insecure (uses readdir() or similar) |
315 | 367 | @files = glob('*.c'); # insecure (uses readdir() or similar) |
316 | 368 | |
317 | 369 | =end original |
318 | 370 | |
319 | 371 | @files = <*.c>; # 安全でない (readdir() のようなものを使う) |
320 | 372 | @files = glob('*.c'); # 安全でない (readdir() のようなものを使う) |
321 | 373 | |
322 | ||
374 | =begin original | |
323 | # have used an external program to do the filename expansion; but in | |
324 | # either case the result is tainted since the list of filenames comes | |
325 | # from outside of the program. | |
326 | 375 | |
376 | # In either case, the results of glob are tainted, since the list of | |
377 | # filenames comes from outside of the program. | |
378 | ||
379 | =end original | |
380 | ||
381 | # どちらの場合でも、glob の結果は汚染されています; ファイル名の一覧は | |
382 | # プログラムの外部から来るからです。 | |
383 | ||
327 | 384 | =begin original |
328 | 385 | |
329 | 386 | $bad = ($arg, 23); # $bad will be tainted |
330 | 387 | $arg, `true`; # Insecure (although it isn't really) |
331 | 388 | |
332 | 389 | =end original |
333 | 390 | |
334 | 391 | $bad = ($arg, 23); # $bad は汚染されているかも |
335 | 392 | $arg, `true`; # 安全でない (実際はそうでなくても) |
336 | 393 | |
337 | 394 | =begin original |
338 | 395 | |
339 | 396 | If you try to do something insecure, you will get a fatal error saying |
340 | 397 | something like "Insecure dependency" or "Insecure $ENV{PATH}". |
341 | 398 | |
342 | 399 | =end original |
343 | 400 | |
344 | 401 | 安全でないことをやろうとすると、"Insecure dependency" や |
345 | 402 | "Insecure $ENV{PATH}" のような致命的エラーとなるでしょう。 |
346 | 403 | |
347 | 404 | =begin original |
348 | 405 | |
349 | 406 | The exception to the principle of "one tainted value taints the whole |
350 | 407 | expression" is with the ternary conditional operator C<?:>. Since code |
351 | 408 | with a ternary conditional |
352 | 409 | |
353 | 410 | =end original |
354 | 411 | |
355 | ||
412 | 「一つの汚染された値が式全体を汚染する」の原則の例外は、3 項条件演算子 | |
356 | ||
413 | C<?:> です。 | |
357 | 414 | 3 項条件を使ったコード |
358 | 415 | |
359 | 416 | $result = $tainted_value ? "Untainted" : "Also untainted"; |
360 | 417 | |
361 | 418 | =begin original |
362 | 419 | |
363 | 420 | is effectively |
364 | 421 | |
365 | 422 | =end original |
366 | 423 | |
367 | 424 | というのは事実上 |
368 | 425 | |
369 | 426 | if ( $tainted_value ) { |
370 | 427 | $result = "Untainted"; |
371 | 428 | } else { |
372 | 429 | $result = "Also untainted"; |
373 | 430 | } |
374 | 431 | |
375 | 432 | =begin original |
376 | 433 | |
377 | 434 | it doesn't make sense for C<$result> to be tainted. |
378 | 435 | |
379 | 436 | =end original |
380 | 437 | |
381 | 438 | なので、C<$result> が汚染されたと考えるのは意味がありません。 |
382 | 439 | |
383 | 440 | =head2 Laundering and Detecting Tainted Data |
384 | 441 | |
385 | 442 | (汚染されたデータの検出と洗浄) |
386 | 443 | |
387 | 444 | =begin original |
388 | 445 | |
389 | 446 | To test whether a variable contains tainted data, and whose use would |
390 | 447 | thus trigger an "Insecure dependency" message, you can use the |
391 | 448 | C<tainted()> function of the Scalar::Util module, available in your |
392 | 449 | nearby CPAN mirror, and included in Perl starting from the release 5.8.0. |
393 | 450 | Or you may be able to use the following C<is_tainted()> function. |
394 | 451 | |
395 | 452 | =end original |
396 | 453 | |
397 | 454 | ある変数が汚染されたデータを保持しているかどうかを検査するため、そして、 |
398 | 455 | "Insecure dependency" メッセージの引き金になる可能性があるかどうかを |
399 | 456 | 検査するために、CPAN にあり、5.8.0 からは Perl に含まれている |
400 | 457 | Scalar::Util モジュールの C<tainted()> 関数を使えます。 |
401 | 458 | あるいは、以下のような関数 C<is_tainted()> を使うことができます。 |
402 | 459 | |
403 | 460 | sub is_tainted { |
461 | local $@; # Don't pollute caller's value. | |
404 | 462 | return ! eval { eval("#" . substr(join("", @_), 0, 0)); 1 }; |
405 | 463 | } |
406 | 464 | |
407 | 465 | =begin original |
408 | 466 | |
409 | 467 | This function makes use of the fact that the presence of tainted data |
410 | 468 | anywhere within an expression renders the entire expression tainted. It |
411 | 469 | would be inefficient for every operator to test every argument for |
412 | 470 | taintedness. Instead, the slightly more efficient and conservative |
413 | 471 | approach is used that if any tainted value has been accessed within the |
414 | 472 | same expression, the whole expression is considered tainted. |
415 | 473 | |
416 | 474 | =end original |
417 | 475 | |
418 | 476 | この関数はある式のどこかにある汚染されたデータが式全体を汚染してしまうことを |
419 | 477 | 利用しています。 |
420 | 478 | これはすべての演算子に対して、そのすべての引数が汚染されているかどうかの |
421 | 479 | 検査をするので効率は良くないでしょう。 |
422 | 480 | その代わりに、一部の式において汚染された値にアクセスして式全体が |
423 | 481 | 汚染されたとみなされるような場合には、もっと効率が良くて |
424 | 482 | 保守的な方法が使われます。 |
425 | 483 | |
426 | 484 | =begin original |
427 | 485 | |
428 | 486 | But testing for taintedness gets you only so far. Sometimes you have just |
429 | 487 | to clear your data's taintedness. Values may be untainted by using them |
430 | 488 | as keys in a hash; otherwise the only way to bypass the tainting |
431 | 489 | mechanism is by referencing subpatterns from a regular expression match. |
432 | Perl presumes that if you reference a substring using $1, $2, etc. | |
490 | Perl presumes that if you reference a substring using $1, $2, etc. in a | |
433 | ||
491 | non-tainting pattern, that | |
492 | you knew what you were doing when you wrote that pattern. That means using | |
434 | 493 | a bit of thought--don't just blindly untaint anything, or you defeat the |
435 | 494 | entire mechanism. It's better to verify that the variable has only good |
436 | 495 | characters (for certain values of "good") rather than checking whether it |
437 | 496 | has any bad characters. That's because it's far too easy to miss bad |
438 | 497 | characters that you never thought of. |
439 | 498 | |
440 | 499 | =end original |
441 | 500 | |
442 | 501 | しかし、汚染の検査は面倒です。 |
443 | 502 | あなたのデータの汚染を取り除くだけということもあるでしょう。 |
444 | 503 | 値はハッシュのキーとして使うことで浄化されます; さもなければ、 |
445 | 504 | 汚染検査機構をバイパスするためのただ一つの方法は、 |
446 | 505 | マッチした正規表現のサブパターンを参照することです。 |
447 | Perl は、あなたが $1、$2 などを使って部分文字列を | |
506 | Perl は、あなたが $1、$2 などを使って汚染されていないパターンで部分文字列を | |
448 | あなたがパターンを記述したときに何を行うのかを知っていたと | |
507 | 参照したときに、あなたがパターンを記述したときに何を行うのかを知っていたと | |
449 | ||
508 | 仮定します。 | |
509 | つまり、汚染されていないものを束縛しないか、機構全体を | |
510 | 無効にするということです。 | |
450 | 511 | これは、変数がなんらかの悪い文字を持っているかどうかを |
451 | 検査するというのではなく、変数が良い文字のみを持っていることの | |
512 | 検査するというのではなく、変数が良い文字のみを持っていることの検査には | |
452 | ||
513 | 都合が良いです。 | |
453 | 514 | これは(あなたが考えもしないような)悪い文字を見失うことがあまりにも |
454 | 515 | 簡単であるからです。 |
455 | 516 | |
456 | 517 | =begin original |
457 | 518 | |
458 | 519 | Here's a test to make sure that the data contains nothing but "word" |
459 | 520 | characters (alphabetics, numerics, and underscores), a hyphen, an at sign, |
460 | 521 | or a dot. |
461 | 522 | |
462 | 523 | =end original |
463 | 524 | |
464 | 525 | 以下に示す例は、データに“語”(アルファベット、数字、アンダースコア)の |
465 | 526 | 文字、ハイフン、アットマーク、ドット以外のものが入っていないことを |
466 | 527 | 検査するものです。 |
467 | 528 | |
468 | 529 | if ($data =~ /^([-\@\w.]+)$/) { |
469 | 530 | $data = $1; # $data now untainted |
470 | 531 | } else { |
471 | 532 | die "Bad data in '$data'"; # log this somewhere |
472 | 533 | } |
473 | 534 | |
474 | 535 | =begin original |
475 | 536 | |
476 | 537 | This is fairly secure because C</\w+/> doesn't normally match shell |
477 | 538 | metacharacters, nor are dot, dash, or at going to mean something special |
478 | 539 | to the shell. Use of C</.+/> would have been insecure in theory because |
479 | 540 | it lets everything through, but Perl doesn't check for that. The lesson |
480 | 541 | is that when untainting, you must be exceedingly careful with your patterns. |
481 | 542 | Laundering data using regular expression is the I<only> mechanism for |
482 | 543 | untainting dirty data, unless you use the strategy detailed below to fork |
483 | 544 | a child of lesser privilege. |
484 | 545 | |
485 | 546 | =end original |
486 | 547 | |
487 | これはかなり安全です | |
548 | これはかなり安全です; なぜなら C<\w+> は通常シェルのメタ文字には | |
488 | なぜなら C<\w+> は通常シェルのメタ文字には | |
489 | 549 | マッチしませんし、ドットやダッシュなどのシェルにとって特別な意味を |
490 | 550 | 持つようなものにもマッチしないからです。 |
491 | 551 | C</.+/> を使うのは、これはすべてを通してしまうのに Perl はそれを |
492 | 552 | チェックしませんから、理論的には安全ではありません。 |
493 | 553 | 汚染を取り除くときには、自分のパターンについて十二分に注意せねばなりません。 |
494 | 554 | 正規表現を使ったデータの洗浄は、先に説明したより低い特権度の子プロセスを |
495 | 555 | fork するための戦略を使うまでは汚れたデータの汚染除去 B<のみ> の機構です。 |
496 | 556 | |
497 | 557 | =begin original |
498 | 558 | |
499 | 559 | The example does not untaint C<$data> if C<use locale> is in effect, |
500 | 560 | because the characters matched by C<\w> are determined by the locale. |
501 | 561 | Perl considers that locale definitions are untrustworthy because they |
502 | 562 | contain data from outside the program. If you are writing a |
503 | 563 | locale-aware program, and want to launder data with a regular expression |
504 | 564 | containing C<\w>, put C<no locale> ahead of the expression in the same |
505 | 565 | block. See L<perllocale/SECURITY> for further discussion and examples. |
506 | 566 | |
507 | 567 | =end original |
508 | 568 | |
509 | 先の例では、C<use locale> が有効であるときには C<$data> の | |
569 | 先の例では、C<use locale> が有効であるときには C<$data> の汚染除去を | |
510 | ||
570 | 行いません; なぜなら、C<\w> にマッチする文字はロケールによって | |
511 | ||
571 | 決定されるからです。 | |
512 | 572 | Perl は、ロケールで決まることを、それがプログラムの外から来たデータから |
513 | 573 | 構成されているという理由によって信用できないものとみなします。 |
514 | 574 | もしロケールを考慮したプログラムを書いていて、C<\w> を含んだ正規表現で |
515 | 575 | データの洗浄を行いたいというのなら、式の置かれたのと同じブロックの前の部分に |
516 | 576 | C<no locale>を置きます。 |
517 | 577 | L<perllocale/SECURITY> に詳しい説明と例があります。 |
518 | 578 | |
519 | 579 | =head2 Switches On the "#!" Line |
520 | 580 | |
521 | 581 | ("#!" 行のスイッチ) |
522 | 582 | |
523 | 583 | =begin original |
524 | 584 | |
525 | 585 | When you make a script executable, in order to make it usable as a |
526 | 586 | command, the system will pass switches to perl from the script's #! |
527 | 587 | line. Perl checks that any command line switches given to a setuid |
528 | 588 | (or setgid) script actually match the ones set on the #! line. Some |
529 | 589 | Unix and Unix-like environments impose a one-switch limit on the #! |
530 | 590 | line, so you may need to use something like C<-wU> instead of C<-w -U> |
531 | 591 | under such systems. (This issue should arise only in Unix or |
532 | 592 | Unix-like environments that support #! and setuid or setgid scripts.) |
533 | 593 | |
534 | 594 | =end original |
535 | 595 | |
536 | 596 | 自分の作ったスクリプトをコマンドのように使えるようにしたとき、システムは |
537 | 597 | perl に対して、スクリプトの #! の行からコマンドラインスイッチを渡します。 |
538 | 598 | Perl は、setuid(あるいは setgid) されたスクリプトに与えられた |
539 | 599 | コマンドラインスイッチが #! 行にあるものと本当に一致するかどうかを検査します。 |
540 | 600 | 一部の UNIX や UNIX 風の環境では #! 行には一つのスイッチしか置けないので、 |
541 | 601 | そういったシステムでは C<-w -U> といった形式ではなく |
542 | C<-wU> のようにする必要があるでしょう | |
602 | C<-wU> のようにする必要があるでしょう。 | |
543 | setuid や setgid スクリプトが使える | |
603 | (これは #! をサポートしていて、setuid や setgid スクリプトが使える | |
544 | 行なわれることです | |
604 | UNIX 環境や UNIX に似た環境でのみ行なわれることです。) | |
545 | 605 | |
546 | 606 | =head2 Taint mode and @INC |
547 | 607 | |
548 | 608 | (汚染検査モードと @INC) |
549 | 609 | |
550 | 610 | =begin original |
551 | 611 | |
552 | When the taint mode (C<-T>) is in effect, the | |
612 | +When the taint mode (C<-T>) is in effect, the environment variables | |
553 | ||
613 | +C<PERL5LIB>, C<PERLLIB>, and C<PERL_USE_UNSAFE_INC> | |
554 | are ignored by Perl. You can still adjust C<@INC> from outside the | |
614 | are ignored by Perl. You can still adjust C<@INC> from outside the | |
555 | 615 | program by using the C<-I> command line option as explained in |
556 | L<perlrun>. The two environment variables ar | |
616 | L<perlrun|perlrun/-Idirectory>. The two environment variables are | |
557 | they are obscured, and a user running a program could | |
617 | ignored because they are obscured, and a user running a program could | |
558 | they are set, whereas the C<-I> option is clearly | |
618 | be unaware that they are set, whereas the C<-I> option is clearly | |
559 | therefore permitted. | |
619 | visible and therefore permitted. | |
560 | 620 | |
561 | 621 | =end original |
562 | 622 | |
563 | 汚染検査モード(C<-T>) が有効のとき、 | |
623 | 汚染検査モード(C<-T>) が有効のとき、 | |
564 | ||
624 | 環境変数 C<PERL5LIB>, C<PERLLIB>, C<PERL_USE_UNSAFE_INC> は | |
565 | ||
625 | Perl から無視されます。 | |
566 | ||
626 | それでも、L<perlrun|perlrun/-Idirectory> で説明されている | |
627 | C<-I> コマンドラインオプションを使うことで、 | |
628 | プログラムの外部から C<@INC> を調整出来ます。 | |
567 | 629 | 二つの環境変数は不明確で、プログラムを実行している |
568 | 630 | ユーザーはこの変数が設定されていることに気付かないかもしれないので |
569 | 631 | 無視されますが、一方 C<-I> オプションは明確に見えるので許可されます。 |
570 | 632 | |
571 | 633 | =begin original |
572 | 634 | |
573 | 635 | Another way to modify C<@INC> without modifying the program, is to use |
574 | 636 | the C<lib> pragma, e.g.: |
575 | 637 | |
576 | 638 | =end original |
577 | 639 | |
578 | 640 | プログラムを修正することなく C<@INC> を修正するもう一つの方法は、 |
579 | C<lib> プラグマを使うことです | |
641 | C<lib> プラグマを使うことです; つまり: | |
580 | 642 | |
581 | 643 | perl -Mlib=/foo program |
582 | 644 | |
583 | 645 | =begin original |
584 | 646 | |
585 | 647 | The benefit of using C<-Mlib=/foo> over C<-I/foo>, is that the former |
586 | will automagically remove any duplicated directories, while the later | |
648 | will automagically remove any duplicated directories, while the latter | |
587 | 649 | will not. |
588 | 650 | |
589 | 651 | =end original |
590 | 652 | |
591 | 653 | C<-I/foo> ではなく C<-Mlib=/foo> を使う利点は、後者だけが自動的に重複した |
592 | 654 | ディレクトリを自動的に除去することです。 |
593 | 655 | |
594 | 656 | =begin original |
595 | 657 | |
596 | 658 | Note that if a tainted string is added to C<@INC>, the following |
597 | 659 | problem will be reported: |
598 | 660 | |
599 | 661 | =end original |
600 | 662 | |
601 | 663 | もし汚染された文字列が C<@INC> に追加されると、以下の問題が報告されることに |
602 | 664 | 注意してください: |
603 | 665 | |
604 | 666 | Insecure dependency in require while running with -T switch |
605 | 667 | |
668 | =begin original | |
669 | ||
670 | On versions of Perl before 5.26, activating taint mode will also remove | |
671 | the current directory (".") from the default value of C<@INC>. Since | |
672 | version 5.26, the current directory isn't included in C<@INC> by | |
673 | default. | |
674 | ||
675 | =end original | |
676 | ||
677 | 5.26 より前のバージョンの Perl では、汚染モードを有効にすると、 | |
678 | C<@INC> のデフォルト値からカレントディレクトリ (".") を削除します。 | |
679 | バージョン 5.26 からは、デフォルトではカレントディレクトリは C<@INC> に | |
680 | 含まれていません。 | |
681 | ||
606 | 682 | =head2 Cleaning Up Your Path |
607 | 683 | |
608 | 684 | (実行パスを洗浄する) |
609 | 685 | |
610 | 686 | =begin original |
611 | 687 | |
612 | 688 | For "Insecure C<$ENV{PATH}>" messages, you need to set C<$ENV{'PATH'}> to |
613 | 689 | a known value, and each directory in the path must be absolute and |
614 | 690 | non-writable by others than its owner and group. You may be surprised to |
615 | 691 | get this message even if the pathname to your executable is fully |
616 | 692 | qualified. This is I<not> generated because you didn't supply a full path |
617 | 693 | to the program; instead, it's generated because you never set your PATH |
618 | 694 | environment variable, or you didn't set it to something that was safe. |
619 | 695 | Because Perl can't guarantee that the executable in question isn't itself |
620 | 696 | going to turn around and execute some other program that is dependent on |
621 | 697 | your PATH, it makes sure you set the PATH. |
622 | 698 | |
623 | 699 | =end original |
624 | 700 | |
625 | 701 | "Insecure C<$ENV{PATH}>" メッセージに対処するために、C<$ENV{'PATH'}> に |
626 | 既知の値を設定する必要があります | |
702 | 既知の値を設定する必要があります; そして path に含まれている各ディレクトリは、 | |
627 | そ | |
703 | 絶対パスで、そのディレクトリの所有者やグループ以外からの書き込みを | |
628 | そのディレクトリの所有者やグループ以外からの書き込みを | |
629 | 704 | 禁じていなければなりません。 |
630 | 実行しようとしているファイルをフルパスで | |
705 | 実行しようとしているファイルをフルパスで書いたとしてもこのメッセージが | |
631 | ||
706 | 出るので、びっくりすることがあるかもしれません。 | |
632 | 707 | このメッセージはプログラムのフルパスを書かなかったから出力されるではなく、 |
633 | 708 | 環境変数 PATH を設定しなかったり安全でない値を |
634 | 709 | 設定したりしたために出力されるのです。 |
635 | 710 | Perl は対象となっている実行ファイルが自分自身を方向転換したり、 |
636 | 711 | PATH を参照して別のプログラムを起動したりするかどうかを知ることができないので、 |
637 | 712 | 確実に自分で PATH を設定するようにします。 |
638 | 713 | |
639 | 714 | =begin original |
640 | 715 | |
641 | 716 | The PATH isn't the only environment variable which can cause problems. |
642 | 717 | Because some shells may use the variables IFS, CDPATH, ENV, and |
643 | 718 | BASH_ENV, Perl checks that those are either empty or untainted when |
644 | starting subprocesses. You may wish to add something like this to your | |
719 | starting subprocesses. You may wish to add something like this to your | |
645 | 720 | setid and taint-checking scripts. |
646 | 721 | |
647 | 722 | =end original |
648 | 723 | |
649 | 724 | この問題を引き起こす環境変数は PATH だけではありません。 |
650 | 725 | 一部のシェルでは、IFS、CDPATH、ENV、BASH_ENV のような環境変数を |
651 | 726 | 使っていますから、Perl はこれらの変数がからであるかあるいは |
652 | 727 | サブプロセスが起動したときに汚染されていないかどうかチェックします。 |
653 | 728 | setid していたり、汚染検査をするスクリプトに |
654 | 729 | 以下のような行を付け加えたくなるかしれません。 |
655 | 730 | |
656 | 731 | delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer |
657 | 732 | |
658 | 733 | =begin original |
659 | 734 | |
660 | 735 | It's also possible to get into trouble with other operations that don't |
661 | 736 | care whether they use tainted values. Make judicious use of the file |
662 | 737 | tests in dealing with any user-supplied filenames. When possible, do |
663 | 738 | opens and such B<after> properly dropping any special user (or group!) |
664 | privileges. Perl doesn't prevent you from | |
739 | privileges. Perl doesn't prevent you from | |
740 | opening tainted filenames for reading, | |
665 | 741 | so be careful what you print out. The tainting mechanism is intended to |
666 | 742 | prevent stupid mistakes, not to remove the need for thought. |
667 | 743 | |
668 | 744 | =end original |
669 | 745 | |
670 | 746 | このほかの、汚染された値を使っているかどうかに注意を払わないような |
671 | 747 | 操作によってトラブルに巻込まれる可能性もあります。 |
672 | 748 | ユーザーが使うようなファイル名を扱うファイル検査の使用を賢明なものにします。 |
673 | 749 | 可能であれば、ファイルをオープンした B<その後で> 適切にスペシャルユーザー |
674 | 750 | (グループも!)の特権を落とします。 |
675 | 751 | Perl はあなたが読み出しのために汚染されたファイル名を使ってファイルを |
676 | 752 | オープンすることを妨げませんから、出力の際には注意しましょう。 |
677 | 753 | 汚染検査機構はばかばかしいミスに対応するためのものであって、 |
678 | 754 | 必要なことを取り除くものではありません。 |
679 | 755 | |
680 | 756 | =begin original |
681 | 757 | |
682 | 758 | Perl does not call the shell to expand wild cards when you pass C<system> |
683 | 759 | and C<exec> explicit parameter lists instead of strings with possible shell |
684 | 760 | wildcards in them. Unfortunately, the C<open>, C<glob>, and |
685 | 761 | backtick functions provide no such alternate calling convention, so more |
686 | 762 | subterfuge will be required. |
687 | 763 | |
688 | 764 | =end original |
689 | 765 | |
690 | 766 | Perl は、C<system> や C<exec> に対してシェルのワイルドカードが |
691 | 767 | あるかもしれないような文字列ではなく陽にパラメータリストを渡した場合には、 |
692 | 768 | ワイルドカードの展開のためにシェルを呼び出したりしません。 |
693 | 769 | 残念なことに、C<open>、C<glob>、逆クォートといったものはそういった別の |
694 | 770 | 呼び出し手順を提供していないので、より多くのごまかしが必要とされます。 |
695 | 771 | |
696 | 772 | =begin original |
697 | 773 | |
698 | 774 | Perl provides a reasonably safe way to open a file or pipe from a setuid |
699 | 775 | or setgid program: just create a child process with reduced privilege who |
700 | 776 | does the dirty work for you. First, fork a child using the special |
701 | 777 | C<open> syntax that connects the parent and child by a pipe. Now the |
702 | 778 | child resets its ID set and any other per-process attributes, like |
703 | 779 | environment variables, umasks, current working directories, back to the |
704 | 780 | originals or known safe values. Then the child process, which no longer |
705 | 781 | has any special permissions, does the C<open> or other system call. |
706 | 782 | Finally, the child passes the data it managed to access back to the |
707 | 783 | parent. Because the file or pipe was opened in the child while running |
708 | 784 | under less privilege than the parent, it's not apt to be tricked into |
709 | 785 | doing something it shouldn't. |
710 | 786 | |
711 | 787 | =end original |
712 | 788 | |
713 | 789 | Perl は、setuid や setgid されたプログラムから安全にファイルやパイプを |
714 | 790 | オープンする方法を提供しています。 |
715 | 791 | これは単に、汚れ仕事をするための制限された権利を持った子プロセスを |
716 | 792 | 生成するというものです。 |
717 | 793 | まず最初に、パイプによって親プロセスと子プロセスとを繋ぐ構文の |
718 | 794 | 特別な C<open> を使って子プロセスを fork します。 |
719 | 795 | このとき、子プロセスはその ID セットをリセットしさらにその他の |
720 | 796 | プロセス毎の属性をリセットして、オリジナルの、 |
721 | 797 | もしくは安全な既知の値へと戻します。 |
722 | 798 | それからもはや何の特別のパーミッションも持っていない子プロセスが |
723 | 799 | C<open> などのシステムコールを実行します。 |
724 | 800 | ファイルやパイプは親プロセスよりも低い特権の元で実行されている |
725 | 801 | 子プロセスでオープンされたので、すべきではないようなことを |
726 | 802 | ごまかしておこなうことはできません。 |
727 | 803 | |
728 | 804 | =begin original |
729 | 805 | |
730 | 806 | Here's a way to do backticks reasonably safely. Notice how the C<exec> is |
731 | 807 | not called with a string that the shell could expand. This is by far the |
732 | 808 | best way to call something that might be subjected to shell escapes: just |
733 | 809 | never call the shell at all. |
734 | 810 | |
735 | 811 | =end original |
736 | 812 | |
737 | 813 | 以下に示すのは、安全に逆クォートを行う方法です。 |
738 | 814 | どのようにして C<exec> はシェルが展開するかもしれない文字列を伴って |
739 | 815 | 呼び出されないようになっているかに注目してください。 |
740 | これはシェルをエスケープする目的には最善の方法というわけではありません | |
816 | これはシェルをエスケープする目的には最善の方法というわけではありません; | |
741 | 817 | これは単に、シェルを呼び出さないというだけです。 |
742 | 818 | |
743 | use English | |
819 | use English; | |
744 | 820 | die "Can't fork: $!" unless defined($pid = open(KID, "-|")); |
745 | 821 | if ($pid) { # parent |
746 | 822 | while (<KID>) { |
747 | 823 | # do something |
748 | 824 | } |
749 | 825 | close KID; |
750 | 826 | } else { |
751 | 827 | my @temp = ($EUID, $EGID); |
752 | 828 | my $orig_uid = $UID; |
753 | 829 | my $orig_gid = $GID; |
754 | 830 | $EUID = $UID; |
755 | 831 | $EGID = $GID; |
756 | 832 | # Drop privileges |
757 | 833 | $UID = $orig_uid; |
758 | 834 | $GID = $orig_gid; |
759 | 835 | # Make sure privs are really gone |
760 | 836 | ($EUID, $EGID) = @temp; |
761 | 837 | die "Can't drop privileges" |
762 | 838 | unless $UID == $EUID && $GID eq $EGID; |
763 | 839 | $ENV{PATH} = "/bin:/usr/bin"; # Minimal PATH. |
764 | 840 | # Consider sanitizing the environment even more. |
765 | 841 | exec 'myprog', 'arg1', 'arg2' |
766 | 842 | or die "can't exec myprog: $!"; |
767 | 843 | } |
768 | 844 | |
769 | 845 | =begin original |
770 | 846 | |
771 | 847 | A similar strategy would work for wildcard expansion via C<glob>, although |
772 | 848 | you can use C<readdir> instead. |
773 | 849 | |
774 | 850 | =end original |
775 | 851 | |
776 | 852 | C<readdir> を代わりに使うことができるにしても、同様の戦略が C<glob> を |
777 | 853 | 通じたワイルドカードの展開でも有効です。 |
778 | 854 | |
779 | 855 | =begin original |
780 | 856 | |
781 | 857 | Taint checking is most useful when although you trust yourself not to have |
782 | 858 | written a program to give away the farm, you don't necessarily trust those |
783 | 859 | who end up using it not to try to trick it into doing something bad. This |
784 | 860 | is the kind of security checking that's useful for set-id programs and |
785 | 861 | programs launched on someone else's behalf, like CGI programs. |
786 | 862 | |
787 | 863 | =end original |
788 | 864 | |
789 | 865 | 汚染検査は、農場をくれてやる (give away the farm) ためのプログラムを |
790 | 866 | 記述することを自分自身に任せないということではなくて、 |
791 | 867 | 最終的にそれをつかって良からぬなにかを行おうとしているだれかを |
792 | 868 | 信頼する必要がないというときに最も便利なものです。 |
793 | 869 | これは、set-id プログラムや、CGI プログラムのように誰かに |
794 | 870 | すり変わって起動されるようなプログラムに便利なセキュリティチェックです。 |
795 | 871 | |
796 | 872 | =begin original |
797 | 873 | |
798 | 874 | This is quite different, however, from not even trusting the writer of the |
799 | 875 | code not to try to do something evil. That's the kind of trust needed |
800 | 876 | when someone hands you a program you've never seen before and says, "Here, |
801 | run this." For that kind of safety, check out the Safe | |
877 | run this." For that kind of safety, you might want to check out the Safe | |
802 | included standard in the Perl distribution. This module allows the | |
878 | module, included standard in the Perl distribution. This module allows the | |
803 | 879 | programmer to set up special compartments in which all system operations |
804 | are trapped and namespace access is carefully controlled. | |
880 | are trapped and namespace access is carefully controlled. Safe should | |
881 | not be considered bullet-proof, though: it will not prevent the foreign | |
882 | code to set up infinite loops, allocate gigabytes of memory, or even | |
883 | abusing perl bugs to make the host interpreter crash or behave in | |
884 | unpredictable ways. In any case it's better avoided completely if you're | |
885 | really concerned about security. | |
805 | 886 | |
806 | 887 | =end original |
807 | 888 | |
808 | 889 | しかしながら、これは良からぬなにかを行おうはしないコードの作者を |
809 | 890 | 信用しないということとは明らかに違います。 |
810 | 891 | これは誰かが、プログラムをあなたが今まで見たことのないようにいじって |
811 | 892 | 「ほら、これを実行して」と言わせるようなときに必要な種類の信用です。 |
812 | 893 | この種の安全性のために、Perl の配布パッケージに標準で含まれている |
813 | Safe モジュールをチェックし | |
894 | Safe モジュールをチェックしたほうがいいかもしれません。 | |
814 | 895 | このモジュールはプログラマーがすべてのシステム操作をトラップし、 |
815 | 896 | 名前空間のアクセスが注意深く制御されるような |
816 | 897 | 特別な仕切り(compartment)をセットアップすることを許します。 |
898 | しかし Safe は防弾であると考えるべきではありません: 無限ループ、 | |
899 | 何ギガバイトものメモリ割り当て、ホストインタプリタをクラッシュや予測不能な | |
900 | 振る舞いをさせるための perl のバグの悪用をする外部コードすら防げません。 | |
901 | 本当にセキュリティのことを考えるならどの場合も完全に防いだ方が良いです。 | |
817 | 902 | |
818 | =head2 Sec | |
903 | =head2 Shebang Race Condition | |
819 | 904 | |
820 | ( | |
905 | (Shebang の競合条件) | |
821 | 906 | |
822 | 907 | =begin original |
823 | 908 | |
824 | 909 | Beyond the obvious problems that stem from giving special privileges to |
825 | 910 | systems as flexible as scripts, on many versions of Unix, set-id scripts |
826 | 911 | are inherently insecure right from the start. The problem is a race |
827 | 912 | condition in the kernel. Between the time the kernel opens the file to |
828 | 913 | see which interpreter to run and when the (now-set-id) interpreter turns |
829 | 914 | around and reopens the file to interpret it, the file in question may have |
830 | 915 | changed, especially if you have symbolic links on your system. |
831 | 916 | |
832 | 917 | =end original |
833 | 918 | |
834 | 919 | スクリプトと同じくらい柔軟に特別な権限をシステムに与えて |
835 | 920 | しまう類の明白な問題の他に、多くの UNIX では、set-id されたスクリプトは |
836 | 921 | 本質的に安全でない権利を最初から持っています。 |
837 | 922 | その問題とは、カーネルにおける競合条件です。 |
838 | 923 | インタープリターを実行するためにカーネルがファイルをオープンするのと、 |
839 | 924 | (set-id された)インタープリターが起動してファイルを解釈するために |
840 | 再度オープンするその間に、問題のファイルが変更されるかもしれません | |
925 | 再度オープンするその間に、問題のファイルが変更されるかもしれません; | |
841 | 926 | 特に、使っているシステムがシンボリックリンクをサポートしている場合には。 |
842 | 927 | |
843 | 928 | =begin original |
844 | 929 | |
845 | ||
930 | Some Unixes, especially more recent ones, are free of this | |
846 | ||
931 | inherent security bug. On such systems, when the kernel passes the name | |
847 | o | |
932 | of the set-id script to open to the interpreter, rather than using a | |
848 | ||
933 | pathname subject to meddling, it instead passes I</dev/fd/3>. This is a | |
849 | ||
934 | special file already opened on the script, so that there can be no race | |
850 | ||
935 | condition for evil scripts to exploit. On these systems, Perl should be | |
851 | ||
936 | compiled with C<-DSETUID_SCRIPTS_ARE_SECURE_NOW>. The F<Configure> | |
852 | ||
937 | program that builds Perl tries to figure this out for itself, so you | |
938 | should never have to specify this yourself. Most modern releases of | |
939 | SysVr4 and BSD 4.4 use this approach to avoid the kernel race condition. | |
853 | 940 | |
854 | 941 | =end original |
855 | 942 | |
856 | ||
943 | 一部の Unix、特に最近のものは、このようなセキュリティバグに対する耐性を | |
857 | ||
944 | 備えています。 | |
858 | システムは | |
945 | そのようなシステムでは、インタプリタを起動するためにカーネルに | |
859 | ||
946 | set-id スクリプトが渡されたときにそのパス名をそのまま使うのではなく、 | |
860 | ||
947 | 代わりに I</dev/fd/3> を渡します。 | |
861 | ||
948 | これはスクリプトでは、あらかじめオープンされている特別なファイルですから、 | |
862 | ||
949 | 邪悪なスクリプトをこじ入れるためにつかうことはできません。 | |
863 | ||
950 | こういったシステムにおいては、Perl は | |
864 | ||
951 | C<-DSETUID_SCRIPTS_ARE_SECURE_NOW> を付加してコンパイルすべきでしょう。 | |
865 | ||
952 | Perl を構築する F<Configure> プログラムは自分自身でこれを | |
866 | 特別な | |
953 | 見つけ出そうとするので、あなたが特別な何かをしなければならない、 | |
954 | ということはありあません。 | |
955 | SysVr4 の最近のリリースのほとんどや BSD4.4 は | |
956 | このアプローチをカーネルの競合条件を避けるために使っています。 | |
867 | 957 | |
868 | 958 | =begin original |
869 | 959 | |
870 | ||
960 | If you don't have the safe version of set-id scripts, all is not lost. | |
871 | ||
961 | Sometimes this kernel "feature" can be disabled, so that the kernel | |
872 | either d | |
962 | either doesn't run set-id scripts with the set-id or doesn't run them | |
963 | at all. Either way avoids the exploitability of the race condition, | |
964 | but doesn't help in actually running scripts set-id. | |
965 | ||
966 | =end original | |
967 | ||
968 | 安全なバージョンの set-id スクリプトがない場合でも、他に手段が | |
969 | ないわけではありません。 | |
970 | カーネルは set-id スクリプトを set-id で実行しないか、 | |
971 | これらを全く実行しないことで、 | |
972 | このカーネル「仕様」は使用禁止にできることもあります。 | |
973 | どちらかの方法で競合条件の悪用可能性を避けることができますが、 | |
974 | 実際にスクリプトを set-id で実行する助けにはなりません。 | |
975 | ||
976 | =begin original | |
977 | ||
978 | If the kernel set-id script feature isn't disabled, then any set-id | |
979 | script provides an exploitable vulnerability. Perl can't avoid being | |
980 | exploitable, but will point out vulnerable scripts where it can. If Perl | |
981 | detects that it is being applied to a set-id script then it will complain | |
982 | loudly that your set-id script is insecure, and won't run it. When Perl | |
983 | complains, you need to remove the set-id bit from the script to eliminate | |
984 | the vulnerability. Refusing to run the script doesn't in itself close | |
985 | the vulnerability; it is just Perl's way of encouraging you to do this. | |
986 | ||
987 | ||
988 | =end original | |
989 | ||
990 | kernel set-id スクリプト機能が禁止されていなければ、 | |
991 | 任意の set-id スクリプトは悪用可能な脆弱性を持ちます。 | |
992 | Perl は悪用可能性を避けることはできませんが、 | |
993 | 可能性のある脆弱性のあるスクリプトを示すことはできます。 | |
994 | Perl が set-id スクリプトが適用されていることを検出した場合、 | |
995 | あなたの set-id スクリプトは安全ではないとやかましく主張し、 | |
996 | 実行しません。 | |
997 | Perl が文句を言った場合、脆弱性を取り除くためにスクリプトから | |
998 | set-id ビットを取り除く必要があります。 | |
999 | スクリプトの実行を拒否することは、それ自体で脆弱性を閉じることはありません; | |
1000 | これは単にそうするようにあなたを後押しする Perl の方法です。 | |
1001 | ||
1002 | =begin original | |
1003 | ||
1004 | To actually run a script set-id, if you don't have the safe version of | |
1005 | set-id scripts, you'll need to put a C wrapper around | |
873 | 1006 | the script. A C wrapper is just a compiled program that does nothing |
874 | 1007 | except call your Perl program. Compiled programs are not subject to the |
875 | 1008 | kernel bug that plagues set-id scripts. Here's a simple wrapper, written |
876 | 1009 | in C: |
877 | 1010 | |
878 | 1011 | =end original |
879 | 1012 | |
880 | ||
1013 | 実際に set-id でスクリプトを実行するために、安全なバージョンの | |
881 | ||
1014 | set-id スクリプトを持っていない場合は、 | |
882 | ||
1015 | スクリプトを C のラッパーで包む必要があります。 | |
883 | スクリプトを C のラッパーで包んでしまうかのいずれかが必要です。 | |
884 | 1016 | C ラッパーは、Perl プログラムを呼び出すことを除いては |
885 | 1017 | 何もしないプログラムです。 |
886 | 1018 | コンパイルされたプログラムは set-id されたスクリプトに関する |
887 | 1019 | カーネルのバグには影響されません。 |
888 | 次の例は、C で書いた単純なラッパーです | |
1020 | 次の例は、C で書いた単純なラッパーです: | |
889 | 1021 | |
1022 | #include <unistd.h> | |
1023 | #include <stdio.h> | |
1024 | #include <string.h> | |
1025 | #include <errno.h> | |
1026 | ||
890 | 1027 | #define REAL_PATH "/path/to/script" |
891 | ||
892 | ||
1029 | int main(int argc, char **argv) | |
893 | 1030 | { |
894 | ||
1031 | execv(REAL_PATH, argv); | |
1032 | fprintf(stderr, "%s: %s: %s\n", | |
1033 | argv[0], REAL_PATH, strerror(errno)); | |
1034 | return 127; | |
895 | 1035 | } |
896 | 1036 | |
897 | 1037 | =begin original |
898 | 1038 | |
899 | 1039 | Compile this wrapper into a binary executable and then make I<it> rather |
900 | than your script setuid or setgid. | |
1040 | than your script setuid or setgid. Note that this wrapper isn't doing | |
1041 | anything to sanitise the execution environment other than ensuring | |
1042 | that a safe path to the script is used. It only avoids the shebang | |
1043 | race condition. It relies on Perl's own features, and on the script | |
1044 | itself being careful, to make it safe enough to run the script set-id. | |
901 | 1045 | |
902 | 1046 | =end original |
903 | 1047 | |
904 | 1048 | このラッパーをコンパイルして実行ファイルにし、スクリプトではなく |
905 | 1049 | I<この実行ファイル> を setuid したり setgid します。 |
1050 | このラッパーは、スクリプトが使われる安全なパスであることを保証する以外に | |
1051 | 実行環境をサニタイズしないことに注意してください。 | |
1052 | これはシェバン競合条件のみを回避します。 | |
1053 | スクリプトを set-id で実行するのに十分なぐらい安全であることは、 | |
1054 | これは Perl 自身の機能と、スクリプト自身が注意深いことに依存しています。 | |
906 | 1055 | |
907 | =begin original | |
908 | ||
909 | In recent years, vendors have begun to supply systems free of this | |
910 | inherent security bug. On such systems, when the kernel passes the name | |
911 | of the set-id script to open to the interpreter, rather than using a | |
912 | pathname subject to meddling, it instead passes I</dev/fd/3>. This is a | |
913 | special file already opened on the script, so that there can be no race | |
914 | condition for evil scripts to exploit. On these systems, Perl should be | |
915 | compiled with C<-DSETUID_SCRIPTS_ARE_SECURE_NOW>. The F<Configure> | |
916 | program that builds Perl tries to figure this out for itself, so you | |
917 | should never have to specify this yourself. Most modern releases of | |
918 | SysVr4 and BSD 4.4 use this approach to avoid the kernel race condition. | |
919 | ||
920 | =end original | |
921 | ||
922 | 近年、ベンダーはこのようなセキュリティバグに対する耐性を備えたシステムを | |
923 | 提供しはじめました。 | |
924 | そのようなシステムでは、インタープリターを起動するためにカーネルに | |
925 | set-id スクリプトが渡されたときにそのパス名をそのまま使うのではなく、 | |
926 | 代わりに I</dev/fd/3> を渡します。 | |
927 | これはスクリプトでは、あらかじめオープンされている特別なファイルですから、 | |
928 | 邪悪なスクリプトをこじ入れるためにつかうことはできません。 | |
929 | こういったシステムにおいては、Perl は | |
930 | C<-DSETUID_SCRIPTS_ARE_SECURE_NOW> を付加してコンパイルすべきでしょう。 | |
931 | Perl を構築する F<Configure> プログラムは自分自身でこれを | |
932 | 見つけ出そうとするので、あなたが特別な何かをしなければならない、 | |
933 | ということはありあません。 | |
934 | SysVr4 の最近のリリースのほとんどや BSD4.4 は | |
935 | このアプローチをカーネルの競合条件を避けるために使っています。 | |
936 | ||
937 | =begin original | |
938 | ||
939 | Prior to release 5.6.1 of Perl, bugs in the code of F<suidperl> could | |
940 | introduce a security hole. | |
941 | ||
942 | =end original | |
943 | ||
944 | リリース 5.6.1 以前の Perl では、F<suidperl> にあったバグによって、 | |
945 | セキュリティホールが持ち込まれる可能性がありました。 | |
946 | ||
947 | 1056 | =head2 Protecting Your Programs |
948 | 1057 | |
949 | 1058 | (あなたのプログラムを守る) |
950 | 1059 | |
951 | 1060 | =begin original |
952 | 1061 | |
953 | 1062 | There are a number of ways to hide the source to your Perl programs, |
954 | 1063 | with varying levels of "security". |
955 | 1064 | |
956 | 1065 | =end original |
957 | 1066 | |
958 | 1067 | ここで挙げるのは、あなたの Perl プログラムのソースコードをさまざまな |
959 | 1068 | “セキュリティ”のレベルで隠す方法です。 |
960 | 1069 | |
961 | 1070 | =begin original |
962 | 1071 | |
963 | 1072 | First of all, however, you I<can't> take away read permission, because |
964 | 1073 | the source code has to be readable in order to be compiled and |
965 | 1074 | interpreted. (That doesn't mean that a CGI script's source is |
966 | 1075 | readable by people on the web, though.) So you have to leave the |
967 | 1076 | permissions at the socially friendly 0755 level. This lets |
968 | 1077 | people on your local system only see your source. |
969 | 1078 | |
970 | 1079 | =end original |
971 | 1080 | |
972 | 1081 | しかしまず最初にいっておきますが、ソースコードの読み込み権限を |
973 | 1082 | 落とすことは B<できません>。 |
974 | 1083 | なぜなら、ソースコードは、コンパイルやインタープリットするために |
975 | 1084 | 読めるようになっていなければならないからです(これは、CGI スクリプトのソースが |
976 | 1085 | web の利用者から見ることができないというのとは違います)。 |
977 | 1086 | このため、パーミッションは 0755 レベルにしておかなければならないのです。 |
978 | 1087 | これによってあなたのローカルシステム上のユーザーはあなたのソースを |
979 | 1088 | 見ることだけになります。 |
980 | 1089 | |
981 | 1090 | =begin original |
982 | 1091 | |
983 | 1092 | Some people mistakenly regard this as a security problem. If your program does |
984 | 1093 | insecure things, and relies on people not knowing how to exploit those |
985 | 1094 | insecurities, it is not secure. It is often possible for someone to |
986 | 1095 | determine the insecure things and exploit them without viewing the |
987 | 1096 | source. Security through obscurity, the name for hiding your bugs |
988 | 1097 | instead of fixing them, is little security indeed. |
989 | 1098 | |
990 | 1099 | =end original |
991 | 1100 | |
992 | 1101 | 一部の人達はこれをセキュリティ上の問題であると考えています。 |
993 | 1102 | あなたのプログラムが安全でないことを行っていて、 |
994 | 1103 | 他人がそういったセキュリティの隙間をこじ開ける方法を知らないことに |
995 | 1104 | 頼っているのなら、それは安全ではないのです。 |
996 | 1105 | これはある人が安全でないことがらを見つけだし、 |
997 | 1106 | ソースを見ることなしにそれをこじ開けることの要因となります。 |
998 | 1107 | 明快さを通したセキュリティはバグを直すのではなく隠すことに比べれば、 |
999 | 1108 | セキュリティをほんの少しだけしか傷つけません。 |
1000 | 1109 | |
1001 | 1110 | =begin original |
1002 | 1111 | |
1003 | 1112 | You can try using encryption via source filters (Filter::* from CPAN, |
1004 | 1113 | or Filter::Util::Call and Filter::Simple since Perl 5.8). |
1005 | 1114 | But crackers might be able to decrypt it. You can try using the byte |
1006 | 1115 | code compiler and interpreter described below, but crackers might be |
1007 | 1116 | able to de-compile it. You can try using the native-code compiler |
1008 | 1117 | described below, but crackers might be able to disassemble it. These |
1009 | 1118 | pose varying degrees of difficulty to people wanting to get at your |
1010 | 1119 | code, but none can definitively conceal it (this is true of every |
1011 | 1120 | language, not just Perl). |
1012 | 1121 | |
1013 | 1122 | =end original |
1014 | 1123 | |
1015 | 1124 | ソースフィルター(CPAN にある Filter::*, |
1016 | 1125 | or Filter::Util::Call and Filter::Simple since Perl 5.8) |
1017 | を通して暗号化しようと | |
1126 | を通して暗号化しようとすることはできます。 | |
1018 | ||
1127 | しかしクラッカーがそれを復号化することは可能でしょう。 | |
1019 | 1128 | 先に説明したバイトコードコンパイラーとインタープリターを使うことも |
1020 | 1129 | できますが、クラッカーはそれを逆コンパイルすることができるかもしれません。 |
1021 | 1130 | ネイティブコードコンパイラーを使おうとしても、クラッカーはそれを |
1022 | 1131 | 逆アセンブルできるかもしれません。 |
1023 | 1132 | こういったことは、他人があなたの |
1024 | 1133 | プログラムを手に入れようとすることを難しくしたりしますが、 |
1025 | 1134 | プログラムを決定的に隠すことは誰にもできないのです(このことは、 |
1026 | 1135 | Perl に限らずすべての言語にあてはまります)。 |
1027 | 1136 | |
1028 | 1137 | =begin original |
1029 | 1138 | |
1030 | 1139 | If you're concerned about people profiting from your code, then the |
1031 | bottom line is that nothing but a restrictive licen | |
1140 | bottom line is that nothing but a restrictive license will give you | |
1032 | 1141 | legal security. License your software and pepper it with threatening |
1033 | 1142 | statements like "This is unpublished proprietary software of XYZ Corp. |
1034 | 1143 | Your access to it does not give you permission to use it blah blah |
1035 | blah." You should see a lawyer to be sure your licen | |
1144 | blah." You should see a lawyer to be sure your license's wording will | |
1036 | 1145 | stand up in court. |
1037 | 1146 | |
1038 | 1147 | =end original |
1039 | 1148 | |
1040 | 1149 | 他人があなたのプログラムから受ける利益について気にしているのであれば、 |
1041 | 1150 | 制限つきライセンスがあなたに法的な安全を与えるでしょう。 |
1042 | あなたのソフトウェアのライセンスに、 | |
1151 | あなたのソフトウェアのライセンスに、「本ソフトウェアは XYZ Corp.による、 | |
1043 | 1152 | 公表されていない独占的ソフトウェアです。 |
1044 | あなたが使用するために | |
1153 | あなたが使用するためにこれにアクセスすることは許可されておらず云々」のような | |
1045 | ||
1154 | 脅し文句を付けておきます。 | |
1046 | ||
1155 | あなたのライセンスの文言が法廷で確実に有効なものとなるように、 | |
1047 | あなたのライセンスが確実に有効なものとなるように、 | |
1048 | 1156 | 弁護士と相談したほうが良いでしょう。 |
1049 | 1157 | |
1050 | 1158 | =head2 Unicode |
1051 | 1159 | |
1052 | 1160 | =begin original |
1053 | 1161 | |
1054 | 1162 | Unicode is a new and complex technology and one may easily overlook |
1055 | 1163 | certain security pitfalls. See L<perluniintro> for an overview and |
1056 | 1164 | L<perlunicode> for details, and L<perlunicode/"Security Implications |
1057 | 1165 | of Unicode"> for security implications in particular. |
1058 | 1166 | |
1059 | 1167 | =end original |
1060 | 1168 | |
1061 | 1169 | Unicode は新しくて複雑な技術で、ある種のセキュリティの罠を簡単に |
1062 | 1170 | 見落としてしまいます。 |
1063 | 1171 | 概要については L<perluniintro> を、詳細については L<perlunicode> を、 |
1064 | 1172 | そして特にセキュリティ実装については L<perlunicode/"Security Implications |
1065 | 1173 | of Unicode"> を参照してください。 |
1066 | 1174 | |
1067 | 1175 | =head2 Algorithmic Complexity Attacks |
1068 | 1176 | |
1069 | 1177 | (アルゴリズム的複雑性攻撃) |
1070 | 1178 | |
1071 | 1179 | =begin original |
1072 | 1180 | |
1073 | 1181 | Certain internal algorithms used in the implementation of Perl can |
1074 | 1182 | be attacked by choosing the input carefully to consume large amounts |
1075 | 1183 | of either time or space or both. This can lead into the so-called |
1076 | 1184 | I<Denial of Service> (DoS) attacks. |
1077 | 1185 | |
1078 | 1186 | =end original |
1079 | 1187 | |
1080 | 1188 | Perl の実装で使われているある種の内部アルゴリズムは、多くの時間や |
1081 | 1189 | 空間を消費するように注意深く選択された入力によって攻撃可能です。 |
1082 | 1190 | これにより I<サービス拒否(Denial of Service)> (DoS) 攻撃と呼ばれている |
1083 | 1191 | ものを引き起こすことができます。 |
1084 | 1192 | |
1085 | 1193 | =over 4 |
1086 | 1194 | |
1087 | 1195 | =item * |
1088 | 1196 | |
1089 | 1197 | =begin original |
1090 | 1198 | |
1091 | Hash | |
1199 | Hash Algorithm - Hash algorithms like the one used in Perl are well | |
1092 | ||
1200 | known to be vulnerable to collision attacks on their hash function. | |
1093 | ||
1201 | Such attacks involve constructing a set of keys which collide into | |
1094 | ||
1202 | the same bucket producing inefficient behavior. Such attacks often | |
1203 | depend on discovering the seed of the hash function used to map the | |
1204 | keys to buckets. That seed is then used to brute-force a key set which | |
1205 | can be used to mount a denial of service attack. In Perl 5.8.1 changes | |
1206 | were introduced to harden Perl to such attacks, and then later in | |
1207 | Perl 5.18.0 these features were enhanced and additional protections | |
1208 | added. | |
1095 | 1209 | |
1096 | 1210 | =end original |
1097 | 1211 | |
1098 | ハッシュ | |
1212 | ハッシュアルゴリズム - 以前 Perl で使われていたようなハッシュアルゴリズムは、 | |
1099 | ||
1213 | ハッシュ関数に対する衝突攻撃に対して脆弱であることでよく知られています。 | |
1100 | ||
1214 | この攻撃は、非効率的な振る舞いをさせるために同じバケツに入るようなキーの集合を | |
1215 | 構築することで行われます。 | |
1216 | このような攻撃はしばしばキーをバケツにマッピングするために使われる | |
1217 | ハッシュ関数の種の発見に依存します。 | |
1218 | この種はそれからサービス拒否攻撃を起こせるブルートフォースキー集合に | |
1219 | 使われます。 | |
1220 | Perl 5.8.1 でこのような攻撃に対する Perl の強化が導入され、後に Perl 5.18.0 で | |
1221 | これらの機能は拡張され、追加の防御が追加されました。 | |
1101 | 1222 | |
1102 | 1223 | =begin original |
1103 | 1224 | |
1104 | ||
1225 | At the time of this writing, Perl 5.18.0 is considered to be | |
1105 | ha | |
1226 | well-hardened against algorithmic complexity attacks on its hash | |
1106 | i | |
1227 | implementation. This is largely owed to the following measures | |
1107 | t | |
1228 | mitigate attacks: | |
1108 | makes generating such naughty hash keys harder. | |
1109 | See L<perlrun/PERL_HASH_SEED> for more information. | |
1110 | 1229 | |
1111 | 1230 | =end original |
1112 | 1231 | |
1113 | ||
1232 | これを書いている時点では、Perl 5.18.0 はハッシュ実装に対するアルゴリズム的 | |
1114 | ||
1233 | 複雑性攻撃に対してよく防御されていると考えられています。 | |
1115 | ||
1234 | これは主に以下のような要素が攻撃を緩和していることに依ります: | |
1116 | Perl 5.8.1 で、そのようなよくないハッシュキーを生成するのをより難しく | |
1117 | するために、ハッシュ関数は擬似乱数の種によってランダムに攪拌されます。 | |
1118 | さらなる情報については L<perlrun/PERL_HASH_SEED> を参照してください。 | |
1119 | 1235 | |
1236 | =over 4 | |
1237 | ||
1238 | =item Hash Seed Randomization | |
1239 | ||
1240 | (ハッシュの種のランダム化) | |
1241 | ||
1120 | 1242 | =begin original |
1121 | 1243 | |
1122 | ||
1244 | In order to make it impossible to know what seed to generate an attack | |
1123 | ||
1245 | key set for, this seed is randomly initialized at process start. This | |
1124 | PERL_HASH_SEED | |
1246 | may be overridden by using the PERL_HASH_SEED environment variable, see | |
1125 | ||
1247 | L<perlrun/PERL_HASH_SEED>. This environment variable controls how | |
1126 | ||
1248 | items are actually stored, not how they are presented via | |
1127 | ||
1249 | C<keys>, C<values> and C<each>. | |
1128 | different runs are no more identical). | |
1129 | 1250 | |
1130 | 1251 | =end original |
1131 | 1252 | |
1132 | ||
1253 | 攻撃キー集合を生成するための種が何かを知ることを不可能にするために、この種は | |
1133 | ||
1254 | プロセス開始時にランダムに初期化されます。 | |
1134 | ||
1255 | これは PERL_HASH_SEED 環境変数を使うことで上書きできます; | |
1135 | ||
1256 | L<perlrun/PERL_HASH_SEED> を参照してください。 | |
1136 | ||
1257 | この環境変数はアイテムが実際にどのように保管されるかを制御するもので、 | |
1137 | ||
1258 | C<keys>, C<values>, C<each> 経由でどのように表現されるかを | |
1138 | ||
1259 | 制御するものではありません。 | |
1139 | 1260 | |
1261 | =item Hash Traversal Randomization | |
1262 | ||
1263 | (ハッシュ探索のランダム化) | |
1264 | ||
1140 | 1265 | =begin original |
1141 | 1266 | |
1142 | ||
1267 | Independent of which seed is used in the hash function, C<keys>, | |
1143 | ||
1268 | C<values>, and C<each> return items in a per-hash randomized order. | |
1144 | ||
1269 | Modifying a hash by insertion will change the iteration order of that hash. | |
1145 | ||
1270 | This behavior can be overridden by using C<hash_traversal_mask()> from | |
1271 | L<Hash::Util> or by using the PERL_PERTURB_KEYS environment variable, | |
1272 | see L<perlrun/PERL_PERTURB_KEYS>. Note that this feature controls the | |
1273 | "visible" order of the keys, and not the actual order they are stored in. | |
1146 | 1274 | |
1147 | 1275 | =end original |
1148 | 1276 | |
1277 | ハッシュ関数でどの種が使われるかとは独立に、C<keys>, C<values>, C<each> は | |
1278 | ハッシュ毎にランダム化された順序で要素を返します。 | |
1279 | 挿入によってハッシュが変更されると、そのハッシュの反復順が変わります。 | |
1280 | この振る舞いは、L<Hash::Util> の C<hash_traversal_mask()> を使うか、 | |
1281 | PERL_PERTURB_KEYS 環境変数を使うことで上書きできます; | |
1282 | L<perlrun/PERL_PERTURB_KEYS> を参照してください。 | |
1283 | この機能は keys の「見える」順序を制御するもので、実際に保管される順序を | |
1284 | 制御するものではありません。 | |
1285 | ||
1286 | =item Bucket Order Perturbance | |
1287 | ||
1288 | (バケツ順の撹乱) | |
1289 | ||
1290 | =begin original | |
1291 | ||
1292 | When items collide into a given hash bucket the order they are stored in | |
1293 | the chain is no longer predictable in Perl 5.18. This | |
1294 | has the intention to make it harder to observe a | |
1295 | collision. This behavior can be overridden by using | |
1296 | the PERL_PERTURB_KEYS environment variable, see L<perlrun/PERL_PERTURB_KEYS>. | |
1297 | ||
1298 | =end original | |
1299 | ||
1300 | あるハッシュバケツで要素が衝突したとき、Perl 5.18 ではチェーンに保管される順番は | |
1301 | もはや予測できなくなりました。 | |
1302 | これは、衝突を観測するのをより困難にする意図があります。 | |
1303 | この振る舞いは PERL_PERTURB_KEYS 環境変数を使うことで上書きできます; | |
1304 | L<perlrun/PERL_PERTURB_KEYS> を参照してください。 | |
1305 | ||
1306 | =item New Default Hash Function | |
1307 | ||
1308 | (新しいデフォルトハッシュ関数) | |
1309 | ||
1310 | =begin original | |
1311 | ||
1312 | The default hash function has been modified with the intention of making | |
1313 | it harder to infer the hash seed. | |
1314 | ||
1315 | =end original | |
1316 | ||
1317 | デフォルトハッシュ関数は、ハッシュの種の推論をより難しくするために | |
1318 | 修正されました。 | |
1319 | ||
1320 | =item Alternative Hash Functions | |
1321 | ||
1322 | (代替ハッシュ関数) | |
1323 | ||
1324 | =begin original | |
1325 | ||
1326 | The source code includes multiple hash algorithms to choose from. While we | |
1327 | believe that the default perl hash is robust to attack, we have included the | |
1328 | hash function Siphash as a fall-back option. At the time of release of | |
1329 | Perl 5.18.0 Siphash is believed to be of cryptographic strength. This is | |
1330 | not the default as it is much slower than the default hash. | |
1331 | ||
1332 | =end original | |
1333 | ||
1334 | ソースコードには選択できる複数のハッシュアルゴリズムが含まれています。 | |
1335 | デフォルトの perl ハッシュは攻撃に頑強であると信じていますが、 | |
1336 | フォールバックオプションとして Siphash ハッシュ関数も含めています。 | |
1337 | Perl 5.18.0 のリリースの時点で、Siphash は暗号学的強度を持つと | |
1338 | 信じられています。 | |
1339 | これはデフォルトのハッシュよりもはるかに遅いので、デフォルトではありません。 | |
1340 | ||
1341 | =back | |
1342 | ||
1343 | =begin original | |
1344 | ||
1345 | Without compiling a special Perl, there is no way to get the exact same | |
1346 | behavior of any versions prior to Perl 5.18.0. The closest one can get | |
1347 | is by setting PERL_PERTURB_KEYS to 0 and setting the PERL_HASH_SEED | |
1348 | to a known value. We do not advise those settings for production use | |
1349 | due to the above security considerations. | |
1350 | ||
1351 | =end original | |
1352 | ||
1353 | 特別な Perl をコンパイルしない限り、Perl 5.18.0 より前のバージョンと正確に | |
1354 | 同じ振る舞いにする方法はありません。 | |
1355 | 最も近いのは、PERL_PERTURB_KEYS に 0 を設定し、PERL_HASH_SEED に既知の値を | |
1356 | 設定することです。 | |
1357 | 上述のセキュリティ上の問題のため、製品にはこの設定をしないことを勧めます。 | |
1358 | ||
1359 | =begin original | |
1360 | ||
1361 | B<Perl has never guaranteed any ordering of the hash keys>, and | |
1362 | the ordering has already changed several times during the lifetime of | |
1363 | Perl 5. Also, the ordering of hash keys has always been, and continues | |
1364 | to be, affected by the insertion order and the history of changes made | |
1365 | to the hash over its lifetime. | |
1366 | ||
1367 | =end original | |
1368 | ||
1149 | 1369 | B<Perl はハッシュキーの順序について何の保障もありません> し、Perl 5 の |
1150 | 1370 | 間でも既に何度か変更されています。 |
1151 | また、ハッシュキーの順序は、今までもこれからも、挿入順に | |
1371 | また、ハッシュキーの順序は、今までもこれからも、挿入順と、ハッシュに対して | |
1372 | 行われた変更の歴史の影響を受けます。 | |
1152 | 1373 | |
1153 | 1374 | =begin original |
1154 | 1375 | |
1155 | 1376 | Also note that while the order of the hash elements might be |
1156 | randomi | |
1377 | randomized, this "pseudo-ordering" should B<not> be used for | |
1157 | applications like shuffling a list randomly (use List::Util::shuffle() | |
1378 | applications like shuffling a list randomly (use C<List::Util::shuffle()> | |
1158 | 1379 | for that, see L<List::Util>, a standard core module since Perl 5.8.0; |
1159 | or the CPAN module Algorithm::Numerical::Shuffle), or for generating | |
1380 | or the CPAN module C<Algorithm::Numerical::Shuffle>), or for generating | |
1160 | permutations (use e.g. the CPAN modules Algorithm::Permute or | |
1381 | permutations (use e.g. the CPAN modules C<Algorithm::Permute> or | |
1161 | Algorithm::FastPermute), or for any cryptographic applications. | |
1382 | C<Algorithm::FastPermute>), or for any cryptographic applications. | |
1162 | 1383 | |
1163 | 1384 | =end original |
1164 | 1385 | |
1165 | 1386 | また、ハッシュ要素の順序はランダム化されますが、この「擬似整列」は |
1166 | 1387 | 以下のことに B<使うべきではありません>: リストをランダムに |
1167 | シャッフルするようなアプリケーション | |
1388 | シャッフルするようなアプリケーション (Perl 5.8.0 から標準モジュールと | |
1168 | ||
1389 | なっている L<List::Util> の C<List::Util::shuffle()> や、CPAN モジュールである | |
1169 | ||
1390 | C<Algorithm::Numerical::Shuffle> を使ってください)、 順列の生成 | |
1170 | Algorithm:: | |
1391 | (CPAN モジュールである C<Algorithm::Permute> や C<Algorithm::FastPermute> を | |
1171 | (CPAN モジュールである Algorithm::Permute や Algorithm::FastPermute を | |
1172 | 1392 | 使ってください)、あらゆる暗号アプリケーション。 |
1173 | 1393 | |
1394 | =begin original | |
1395 | ||
1396 | Tied hashes may have their own ordering and algorithmic complexity | |
1397 | attacks. | |
1398 | ||
1399 | =end original | |
1400 | ||
1401 | tie されたハッシュは独自の順序とアルゴリズム的複雑性攻撃があるかもしれません。 | |
1402 | ||
1174 | 1403 | =item * |
1175 | 1404 | |
1176 | 1405 | =begin original |
1177 | 1406 | |
1178 | 1407 | Regular expressions - Perl's regular expression engine is so called NFA |
1179 | 1408 | (Non-deterministic Finite Automaton), which among other things means that |
1180 | 1409 | it can rather easily consume large amounts of both time and space if the |
1181 | 1410 | regular expression may match in several ways. Careful crafting of the |
1182 | 1411 | regular expressions can help but quite often there really isn't much |
1183 | 1412 | one can do (the book "Mastering Regular Expressions" is required |
1184 | 1413 | reading, see L<perlfaq2>). Running out of space manifests itself by |
1185 | 1414 | Perl running out of memory. |
1186 | 1415 | |
1187 | 1416 | =end original |
1188 | 1417 | |
1189 | 1418 | 正規表現 - Perl の正規表現エンジンは NFA (Non-deterministic Finite Automaton: |
1190 | 1419 | 非決定性有限オートマトン)と呼ばれ、これは他のものに比べて、もし正規表現が |
1191 | 1420 | 複数の方法でマッチングする場合、かなり簡単に大量の時間と空間を |
1192 | 1421 | 消費することを意味します。 |
1193 | 1422 | 正規表現を注意深く構築することは助けになりますが、かなりの場合これは |
1194 | 1423 | 不十分です ("Mastering Regular Expressions" という本を読む必要があります; |
1195 | 1424 | L<perlfaq2> を参照してください)。 |
1196 | 1425 | 空間の不足は Perl がメモリ不足になることで明らかになります。 |
1197 | 1426 | |
1198 | 1427 | =item * |
1199 | 1428 | |
1200 | 1429 | =begin original |
1201 | 1430 | |
1202 | 1431 | Sorting - the quicksort algorithm used in Perls before 5.8.0 to |
1203 | implement the sort() function | |
1432 | implement the sort() function was very easy to trick into misbehaving | |
1204 | so that it consumes a lot of time. | |
1433 | so that it consumes a lot of time. Starting from Perl 5.8.0 a different | |
1205 | ||
1434 | sorting algorithm, mergesort, is used by default. Mergesort cannot | |
1206 | ||
1435 | misbehave on any input. | |
1207 | its input data, so it cannot be similarly fooled. | |
1208 | 1436 | |
1209 | 1437 | =end original |
1210 | 1438 | |
1211 | 1439 | ソート - 5.8.0 以前の Perl で sort() 関数を実装するために使われていた |
1212 | 1440 | クイックソートアルゴリズムは、大量の時間を消費するような策略がとても |
1213 | 簡単で | |
1441 | 簡単でした。 | |
1214 | 既にソートされているリストを再ソートさせる以上のことは不要です。 | |
1215 | 1442 | Perl 5.8.0 から、異なったソートアルゴリズムであるマージソートが |
1216 | 使われています。 | |
1443 | デフォルトで使われています。 | |
1217 | マージソートは入力データによって影響を受け | |
1444 | マージソートは入力データによって影響を受けません。 | |
1218 | 不可能です。 | |
1219 | 1445 | |
1220 | 1446 | =back |
1221 | 1447 | |
1222 | 1448 | =begin original |
1223 | 1449 | |
1224 | See L<http://www. | |
1450 | See L<https://www.usenix.org/legacy/events/sec03/tech/full_papers/crosby/crosby.pdf> for more information, | |
1225 | and any computer science textbook on | |
1451 | and any computer science textbook on algorithmic complexity. | |
1226 | 1452 | |
1227 | 1453 | =end original |
1228 | 1454 | |
1229 | さらなる情報については L<http://www. | |
1455 | さらなる情報については L<https://www.usenix.org/legacy/events/sec03/tech/full_papers/crosby/crosby.pdf> および、 | |
1230 | 1456 | アルゴリズム的複雑性に関する情報工学の教科書を参照してください。 |
1231 | 1457 | |
1458 | =head2 Using Sudo | |
1459 | ||
1460 | (sudo を使う) | |
1461 | ||
1462 | =begin original | |
1463 | ||
1464 | The popular tool C<sudo> provides a controlled way for users to be able | |
1465 | to run programs as other users. It sanitises the execution environment | |
1466 | to some extent, and will avoid the L<shebang race condition|/"Shebang | |
1467 | Race Condition">. If you don't have the safe version of set-id scripts, | |
1468 | then C<sudo> may be a more convenient way of executing a script as | |
1469 | another user than writing a C wrapper would be. | |
1470 | ||
1471 | =end original | |
1472 | ||
1473 | 人気のあるツールである C<sudo> は、 | |
1474 | ユーザーが他のユーザーとしてプログラムを実行する制御された手段を | |
1475 | 提供します。 | |
1476 | これはある程度実行環境をサニタイズして、 | |
1477 | L<シェバン競合条件|/"Shebang Race Condition"> を回避します。 | |
1478 | 安全なバージョンの set-id スクリプトを持っていない場合、 | |
1479 | C<sudo> は、他のユーザーとしてスクリプトを実行するための、 | |
1480 | C ラッパーを書くよりもより便利な手段になります。 | |
1481 | ||
1482 | =begin original | |
1483 | ||
1484 | However, C<sudo> sets the real user or group ID to that of the target | |
1485 | identity, not just the effective ID as set-id bits do. As a result, Perl | |
1486 | can't detect that it is running under C<sudo>, and so won't automatically | |
1487 | take its own security precautions such as turning on taint mode. Where | |
1488 | C<sudo> configuration dictates exactly which command can be run, the | |
1489 | approved command may include a C<-T> option to perl to enable taint mode. | |
1490 | ||
1491 | =end original | |
1492 | ||
1493 | しかし、C<sudo> はターゲットの身元として set-id ビットが行うような | |
1494 | 単なる実効 ID ではなく、実ユーザー ID やグループ ID を設定します。 | |
1495 | 結果として、Perl はこれが C<sudo> の基で実行されていることを検出できず、 | |
1496 | 汚染チェックモードを友好にすると行ったセキュリティ上の予防措置を | |
1497 | 自動的に有効にしません。 | |
1498 | C<sudo> 設定が実行されるコマンドを正確に設定する部分では、 | |
1499 | perl が汚染チェックモードを有効にするために、承認されたコマンドに | |
1500 | C<-T> オプションを含むことができます。 | |
1501 | ||
1502 | =begin original | |
1503 | ||
1504 | In general, it is necessary to evaluate the suitability of a script to | |
1505 | run under C<sudo> specifically with that kind of execution environment | |
1506 | in mind. It is neither necessary nor sufficient for the same script to | |
1507 | be suitable to run in a traditional set-id arrangement, though many of | |
1508 | the issues overlap. | |
1509 | ||
1510 | =end original | |
1511 | ||
1512 | 一般的に、C<sudo> の基で実効するためのスクリプトの適合性を評価することは、 | |
1513 | 特に想定している実行環境では必要です。 | |
1514 | 同じスクリプトに対して伝統的な set-id 配置で実行できるようにすることは | |
1515 | 必要でも十分でもありませんが、多くの問題は重なっています。 | |
1516 | ||
1232 | 1517 | =head1 SEE ALSO |
1233 | 1518 | |
1234 | 1519 | =begin original |
1235 | 1520 | |
1236 | L<perlrun> for its description of cleaning up environment | |
1521 | L<perlrun/ENVIRONMENT> for its description of cleaning up environment | |
1522 | variables. | |
1237 | 1523 | |
1238 | 1524 | =end original |
1239 | 1525 | |
1240 | L<perlrun> には環境変数を洗浄する方法が記述されています。 | |
1526 | L<perlrun/ENVIRONMENT> には環境変数を洗浄する方法が記述されています。 | |
1241 | 1527 | |
1242 | 1528 | =begin meta |
1243 | 1529 | |
1244 | 1530 | Translate: KIMURA Koichi (5.005_03) |
1245 | Update: Kentaro | |
1531 | Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-) | |
1532 | Status: completed | |
1246 | 1533 | |
1247 | 1534 | =end meta |