LinuxÒÁµéÔ°ÂÛ̳'s Archiver

hongmy525 ·¢±íÓÚ 2007-5-18 22:43

ÇóÖú£¬À¹½Øexecve()ϵͳµ÷ÓöδíÎóÎÊÌâ

×î½üÎÒÒ²ÔÚÊÔͼ½Ø»ñexecve()ϵͳµ÷Ó㬵«ÊDZàдµÄÄ£¿é¼ÓÔØºóÏÔʾ¶Î´íÎó£¬ÕÒ²»³öÔ­Òò£¬Çó´ó¼Ò°ï°ï

棺£©

ÎÒµÄÄں˰汾ÊÇ2.4.7-10µÄ£¬ÔÚRedHat7.2µÄƽ̨ÏÂ

ÎҲο¼¹ýÒÔǰµÄһƪÌû×Ó¡¶½Ø»ñexecveϵͳµ÷Óã¬ÎªÊ²Ã´³öÏÖ¡°¶Î´íÎ󡱡·£¬Ìû×ӵĵØÖ·£º

[url]http://bbs.chinaunix.net/viewthread.php?tid=593811[/url]

ÎÒµÄÄ¿µÄÊÇ[color=Red]½Ø»ñ execve()ϵͳµ÷ÓúÍËüµÄËùÓвÎÊý[/color]£¬²¢ÉèÖñêÖ¾ i ,Èô i=-1 ,

Ôò²»Ö´ÐÐÕâ´Îϵͳµ÷Óã¬Èô i=0 ÔòÖ´ÐС£

ÒÔÏÂÊÇÎҵĴúÂ룺

#ifndef MODULE
#define MODULE
#endif
#ifndef __KERNEL__
#define __KERNEL__
#endif

#include <linux/module.h>
#include <linux/kernel.h>
#include <asm/unistd.h>
#include <sys/syscall.h>
#include <linux/types.h>
#include <linux/dirent.h>
#include <linux/string.h>
#include <linux/fs.h>
#include <linux/slab.h>  
#include <linux/init.h>
#include <linux/string.h>

extern void* sys_call_table[];    /* we can access sys_call_table  */
int (*orig_execve)(struct pt_regs regs); //the execve origin syscall

int check_exec(struct pt_regs regs)
{//use this funtion capture the execve system call
        
    int error=0;
    char *filename=NULL,**argv;
    filename=getname((char *)regs.ebx);
    argv=(char *)regs.ecx;
    printk("filename=%s\n",* filename);//[color=Red]³¢ÊÔ×ÅÏÈ´òÓ¡Ò»¸ö²ÎÊý£­£­ÎļþÃûÊÔÊÔ

[/color]
   
    error=do_execve(filename,(char **)regs.ecx,(char **)regs.edx,&regs);
        return error;
}

int init_module()
{
    orig_execve=sys_call_table[SYS_execve];    // save origin system call
    sys_call_table[SYS_execve]=check_exec;    // check_exec replace SYS_execve
    return 0;
}

int cleanup_modules()
{
    //Õâ¸öº¯ÊýÎÒÏÖÔÚ»¹Ã»ÓÐд´úÂ룬»ù±¾ÉÏÊÇÂÒдµÄ£¬Ö÷ÒªÏëÏȽػñËüµÄ²ÎÊý
    sys_call_table[SYS_execve]=orig_execve;    //set back syscall to orig_exec
    return 0;
}

flag ·¢±íÓÚ 2007-5-22 17:56

printk("filename=%s\n",[COLOR="Red"]*[/COLOR] filename)
¡£¡£¡£¡£¡£¡£±ÊÎó£¿

Ò³: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.