個人心血來潮時寫的一個腳本,比較粗糙,功能也很簡單,大家有興趣的可以拿去改改。
本腳本之爭對系統中UID為0的用戶
#!/bin/bash????????????? ? #大家都知道
echo test my computer is or not safety?? ?#顯示“ test my computer is or not safety? ”
root_num=`awk -F: '{print $3}' /etc/passwd|grep "^0"|wc -l`??? #以“:”為分隔符,打印出/etc/passwd文件中第三個域的字段,并grep以“0”開頭的(意思是UID是0的用戶),然后計算行數(3行代表有3個UID為0的用戶,包括root),最終賦值給root_num.
if [ $root_num -eq 1 ];then? #如果$root_num的值為1,表示只有一個root用戶
echo your computer is safety #顯示“ your computer is safety ”
else???????? #否則
awk -F: '{print $3,$1}' /etc/passwd|grep "^0"|grep -v "root" >> hack1 #打印/etc/passwd中的第三個域(UID)和第一個域(用戶名),并且grep以“0”開頭的行,輸出到hack1的文件中
cat hack1|awk '{print $2}'>>hack????? #查看hack1文件的內容,并打印出第二個域的內容,輸出到hack文件中
for number in `cat hack`???? #查看hack的內容,并循環賦值給number
do
echo $number mybe created by hacker.? #顯示“?xxx mybe created by hacker.”
read -p "are you want to delete it? y or n? :" answer #顯示“are you want to delete it? y or n? :“
if [ $answer = "y" ]??????? #如果回答是”y“
then
userdel -r $numeber? #刪除xxx
echo $number is delete. #顯示”xxx is dele“
if [ $answer = "yes"]? #如果回答是”yes“
then
userdel -r $number
echo $number is delete.
fi
fi
done
fi
rm -f hack*? #刪除hack和hack1文件
有興趣的可以試試。功能很簡單,只為娛樂娛樂。