私はLinux suidを学んでいるので、テストするために以下を含む小さなCプログラムを書いています。
#include<stdio.h>
int main(){
system("echo 100 >> test.txt");
return 0;
}
-rwsr-xr-x 1 root root 8004 Sep 10 16:19 test
test.txt
ルートのみを変更できるファイルです。
-rw-r----- 1 root root
100
ユーザーアカウントを使用してテストプログラムを実行した場合は、空のファイルに追加する必要があります。しかし、結果は次のようになりました。
sh:test.txt:Permission denied
なぜ?
ベストアンサー1
あなたのシナリオは私にとって完璧に動作します。
$ ls -l test*
-rwsr-xr-x 1 root root 6776 Jan 24 17:18 test
-rw-r--r-- 1 chris chris 74 Jan 24 17:18 test.c
-rw-r----- 1 root root 0 Jan 24 17:20 test.txt
$ ./test
ls -l test.txt
-rw-r----- 1 root root 4 Jan 24 17:21 test.txt
$ sudo cat test.txt
100
setuid実行可能ファイルを許可しないファイルシステムでプログラムをテストすることは可能ですか?コマンドを実行し、次のようにmount
ファイルシステムを探します。nosuid
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noexec,relatime)