.d8888b. .d8888b. 8888888
d88P Y88b d88P Y88b 888
888 888 888 888 888
888 888 888
888 888 88888 888
888 888 888 888 888
Y88b d88P Y88b d88P 888
"Y8888P" "Y8888P88 8888888
PCP => Perl CGI Program (ming)
Version 1.0
Q5.2: 特にどんなセキュリティ項目に関心を寄せるべきでしょうか?
Q5.3:
みんなが
http://bigidiot.abuse-me.com/perl.exe?foo.pl
は危険だといっていますがどうしてですか?
どれくらい悪いことなのでしょうか?
Q5.4:
どうやったら安全にbacktickを使ってプログラムを callできますか?
@ans = `grep '$user_field' some.file`;
は安全ではないというのは本当ですか?
Q5.5:
/$user_variable/ が Perl 5ではセキュリティホールになっているというのは本当ですか?
この件に対する回答は:どんな言語でCGIプログラムが書かれていても セキュリティの問題はなにかしらあるのです!
どんな形のデータでも決してシェルにさらしてはなりません。 次のものは全て潜在的セキュリティホールとなる可能性があります。:
open (COMMAND, "/usr/ucb/finger $form_user");
system ("/usr/ucb/finger $form_user");
@data = `usr/ucb/finger $form_user`;しかしながら、2番目のコンストラクトは文字列ではなく リストとして引数を渡すことでより安全にすることができます。 シェルは文字列だと好きなように扱ってしまえるのです。:
system ("/usr/ucb/finger", $form_user);
また以下も見ておくべきでしょう。:
http://bigidiot.abuse-me.com/perl.exe?foo.pl
は危険だというのはどうしてですか? どれくらい悪いことなのでしょうか?
とんでもなく危険です! 以下のようなことをやったら どんなことがおきるかちょっと想像してみて下さい。:
http://bigidiot.abuse-me.com/cgi-bin/perl.exe?-e+'format:%20c'
さて、同意していただけましたか?
この潜在的な悪夢を避ける方法は以下の通りです。:
ということで、以下はある例です。あなたのCGIスクリプトが"sample.pl"と
呼ばれており、バッチスクリプトが"simple.bat"と呼ばれているとします:
[訳注:下記は"simple.bat"の中身です。]
これで、次のようにすることができます。:@echo off c:\dos_perl\perl.exe c:\netscape\ns-home\docs\cgi-bin\simple.pl
<A HREF="/cgi-bin/simple.bat">Click Here</A>
@ans = `grep '$user_field' some.file`;その通りです!そいつは非常に危険です! $user_field が次のようなものを含んでいる場合を想像してみて下さい。:
; rm -fr / ;
上記を完遂するためのずっと安全な方法は:
if (open (GREP, "-|")) {
@ans = <GREP>;
} else {
exec ("/usr/local/bin/grep", $user_field, "some.file")
|| die "Error exec'ing command", "\n";
}
close (GREP);
/$user_variable/ が Perl 5ではセキュリティホールになっているというのは本当ですか?
いいえ!そんなことはありません。ただ、実行時にevalコマンドを使って
その表現を評価したりするとセキュリティホールとなってしまいます。
以下のようなものは危険なものになり得るのです。:
foreach $regexp (@all_regexps) {
eval "foreach (\@data) { push (\@matches, \$_) if m|$regexp|o; }";
}
This document, and all its parts, are Copyright (c) 1996, Shishir Gundavaram and Tom Christiansen. All rights reservered. Permisson to distribute this collection, in part or full, via electronic means (emailed, posted or archived) or printed copy are granted providing that no charges are involved, reasonable attempt is made to use the most current version, and all credits and copyright notices are retained. Requests for other distribution rights, including incorporation in commercial products, such as books, magazine articles, or CD-ROMs should be made to either of the authors.
ご意見、ご要望は、
電子メールまたは
投稿にお願い致します。ホームページへ戻る。