"find -exec"を使用する際のセキュリティ問題と競合状態は何ですか?

~からfindマニュアルページ:

-exec command ;
    There are unavoidable security problems
    surrounding use of the -exec action; you should use the
    -execdir option instead.

-execdir command {} +
    Like -exec, but the specified command is run from the
    subdirectory containing the matched file, which is not
    normally the directory in which you started find.  This a much
    more secure method for invoking commands, as it avoids race
    conditions during resolution of the paths to the matched
    files.

どういう意味ですか?スタートアップディレクトリで実行すると競合状態が発生するのはなぜですか?これらのセキュリティリスクはどうですか?

ベストアンサー1

詳細が見つかりました。ここ:

これ-execにより他のプログラムが実行されます。検討中のファイル名をプログラムに渡します。その後、呼び出されたプログラムは通常、ファイルに対していくつかの操作を実行します。ここでも悪用される可能性がある競争条件があります。コマンドを例に挙げましょう。

 find /tmp -path /tmp/umsp/passwd -exec /bin/rm

この簡単な例では、削除するファイルを識別し、 /bin/rm削除を呼び出します。 findがジョブを処理する必要があると判断した時点と、コマンドが実際にファイルシステムからファイルを削除するためにunlink()システムコールを実行する-exec時点との間に時間遅延があるため、問題が発生します。/bin/rmこの間、攻撃者はディレクトリ/tmp/umsp 名を/etc/bin/rmシンボリックリンクが確立されると、攻撃者はfindが/etc/passwd実際に呼び出されたコマンドの意図した効果ではなくファイルの削除を引き起こすように説得する可能性があります。

誰かがこれを悪用する可能性がどれくらいになるのかわかりませんが、答えはそこにあるようです。

おすすめ記事