发新话题
打印

linux病毒原型工作过程和关键环节

linux病毒原型工作过程和关键环节

  一、 介绍

  写这篇文章的目的主要是对最近写的一个linux病毒原型代码做一个总结,同时向对这方面有兴趣的朋友做一个简单的介绍。阅读这篇文章你需要一些知识,要对elf有所了解、能够阅读一些嵌入了汇编的c代码、了解病毒的基本工作原理。

  二、 elf infector (elf文件感染器)

  为了制作病毒文件,我们需要一个elf文件感染器,用于制造第一个带毒文件。对于elf文件感染技术,在silvio cesare的《unix elf parasites and virus》一文中已经有了一个非常好的分析、描述,在这方面我还没有发现可以对其进行补充的地方,因此在这里我把silvio cesare对elf infection过程的总结贴出来,以供参考: the final algorithm is using this information is.


  * increase p_shoff by page_size in the elf header

  * patch the insertion code (parasite) to jump to the entry point

  (original)

  * locate the text segment program header

  * modify the entry point of the elf header to point to the new

  code (p_vaddr + p_filesz)

  * increase p_filesz by account for the new code (parasite)

  * increase p_memsz to account for the new code (parasite)

  * for each phdr who's segment is after the insertion (text segment)

  * increase p_offset by page_size

  * for the last shdr in the text segment

  * increase sh_len by the parasite length

  * for each shdr who's section resides after the insertion

  * increase sh_offset by page_size

  * physically insert the new code (parasite) and pad to page_size, into

  the file - text segment p_offset + p_filesz (original)

  在linux病毒原型中所使用的gei - elf infector即是根据这个原理写的。在附录中你可以看到这个感染工具的源代码: g-elf-infector.cg-elf-infector与病毒是独立开的,其只在制作第一个病毒文件时被使用。我简单介绍一下它的使用方法,g-elf-infector.c可以被用于任何希望--将二进制代码插入到指定文件的文本段,并在目标文件执行时首先被执行--的用途上。g-elf-infector.c的接口很简单,你只需要提供以下三个定义:

  * 存放你的二进制代码返回地址的地址,这里需要的是这个地址与代码起始地址的偏移,用于返回到目标程序的正常入口 #define paracode_retaddr_addr_offset 1232

  * 要插入的二进制代码(由于用c编写,所以这里需要以一个函数的方式提供)

  void parasite_code(void);

  * 二进制代码的结束(为了易用,这里用一个结尾函数来进行代码长度计算) void parasite_code_end(void);

  parasite_code_end应该是parasite_code函数后的第一个函数定义,通常应该如下表示 void parasite_code(void)

  {

  ...

  ...

  ...

  }

  void parasite_code_end(void) {}

  在这里存在一个问题,就是编译有可能在编译时将parasite_code_end放在parasite_code地址的前面,这样会导致计算代码长度时失败,为了避免这个问题,你可以这样做 void parasite_code(void)

  {

  ...

  ...

  ...

  }

  void parasite_code_end(void) {parasite_code();}

  有了这三个定义,g-elf-infector就能正确编译,编译后即可用来elf文件感染 face=verdana>

TOP

发新话题