バイナリにsuidを追加

バイナリにsuidを追加

私の質問はsuid!これに対するロジックは、ユーザーが特権コマンドを実行したときにroot権限を付与することです。たとえば、passwdこのような機能があります。

$ ls -l /usr/bin/passwd 
-rwsr-xr-x 1 root root 54224 Aug 21  2017 /usr/bin/passwd

を開くセクションを作成し、実行可能ファイルにzsh手動で追加しました。suid

$ chmod u+s myzs
$ ls -l myzs
-rwsr-xr-x 1 mahmood mahmood  7360 Jul  6 21:34 myzs

ただし、バイナリを実行すると、rootユーザーの代わりに現在のユーザー(私)に対してシェルが開きます。私のバイナリとパスワードの違いは何ですか?両方ともスードを持っています。

$ ./myzs 
% whoami                                                                                       
mahmood

ベストアンサー1

~からman chmod

   4000    (the set-user-ID-on-execution bit) Executable files with this bit set 
           will run with effective uid set to the uid of the file owner. 

したがって、バイナリを実行するユーザーとしてファイル所有者を設定する必要があります。

sudo chown root myzs

おすすめ記事