shell习题-判断pid是否一致
先普及一小段知识,我们用ps aux可以查看到进程的PID,而每个PID都会在/proc内产生。如果查看到的pid而proc内是没有的,则是进程被人修改了,这就代表你的系统很有可能已经被入侵过了。
请大家用上面知识编写一个shell,定期检查下自己的系统是否被人入侵过。
参考答案:
#!/bin/bash ps aux|awk '/[0-9]/ {print $2}'|while read pid do result=`find /proc/ -maxdepth 1 -type d -name "$pid"` if [ -z $result ]; then echo "$pid abnormal!" fi done
2 Responses
18期廖超 says:
每次运行这个脚本必定会有2个Pid找不到,是这个脚本本身运行的pid吧,感觉这个脚本漏洞很多呀
2017年9月8日 at 下午2:03
aming says:
是的 是脚本里面的命令产生的pid。
2017年9月13日 at 下午10:29