Created
May 6, 2019 07:41
-
-
Save grafi-tt/c27b1cd323845fe5a2030461c3e0a4c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 課題3(上級者向け) | |
SUID (Set User ID) ビットを使って、`sudo` コマンドのように root ユーザーとして他のコマンドを実行できるコマンドを作れ。 | |
**注意: 絶対にこのコマンドを実用してはならない。** | |
ヒント: C で書いたプログラムから `execvp` 関数を用いる。スクリプトファイルのすり替えに対処不能というセキュリティ上の問題から、SUID ビットはコンパイルされたプログラムに対してのみ機能する。 | |
<details> | |
<summary>解答</summary> | |
```c | |
#include <unistd.h> | |
int main(int argc, char *argv[]) { | |
execvp(argv[1], argv+1); | |
return 0; | |
} | |
``` | |
```shell | |
$ gcc -Wall kadai.c -o kadai | |
$ sudo chown root:root kadai | |
$ sudo chown u+s kadai | |
$ ./kadai rm -rf /NEVER-EXECUTE-THIS-COMMAND | |
``` | |
</details> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment