先普及一小段知识,我们用ps aux可以查看到进程的PID,而每个PID都会在/proc内产生。如果查看到的pid而proc内是没有的,则是进程被人修改了,这就代表你的系统很有可能已经被入侵过了。
请大家用上面知识编写一个shell,定期检查下自己的系统是否被人入侵过。
#!/bin/bash
##Written by Adai 2017-09-05
p=`ps aux | awk '{print $2}' | grep -v 'PID'`
a=`ls /proc |grep '$p' > /tmp/pid_check.txt |wc -w |awk '{print $1}'`
if [ $a -eq 0 ]
then
echo "The system is ok!"
else
echo "Dangerous PID: $p"
fi
铭哥:
#!/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
(adsbygoogle = window.adsbygoogle || []).push({});