From 8771ff427ef18624057c1805dd05f50dee2b8503 Mon Sep 17 00:00:00 2001 From: newrain001 Date: Tue, 10 Sep 2024 08:56:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20'os/check1.sh'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- os/check1.sh | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 os/check1.sh diff --git a/os/check1.sh b/os/check1.sh deleted file mode 100644 index 9018176..0000000 --- a/os/check1.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -# 定义检查函数 -check_command() { - if eval $1; then - echo "第$2题正确" - else - echo "第$2题错误" - fi -} - -# 1. 检查是否为root用户并且当前目录是否为/opt -check_command "[ $(id -u) -eq 0 ]" 1 - -# 2. 检查用户tom和jack以及组hr是否存在,并且tom是否属于组hr -check_command "id tom &>/dev/null && id jack &>/dev/null && grep hr /etc/group &>/dev/null" 2 - -# 3. 检查目录/opt/myfile和文件hello.txt、world.txt是否存在 -check_command "[ -d /opt/myfile ] && [ -f /opt/myfile/hello.txt ] && [ -f /opt/world.txt ]" 3 - -# 4. 检查world.txt文件是否包含abcde字符串,且重复10行 -check_command "grep -Fxq 'abcde' /opt/world.txt && [ \$(grep -c 'abcde' /opt/world.txt) -ge 10 ]" 4 - -# 5. 检查world.txt文件的属主是否为jack,属组是否为hr -check_command "[ \$(stat -c '%U' /opt/world.txt) = 'jack' ] && [ \$(stat -c '%G' /opt/world.txt) = 'hr' ]" 5 - -# 6. 检查world.txt文件权限是否设置正确 -check_command "[ \$(stat -c '%A' /opt/world.txt) = '-rwxrw-r--' ]" 6 - -# 7. 检查/opt/myfile目录的属组是否为hr,并且递归设置 -check_command "[ \$(stat -c '%G' /opt/myfile) = 'hr' ] && [ \$(find /opt/myfile -not -group hr | wc -l) -eq 0 ]" 7 - -# 8. 检查/opt/myfile目录的权限是否允许所有用户创建文件或子目录,且新文件继承属组 -check_command "[ \$(stat -c '%a' /opt/myfile) = '2777' ]" 8 - -# 9. 检查cat命令是否设置为特殊提权指令 -check_command "find / -perm -4000 2>/dev/null| grep -qw 'cat'" 9 - -# 10. 检查world.txt的后5行是否被复制到hello.txt中 -check_command "head -n 5 /opt/myfile/hello.txt | grep abcde &>/dev/null" 10 - -# 11. 检查ip地址信息是否追加到hello.txt文件中 -check_command "grep ens33 /opt/myfile/hello.txt &>/dev/null" 11 - -# 12. 检查/opt目录下的所有内容是否复制到/mnt目录下 -check_command "[ \$(diff -r /opt /mnt | wc -l) -eq 0 ]" 12 -