killSPRRHEL ボックスで次のプロセスを強制終了するために呼び出される小さな C ユーティリティを作成しました。アイデアは、この Linux ボックスにログインするすべての人がこのユーティリティを使用して、後述のプロセスを強制終了できるようにすることです (これは機能しません - 以下で説明します)。
cadmn@rhel /tmp > ps -eaf | grep -v grep | grep " SPR "
cadmn 5822 5821 99 17:19 ? 00:33:13 SPR 4 cadmn
cadmn 10466 10465 99 17:25 ? 00:26:34 SPR 4 cadmn
cadmn 13431 13430 99 17:32 ? 00:19:55 SPR 4 cadmn
cadmn 17320 17319 99 17:39 ? 00:13:04 SPR 4 cadmn
cadmn 20589 20588 99 16:50 ? 01:01:30 SPR 4 cadmn
cadmn 22084 22083 99 17:45 ? 00:06:34 SPR 4 cadmn
cadmn@rhel /tmp >
このユーティリティは (これらのプロセスを実行する) ユーザーによって所有されcadmn、setuid フラグが設定されています (以下を参照)。
cadmn@rhel /tmp > ls -l killSPR
-rwsr-xr-x 1 cadmn cusers 9925 Dec 17 17:51 killSPR
cadmn@rhel /tmp >
C コードを以下に示します。
/*
* Program Name: killSPR.c
* Description: A simple program that kills all SPR processes that
* run as user cadmn
*/
#include <stdio.h>
int main()
{
char *input;
printf("Before you proceed, find out under which ID I'm running. Hit enter when you are done...");
fgets(input, 2, stdin);
const char *killCmd = "kill -9 $(ps -eaf | grep -v grep | grep \" SPR \" | awk '{print $2}')";
system(killCmd);
return 0;
}
pmnとは異なるユーザー ( )cadmnが、このユーティリティを使用して上記のプロセスを強制終了しようとしましたが、失敗しました (以下を参照)。
pmn@rhel /tmp > ./killSPR
Before you proceed, find out under which ID I'm running. Hit enter when you are done...
sh: line 0: kill: (5822) - Operation not permitted
sh: line 0: kill: (10466) - Operation not permitted
sh: line 0: kill: (13431) - Operation not permitted
sh: line 0: kill: (17320) - Operation not permitted
sh: line 0: kill: (20589) - Operation not permitted
sh: line 0: kill: (22084) - Operation not permitted
pmn@rhel /tmp >
ユーザーが上記の Enter キーを押すのを待っている間、プロセスkillSPRが検査され、cadmnkillSPR がプロセスを終了できないにもかかわらず、ユーザーとして実行されていることがわかります (以下を参照)。
cadmn@rhel /tmp > ps -eaf | grep -v grep | grep killSPR
cadmn 24851 22918 0 17:51 pts/36 00:00:00 ./killSPR
cadmn@rhel /tmp >
ところで、メインパーティションには何もありませnosuidん
pmn@rhel /tmp > mount | grep nosuid
pmn@rhel /tmp >
実行可能ファイルの setuid フラグは、望ましい効果を持っていないようです。ここで何が欠けていますか?setuid の仕組みを誤解していませんか?